Plugin Compatibility with Battery Watch

Posted on
Thu Dec 16, 2021 7:41 am
ryanbuckner offline
Posts: 1074
Joined: Oct 08, 2011
Location: Northern Virginia

Plugin Compatibility with Battery Watch

If we are building a plugin that has a battery state, is there a way to update the device.batteryLevel object attribute to become compatible Battery Watch? Right now I'm updating a custom state only.

I'm able to update the device.address attribute but only when the user is editing a device.

Posted on
Thu Dec 16, 2021 8:32 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Plugin Compatibility with Battery Watch

You need to have a boolean field in your devices.xml that has the name SupportsBatteryLevel with a value of true and set to hidden.
Then you should add a device state of batteryLevel to the devices.xml and have some code like:
Code: Select all
                    if dev.pluginProps.get("SupportsBatteryLevel", False):
                        battery_level = int(float(<BATTERY_LEVEL_VALUE>))
                        dev.updateStateOnServer(key='batteryLevel', value=battery_level)

Replace <BATTERY_LEVEL_VALUE> with the value from your battery.

Hope this helps. :)

Posted on
Thu Dec 16, 2021 2:04 pm
ryanbuckner offline
Posts: 1074
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Plugin Compatibility with Battery Watch

[quote="autolog"]You need to have a boolean field in your devices.xml that has the name SupportsBatteryLevel with a value of true and set to hidden.
Then you should add a device state of batteryLevel to the devices.xml and have some code like:
Code: Select all
                    if dev.pluginProps.get("SupportsBatteryLevel", False):
                        battery_level = int(float(<BATTERY_LEVEL_VALUE>))
                        dev.updateStateOnServer(key='batteryLevel', value=battery_level)

Replace <BATTERY_LEVEL_VALUE> with the value from your battery.

That did it. Thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests