Page 1 of 9
Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 9:25
by Logread
I understand there is not yet a repository for plugins written for the Beta Python plugin framework, so I am posting this in the forum in case it can be of use to some users...
Domoticz does report level of batteries of battery powered z-wave devices in a way that I do not find convenient for the following reasons:
- Battery levels are only shown in the “Setup/Devices” page and for zwave nodes that produce multiple devices, the same information is reported across all these devices.
- The system wide “Battery Low Level” notification system within Domoticz (in “Setup/Settings/Other”) does not allow for different levels of trigger depending on devices, while it is my experience that some devices can still operate for long with say 20% of battery level, while others will shortly stop after reporting a battery level of 50%.
- The evolution of battery level over time cannot be logged for analysis of battery life patterns per devices
This plugin addresses the above as follows:
- It polls at regular intervals a given Domoticz system (it can be the system on which the plugin is running, but also another one in the same local network) for z-wave nodes and creates/updates a Domoticz device for each z-wave node to show the node’s battery level
- Each of these Domoticz devices representing a battery operated z-wave node will allow:
- An easy to read display of the current battery level
- Logging over time like for any Domoticz sensor
- The definition of custom battery level notifications or events for each specific z-wave node
- as a bonus, a dynamic icon will display the battery level in 4 colors (green if >75%, yellow if 50 to 75%, orange if 25 to 50% and red if below 25%). Icons are from https://wpclipart.com/index.html , many thanks to them for these public domain graphics.
The plugin requires Domoticz beta version > 3.7418 to work (otherwise there is a risk that Domoticz crashes due to a typo bug in the Python framework).
Instructions can be found at
https://www.domoticz.com/wiki/Plugins/BatteryLevel.html
and all plugin files are available for review/download at:
https://github.com/999LV/BatteryLevel
EDIT 04/10/2017: Latest version 0.4.5 has been pushed to Github.
Please update your installed version to ensure known bugs are fixed...
Those who upgrade an existing install should do (on a typical Raspberry install... adjust to your platform as needed):
Code: Select all
cd ~/domoticz/plugins/BatteryLevel
git reset --hard
git pull --force
sudo chmod +x plugin.py
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 10:28
by G3rard
Thanks for sharing! Will try it this weekend and let you know the results.
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 11:56
by Egregius
Yes, battery reports are a pain now.
You convinced me to start with Python plugins, so yours is the first one active on my system.
Just noticed some errors in the logfile:
Code: Select all
2017-05-12 11:53:12.069 Error: (Battery) 'onMessage' failed 'KeyError'.
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 225 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 104 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 190 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function scanDevices
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 204 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function UpdateDevice
9 'Battery' devices were created, alltough I have 19 battery powered devices...
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 12:17
by bdormael
Egregius wrote:Yes, battery reports are a pain now.
You convinced me to start with Python plugins, so yours is the first one active on my system.
Just noticed some errors in the logfile:
Code: Select all
2017-05-12 11:53:12.069 Error: (Battery) 'onMessage' failed 'KeyError'.
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 225 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 104 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 190 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function scanDevices
2017-05-12 11:53:12.070 Error: (Battery) ----> Line 204 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function UpdateDevice
9 'Battery' devices were created, alltough I have 19 battery powered devices...
Same error message for me and no devices are created
below the debug logfile:
https://drive.google.com/open?id=0B8NIg ... GdmeVprQXc
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 12:22
by Egregius
You checked the device table? You have to add them as used yourself there.
Just did a reboot, 3 more devices were created. 7 to go
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 12:30
by bdormael
Egregius wrote:You checked the device table? You have to add them as used yourself there.
Just did a reboot, 3 more devices were created. 7 to go
I'm going to settings/devices and no new devices are shown there, did already couple of reboots, always the same errors in the logfile
using Domoticz version v3.7450 on RPI3
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 13:37
by Logread
Thanks for testing and posting the logs... let me check into this later today.
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 13:46
by Derik
Great work!!!!
Still mis this option in Domoticz...
Perhaps built this in?
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 14:06
by Logread
@Egregius, @ bdormael,
Would you mind replacing the existing plugin.py with the attached one (obviously please rename to 'plugin.py' as I had to change the extension to allow posting) ?
Definitely an issue associated with specific devices in your setup. There is an improved error handling at the point where you are currently seeing errors and a logging of the device(s) that raise the error. We can then hopefully understand what's wrong with the plugin's handling of these devices
Please do let me know the outcome...
Thanks !
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 14:34
by Egregius
I replaced the content of the file and restarted domoticz.
The errors are on different linenumbers now:
Code: Select all
2017-05-12 14:29:30.555 Error: (Battery) 'onMessage' failed 'KeyError'.
2017-05-12 14:29:30.555 Error: (Battery) ----> Line 227 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 14:29:30.555 Error: (Battery) ----> Line 103 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function onMessage
2017-05-12 14:29:30.556 Error: (Battery) ----> Line 192 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function scanDevices
2017-05-12 14:29:30.557 Error: (Battery) ----> Line 206 in /home/pi/domoticz/plugins/BatteryLevel/plugin.py, function UpdateDevice
These are the used battery powered devices:
Aeotec DSA03202 Minimote
Danfoss Z Thermostat 014G0013
FIBARO System FGK101 Door Opening Sensor
FIBARO System FGMS001 Motion Sensor
FIBARO System FGSD002 Smoke Sensor
The minimote doesn't report batterylevel, so I guess you can ignore that one.
Currently I have 13 'battery' devices.
I'm still missing:
1 of 6 Smoke sensors
2 of 5 motion sensors
3 of 3 Danfoss thermostats
Edit: checked the danfoss again. They don't have battery level filled in anymore
It used to be filled in, don't know how long it's gone.
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 15:10
by Logread
@Egregius,
Now I am lost with the new error you are seeing... In order to avoid clogging the thread with the debugging work, let's exchange further on this via pm. I just sent you a message, but here is a new file with even more error trapping...
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 15:13
by bdormael
Logread wrote:@Egregius, @ bdormael,
Would you mind replacing the existing plugin.py with the attached one (obviously please rename to 'plugin.py' as I had to change the extension to allow posting) ?
plugin.py.txt
Definitely an issue associated with specific devices in your setup. There is an improved error handling at the point where you are currently seeing errors and a logging of the device(s) that raise the error. We can then hopefully understand what's wrong with the plugin's handling of these devices
Please do let me know the outcome...
Thanks !
Much better now, already detecting lots of devices.
following errors are in the logfile:
Code: Select all
2017-05-12 15:10:39.646 Error: (Battery) Error processing device idx = 907 for node = 9
2017-05-12 15:10:39.647 Error: (Battery) Error processing device idx = 968 for node = 0
2017-05-12 15:10:39.647 Error: (Battery) Error processing device idx = 1007 for node = 36
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 15:16
by Logread
@ bdormael,
Can you confirm first that in the attached are all your zwave nodes (battery powered or not) ? I want to check that this table is ok for starters:
I am puzzled to see devices 907, 968 and 1007 reporting respectively nodes 9, 0 and 36... since these are not in the zwave nodes list... This is where we have to dig... Can you also confirm these 3 devices have indeed their "parent" HardwareID being 5 ?
Thanks
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 15:46
by Logread
OK, I think I understand the issue that @Egregius and @bdormael have reported.
It has to do with the translation of the ID field of the Domoticz device into its "parent" zwave node id... I had assumed that the openzwave hardware always created the device ID field (in hex format) based on the node id + two digits that represent the zwave device "class", hence I could derive the node id by the following:
Code: Select all
nodeID = int(device["ID"][:-2], 16)
for instance, a device with ID field x0000903 would "belong" to node 9 by stripping the last two hex digits... That works for all my zwave devices on my two production systems with a zwave controller. But the log provided by @bdormael shows three devices that do not follow that "logic" (while all others do...)
Unless someone can give me help in figuring a more universal way to derive the "parent" zwave node id of a specific Domoticz device, I am going to edit the plugin code to ignore these "non standard" devices and no longer report errors (at the expense of may be a few battery devices being ignored).
EDIT: Version 0.3.1 is out with the above fix, available in Github as well. Patched python file attached for those who already have all the plugin files installed:
(do not forget to rename to "plugin.py" and "chmod +x" if needed)
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Friday 12 May 2017 17:19
by remb0
very nice!!! thanks for this great plugin. Gonna wait till al my devices are alive and then I can add notifications etc.
With the new skin it would be possible to merge multiple devices with the name into one device. so this would be amazing.
well documented
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Saturday 13 May 2017 11:31
by G3rard
@Logread, installed it and it's looking very nice.
I have 3 smoke sensors Fibaro FGSD002. I replaced a battery of one of these smoke sensors yesterday (after installing the plugin), but the sensor still shows 5% battery.
- battery.png (30.52 KiB) Viewed 7765 times
But the Openzwave panel shows that the battery is 100%.
- battery2.png (19.84 KiB) Viewed 7765 times
The wakeup interval of the smoke sensor is 6 hours and the battery is in there for at least 12 hours now.
One of the smoke sensor devices in the Devices list shows indeed a battery level of 5%.
How does the script check the value for the battery? Does it use one of the devices or does it use the value the Openzwave config is showing?
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Saturday 13 May 2017 13:25
by FritzzJan
@Logread:
My compliments to you, very nice plugin!
To see the correct status of the batterylevel was always a problem, so this plugin is very welcome.
The documentation to install the plugin is also very good.
Regards,
Frits
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Saturday 13 May 2017 16:46
by Logread
G3rard wrote:@Logread, installed it and it's looking very nice.
[...]
How does the script check the value for the battery? Does it use one of the devices or does it use the value the Openzwave config is showing?
Indeed the script looks into the Domoticz devices created for the zwave nodes, using the Domoticz json API. It is therefore totally dependant on how Domoticz refreshes those battery levels from openzwave, and that is beyond my scope...
It would be better and more accurate to get these values directly from openzwave but while I am pretty sure it can be possible to bind Python to openzwave, this is rather low level and I do not yet want to venture into this (but interested to hear if someone wants to take the challenge...)
Also thanks for the kind notes from several users in the thread. Most happy to hear this can be useful...
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Saturday 13 May 2017 17:28
by Egregius
This plugin is absolutely handy! Thank you for this.
There are already multiple topics about the wrong battery levels in Domoticz, all without solution.
I can also give some examples:
Fibaro SD1 & 2: 100% in DZ, 0% in OZWCP (but still working)
Fibaro SD3, 4 & 5: 100% in DZ, 100% in OZWCP (not possible after more than a month)
Fibaro SD6: No report in DZ, 100% in OZWCP (not possible after several months)
Fibaro Motion sensors all report 100% battery
The door contacts are the worst, I think that's mainly because they have a default wake up interval that's so long it never happens (should change that once...)
Re: Python plugin: Battery Level for Z-Wave Devices
Posted: Saturday 13 May 2017 17:33
by Egregius
Just looked at the new devices, some are marked red, probably because they haven't updated in the last 720 minutes (sensor timeout in settings).
Didn't look at the code yet how often this is executed but maybe not a bad idea to update the sensors every x hours to avoid this?