Page 1 of 1

Plugin Compatibility with Battery Watch

PostPosted: Thu Dec 16, 2021 7:41 am
by ryanbuckner
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.

Re: Plugin Compatibility with Battery Watch

PostPosted: Thu Dec 16, 2021 8:32 am
by 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.

Hope this helps. :)

Re: Plugin Compatibility with Battery Watch

PostPosted: Thu Dec 16, 2021 2:04 pm
by ryanbuckner
[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!