Python plugin: Battery Level for Z-Wave Devices

Python and python framework
Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 9:25

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:
  1. 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.
  2. 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%.
  3. 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:
  1. 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
  2. Each of these Domoticz devices representing a battery operated z-wave node will allow:
    1. An easy to read display of the current battery level
    2. Logging over time like for any Domoticz sensor
    3. The definition of custom battery level notifications or events for each specific z-wave node
    4. 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
Last edited by Logread on Wednesday 04 October 2017 14:53, edited 5 times in total.

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by G3rard » Friday 12 May 2017 10:28

Thanks for sharing! Will try it this weekend and let you know the results.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Egregius » Friday 12 May 2017 11:56

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...

bdormael
Posts: 101
Joined: Saturday 13 December 2014 22:20
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by bdormael » Friday 12 May 2017 12:17

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
Last edited by bdormael on Friday 12 May 2017 12:28, edited 1 time in total.

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Egregius » Friday 12 May 2017 12:22

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 :D

bdormael
Posts: 101
Joined: Saturday 13 December 2014 22:20
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by bdormael » Friday 12 May 2017 12:30

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 :D
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

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 13:37

Thanks for testing and posting the logs... let me check into this later today.

User avatar
Derik
Posts: 2185
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Derik » Friday 12 May 2017 13:46

Great work!!!!

Still mis this option in Domoticz...

Perhaps built this in?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 14:06

@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
(10.62 KiB) Downloaded 85 times
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 !

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Egregius » Friday 12 May 2017 14:34

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.

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 15:10

@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...
plugin.py.txt
(10.74 KiB) Downloaded 63 times

bdormael
Posts: 101
Joined: Saturday 13 December 2014 22:20
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by bdormael » Friday 12 May 2017 15:13

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

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 15:16

@ 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:
zwave.txt
(1.4 KiB) Downloaded 79 times
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

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Friday 12 May 2017 15:46

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:
plugin.py.txt
(10.92 KiB) Downloaded 65 times
(do not forget to rename to "plugin.py" and "chmod +x" if needed)

User avatar
remb0
Posts: 1002
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by remb0 » Friday 12 May 2017 17:19

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 :!:

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by G3rard » Saturday 13 May 2017 11:31

@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
battery.png (30.52 KiB) Viewed 4414 times
But the Openzwave panel shows that the battery is 100%.
battery2.png
battery2.png (19.84 KiB) Viewed 4414 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?
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

FritzzJan
Posts: 17
Joined: Sunday 20 December 2015 12:07
Target OS: Raspberry Pi
Domoticz version: beta
Location: The Netherlands, Hoorn
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by FritzzJan » Saturday 13 May 2017 13:25

@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

Logread
Posts: 203
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Logread » Saturday 13 May 2017 16:46

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...

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Egregius » Saturday 13 May 2017 17:28

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...)

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python plugin: Battery Level for Z-Wave Devices

Post by Egregius » Saturday 13 May 2017 17:33

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?

Image

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests