Page 1 of 6
Python plugin: UPS Monitor
Posted: Friday 30 June 2017 18:17
by Logread
Another python plugin that I wrote that I am releasing in case anyone finds it useful.
It exposes via Domoticz devices a number of status variables reported by compatible UPS (Uninterruptible Power Supply) units via a NUT (Network UPS Tools) server running on the same local network as the Domoticz system. An example could be a UPS compatible with a Synology NAS and connected to it with UPS management enabled on the Synology NAS (this is my personal setup: a EATON Ellipse PRO 650 UPS connected to a Synology NAS via USB, with the UPS driving a router, a wifi A/P, the NAS and a Raspberry hosting domoticz).
The plugin is written so as to avoid the need to install any client side software or "packet" such as the NUT Client. It fetches the UPS data directly from the NUT Server via a telnet session, updated every minute (hence any change in the UPS status such as switching to backup power may take up to one minute to be reflected. This is a compromise setting to avoid undue network traffic)
This plugin allows the monitoring/logging of the following UPS variables:
- "ups.status": displayed as alert device "UPS Status" - the status of the UPS (Green = On Line, Red = Backup power)
"battery.charge": displayed as device "UPS Charge" - the % charge of the UPS battery
"battery.runtime": displayed as device "UPS Backup Time" - estimated time on backup power before the UPS dies
"input.voltage": displayed as device "UPS DC Input" - the voltage of the DC mains input
"ups.load": displayed as "UPS Load" - the load output in % of max power of the UPS
"ups.realpower": displayed as "UPS Power" - effective power in watts of the UPS load
"input.frequency": displayed as device "UPS DC Frequency" - the frequency of the DC mains input
Only the "UPS Status" device is always created by the plugin, others are created if the specific UPS reports the variable. Here is a screenshot with all these devices:

- Plugin_NUT_UPS_Devices.PNG (218.64 KiB) Viewed 12825 times
If you want to know more and for installation instructions, see the wiki at
https://www.domoticz.com/wiki/Plugins/NUT_UPS.html
Re: Python plugin: UPS Monitor
Posted: Friday 30 June 2017 19:35
by remb0
great work!!!
Re: Python plugin: UPS Monitor
Posted: Saturday 01 July 2017 4:50
by marco.bag
Brilliant, thank you so much!
Re: Python plugin: UPS Monitor
Posted: Saturday 01 July 2017 17:57
by Logread
Thanks for the positive feedback.
I pulled a new version 0.1.1 to GitHub to fix:
- a bug in the code in the event a specific variable is not published by the UPS that caused a python error, and
two incorrect device labels (AC v.s. DC...)
Re: Python plugin: UPS Monitor
Posted: Tuesday 04 July 2017 21:40
by marco.bag
Unfortunately if I git-pull the new version the domoticz server do not start at all...
Any clue to solve that?
Re: Python plugin: UPS Monitor
Posted: Tuesday 04 July 2017 23:39
by G3rard
@Logread, thanks for this plugin!
I have installed it on Domoticz v3.8025 on Ubuntu Server.
The UPS is running on my Synology NAS, I have enabled Network UPS and added the IP address of the Ubuntu server.
When starting the plugin I get the following errors in the log
- Spoiler: show
Code: Select all
2017-07-04 23:32:35.650 (UPS) Initialized version 0.1.1, author 'logread'
2017-07-04 23:32:35.651 (UPS) Debug log level set to: 'true'.
2017-07-04 23:32:35.651 (UPS) 'Name':'UPS'
2017-07-04 23:32:35.651 (UPS) 'Mode1':'UPS on Synology'
2017-07-04 23:32:35.651 (UPS) 'HardwareID':'18'
2017-07-04 23:32:35.651 (UPS) 'Author':'logread'
2017-07-04 23:32:35.651 (UPS) 'Port':'3493'
2017-07-04 23:32:35.651 (UPS) 'Key':'NUT_UPS'
2017-07-04 23:32:35.651 (UPS) 'HomeFolder':'/home/gerard/domoticz/plugins/nut-ups/'
2017-07-04 23:32:35.651 (UPS) 'Mode6':'Debug'
2017-07-04 23:32:35.651 (UPS) 'Address':'192.168.1.102'
2017-07-04 23:32:35.651 (UPS) 'Version':'0.1.1'
2017-07-04 23:32:35.651 (UPS) Device count: 1
2017-07-04 23:32:35.651 (UPS) Device: 1 - ID: 63, Name: 'UPS - UPS Status Mode', nValue: 0, sValue: ''
2017-07-04 23:32:35.651 (UPS) Device ID: '63'
2017-07-04 23:32:35.651 (UPS) Device Name: 'UPS - UPS Status Mode'
2017-07-04 23:32:35.651 (UPS) Device nValue: 0
2017-07-04 23:32:35.651 (UPS) Device sValue: ''
2017-07-04 23:32:35.651 (UPS) Device LastLevel: 0
2017-07-04 23:32:45.176 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:32:45.181 Error: (UPS) Error reading UPS variables: BEGIN LIST VAR UPS
2017-07-04 23:32:45.182 (UPS) Variable UPS AC Frequency = None
2017-07-04 23:32:45.182 (UPS) Variable UPS Charge = None
2017-07-04 23:32:45.182 (UPS) Variable UPS Backup Time = None
2017-07-04 23:32:45.182 (UPS) Variable UPS Status = 0
2017-07-04 23:32:45.182 Error: (UPS) 'onHeartbeat' failed 'TypeError':'argument of type 'int' is not iterable'.
2017-07-04 23:32:45.182 Error: (UPS) ----> Line 143 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function onHeartbeat
2017-07-04 23:32:45.182 Error: (UPS) ----> Line 99 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function onHeartbeat
2017-07-04 23:32:45.182 Error: (UPS) ----> Line 111 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function UpdateDevice
2017-07-04 23:32:55.156 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:05.180 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:15.160 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:25.188 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:35.165 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:45.200 (UPS) Calling message handler 'onHeartbeat'.
2017-07-04 23:33:45.201 Error: (UPS) Error reading UPS variables: BEGIN LIST VAR UPS
2017-07-04 23:33:45.202 (UPS) Variable UPS AC Frequency = None
2017-07-04 23:33:45.202 (UPS) Variable UPS Charge = None
2017-07-04 23:33:45.202 (UPS) Variable UPS Backup Time = None
2017-07-04 23:33:45.202 (UPS) Variable UPS Status = 0
2017-07-04 23:33:45.202 Error: (UPS) 'onHeartbeat' failed 'TypeError':'argument of type 'int' is not iterable'.
2017-07-04 23:33:45.202 Error: (UPS) ----> Line 143 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function onHeartbeat
2017-07-04 23:33:45.202 Error: (UPS) ----> Line 99 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function onHeartbeat
2017-07-04 23:33:45.202 Error: (UPS) ----> Line 111 in /home/gerard/domoticz/plugins/nut-ups/plugin.py, function UpdateDevice
2017-07-04 23:33:55.180 (UPS) Calling message handler 'onHeartbeat'.
The upsc tool command line utility is running fine from a shell session on the Ubuntu server:
- Spoiler: show
Code: Select all
upsc [email protected]
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: not set
battery.mfr.date: 2015/01/28
battery.runtime: 1440
battery.runtime.low: 120
battery.type: PbAc
battery.voltage: 13.5
battery.voltage.nominal: 12.0
Any ideas how this can be fixed?
Edit: fixed it by renaming the field UPS NUT name from "UPS Synology" to "ups". Apparently that field cannot contain spaces.
It's now working!
Re: Python plugin: UPS Monitor
Posted: Wednesday 05 July 2017 8:31
by Logread
marco.bag wrote:Unfortunately if I git-pull the new version the domoticz server do not start at all...
Any clue to solve that?
What version of domoticz ? I am facing issues with the latest beta builds since a few days that broke some device handling capabilities... for instance beta 3.8035 requires a (minor) rewrite of most of my plugins. I have not yet pulled these on Github pending testing and reading from the python plugin framework developers if they can help in understanding this issue. Will advise ASAP
Re: Python plugin: UPS Monitor
Posted: Wednesday 05 July 2017 8:46
by marco.bag
I'm running 3.8025
Very strange, you basically modified a couple of lines and the old version is working, the new one not... since i run it under ESXI i'll do more tests and i'll let you know

Re: Python plugin: UPS Monitor
Posted: Sunday 09 July 2017 15:41
by nmaster
Hi Logread,
I'm trying your UPS plugin on my domoticz v3.8070.
3 remote UPS and for now it's working fine.
Thank you for his nice work.
Re: Python plugin: UPS Monitor
Posted: Sunday 09 July 2017 17:51
by Logread
nmaster wrote:Hi Logread,
I'm trying your UPS plugin on my domoticz v3.8070.
3 remote UPS and for now it's working fine.
Thank you for his nice work.
Thanks for reporting and for your appreciation !
Re: Python plugin: UPS Monitor
Posted: Sunday 09 July 2017 17:51
by Logread
nmaster wrote:Hi Logread,
I'm trying your UPS plugin on my domoticz v3.8070.
3 remote UPS and for now it's working fine.
Thank you for his nice work.
Thanks for reporting and for your appreciation !
Re: Python plugin: UPS Monitor
Posted: Monday 10 July 2017 19:01
by nmaster
Hi Logread,
I have one of my ups that isn't accessible all the time because it's a desktop computer.
When this computer is off, ups can't be reached, so error comes while plugin tries to connect to it.
In this case the UPS status remain green (Online).
An idea of improvement would be to update the UPS Status sensor in this case to grey color (Not avaliable).
Apart from this, the plugin works nicely on 2 domoticz (me and a friend).
Re: Python plugin: UPS Monitor
Posted: Monday 10 July 2017 19:56
by Logread
nmaster wrote:Hi Logread,
I have one of my ups that isn't accessible all the time because it's a desktop computer.
When this computer is off, ups can't be reached, so error comes while plugin tries to connect to it.
In this case the UPS status remain green (Online).
An idea of improvement would be to update the UPS Status sensor in this case to grey color (Not avaliable).
Apart from this, the plugin works nicely on 2 domoticz (me and a friend).
Should be easy to implement... when I find the time I'll look into this (busy on vacations right now

)
Re: Python plugin: UPS Monitor
Posted: Tuesday 11 July 2017 1:14
by nmaster
OK,
good vacations to you

Re: Python plugin: UPS Monitor
Posted: Thursday 24 August 2017 10:18
by videodrome
Thanx Logread, very good job!
2 questions: i have only 5 switch (status, charge, backup time, Laad, input), why?
In blockly i added a new event:
if "UPS status mode"= "Backup Power" (as user variables)
then send message....
but this seems doesn't work.
Re: Python plugin: UPS Monitor
Posted: Thursday 24 August 2017 11:22
by Logread
videodrome wrote: ↑Thursday 24 August 2017 10:18
Thanx Logread, very good job!
2 questions: i have only 5 switch (status, charge, backup time, Laad, input), why?
In blockly i added a new event:
if "UPS status mode"= "Backup Power" (as user variables)
then send message....
but this seems doesn't work.
Thanks. I am not familiar with blockly but did you make this script a "device" event ? And I am confused with the reference you are making to user variables... hopefuly someone with blockly knowledge can help ?
Re: Python plugin: UPS Monitor
Posted: Thursday 24 August 2017 11:27
by Logread
videodrome wrote: ↑Thursday 24 August 2017 10:18
i have only 5 switch (status, charge, backup time, Laad, input), why?
Sorry, missed your other question. The devices created by the plugin depend on the NUT variables reported by your specific UPS hardware.
Re: Python plugin: UPS Monitor
Posted: Monday 28 August 2017 19:27
by TiXav
I have installed this plugin for 3 days, but I must deactivated it because domoticz crashs.
I put the plugin in debug mode
Code: Select all
2017-08-28 18:55:38.510 (MyUps) Calling message handler 'onHeartbeat'.
2017-08-28 18:55:38.560 (MyUps) Variable UPS Power = None
2017-08-28 18:55:38.560 (MyUps) Variable UPS Charge = 100
2017-08-28 18:55:38.560 (MyUps - UPS Charge) Updating device from 0:'100' to have values 0:'100'.
2017-08-28 18:55:38.564 (MyUps) Variable UPS AC Input = 236.0
2017-08-28 18:55:38.564 (MyUps - UPS AC Input) Updating device from 0:'236.0' to have values 0:'236.0'.
2017-08-28 18:55:38.568 (MyUps) Variable UPS Status = OL
2017-08-28 18:55:38.568 (MyUps) Variable UPS AC Frequency = None
2017-08-28 18:55:38.568 (MyUps) Variable UPS Load = 8
2017-08-28 18:55:38.568 (MyUps - UPS Load) Updating device from 0:'8' to have values 0:'8'.
2017-08-28 18:55:38.577 (MyUps) Variable UPS Backup Time = 450
2017-08-28 18:55:38.577 (MyUps - UPS Backup Time) Updating device from 0:'450' to have values 0:'450'.
2017-08-28 18:55:38.732 Error: Domoticz received fatal signal 11 !...
2017-08-28 18:55:38.743 Error: /home/pi/domoticz/domoticz() [0x22c6f8]
2017-08-28 18:55:38.743 Error: /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x22c7b0]
2017-08-28 18:55:38.743 Error: /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0)
2017-08-28 18:57:55.000 RxQueue: queue worker started...
2017-08-28 18:57:55.477 Incoming connection from: 192.168.1.4
2017-08-28 18:57:57.000 Hardware Monitor: Started
2017-08-28 18:57:57.016 WOL: Started
2017-08-28 18:57:57.017 (MyUps) Started.
Again below
Code: Select all
2017-08-24 15:55:19.197 Error: Domoticz received fatal signal 11 while backtracing !...
2017-08-24 15:55:19.197 Error: Domoticz received fatal signal 11 !...
2017-08-24 15:55:19.200 Error: /home/pi/domoticz/domoticz() [0x22c6f8]
2017-08-24 15:55:19.200 Error: /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x22c7b0]
2017-08-24 15:55:19.201 Error: /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0x76cd1180]
Before crashes, all devices are well updated by the plugin for 1h or 3h or 6h (max) then suddenly it crash.
Very strange and pity because before I used a personnal python script connected to Nut with PyNUTClient which upated dummy devices
Best Regards
Re: Python plugin: UPS Monitor
Posted: Monday 28 August 2017 20:01
by Logread
TiXav wrote: ↑Monday 28 August 2017 19:27
I have installed this plugin for 3 days, but I must deactivated it because domoticz crashs.
Before crashes, all devices are well updated by the plugin for 1h or 3h or 6h (max) then suddenly it crash.
There are apparently some issues with python plugins in recent beta versions of domoticz (python plugins have even been deactivated in latest betas since a couple of days, pending a fix possibly). Which version are you using ?
Re: Python plugin: UPS Monitor
Posted: Monday 28 August 2017 20:58
by TiXav
Ok, understood, you are right I saw some thing about that but I did not make the link in mind. I run 3.8364.
So I look forward a patch patiently
Thank you