Python plugin: UPS Monitor

Python and python framework

Moderator: leecollings

User avatar
TiXav
Posts: 38
Joined: Saturday 28 November 2015 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by TiXav »

For your information or for the others in the same case :
I come back to stable version : Domoticz crashes until the UPS plugin is activated

Yesterday evening, I did :
sudo apt-get update
sudo apt-get upgrade

then now it looks like working fine since

regards.
lrybak
Posts: 40
Joined: Thursday 18 December 2014 20:12
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Poland
Contact:

Re: Python plugin: UPS Monitor

Post by lrybak »

Thanks, very usefull. It works with QNAP (UPS NUT name: qnapups, default port) with no issues
HW: HP dc7900 USD running ESXi, RaspberryPi (few of it), AEON S2 USB stick, Fibaro modules (Dimmers, switches), 1-wire (DS18B20, DS2423), DSC Alarm with Envisalink ethernet module, MySensors, RFLink
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

@TiXav and @Irybak,

Many thanks for your feedback for the community. Glad this works well for you.
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python plugin: UPS Monitor

Post by ycahome »

Logread wrote: Friday 30 June 2017 18:17 Another python plugin that I wrote that I am releasing in case anyone finds it useful.
Hello Logread and thank you for this wonderful plugin.

I own the "EATON 5E 650i" Ups and i thought that everything was OK, till i was realised that "UPS Status Mode" was not updated (except the first time on installation).

After some troubleshooting, found the following correction that need to be done:

My output for "status" is

Code: Select all

VAR ups ups.status "OL CHRG"
so i have added one more case on the "ups.status" value check:

changed from:

Code: Select all

            if key == "ups.status":
                nvalue = 1 if "OL" in self.variables[key][2] else 4
                svalue = "On Line" if "OL" in self.variables[key][2] else "Backup Power"


to:

Code: Select all

            if key == "ups.status":
                nvalue = 1 if "OL" in self.variables[key][2] else 4
                svalue = "On Line" if "OL" in self.variables[key][2] else "Backup Power"
                svalue = "On Line - Charging" if "OL CHRG" in self.variables[key][2] else "Backup Power"
everything seems OK now.

Its time to bring more functionality to this plugin by processing all possible values of "ups.status":

Code: Select all

OL      - On line (mains is present)
OB      - On battery (mains is not present)
LB      - Low battery
HB      - High battery
RB      - The battery needs to be replaced
CHRG    - The battery is charging
DISCHRG - The battery is discharging (inverter is providing load power)
BYPASS  - UPS bypass circuit is active - no battery protection is available
CAL     - UPS is currently performing runtime calibration (on battery)
OFF     - UPS is offline and is not supplying power to the load
OVER    - UPS is overloaded
TRIM    - UPS is trimming incoming voltage (called "buck" in some hardware)
BOOST   - UPS is boosting incoming voltage
FSD     - Forced Shutdown (restricted use, see the note below)
am thinking something like:

Code: Select all

UpsStatusCode = self.variables[key][2].find("OB", beg=0, end=len(string))
.....
.....
.....
if UpsStatusCode is OB or CHRG or DISCHRG or BYPASS or CAL or BOOST or FSD then raise a warning
if UpsStatusCode is RB or OVER or TRIM then raise an alarm



My regards,
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

@ycahome,

Thanks for your appreciation and suggestions... my own UPS does not have all these status levels, so did not think about these.

These would be great additions, though I am pretty tied up at the moment with my day job so not sure I can devote much time to this effort for now.

If you are willing to contribute code through GitHub via a pull request, please do so. If not you’ll have to bear with me.
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Python plugin: UPS Monitor

Post by assenzuid »

It works fine, but i noticed that since begin this month the plugin not works anymore

Error log:
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) 'onHeartbeat' failed 'EOFError'.
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 138 in /home/pi/domoticz/plugins/NUT_UPS/plugin.py, function onHeartbeat
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 82 in /home/pi/domoticz/plugins/NUT_UPS/plugin.py, function onHeartbeat
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 327 in /usr/lib/python3.5/telnetlib.py, function read_until
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 403 in /usr/lib/python3.5/telnetlib.py, function read_very_lazy
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Python plugin: UPS Monitor

Post by assenzuid »

assenzuid wrote: Tuesday 23 January 2018 16:30 It works fine, but i noticed that since begin this month the plugin not works anymore

Error log:
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) 'onHeartbeat' failed 'EOFError'.
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 138 in /home/pi/domoticz/plugins/NUT_UPS/plugin.py, function onHeartbeat
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 82 in /home/pi/domoticz/plugins/NUT_UPS/plugin.py, function onHeartbeat
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 327 in /usr/lib/python3.5/telnetlib.py, function read_until
2018-01-23 16:29:07.874 Error: (APC UPS02 Office) ----> Line 403 in /usr/lib/python3.5/telnetlib.py, function read_very_lazy
Solved after rebooting Qnap NAS
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

@ycahome,
I actually found some spare time... testing the code for now. Will share updated plugin for your testing if you do not mind
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python plugin: UPS Monitor

Post by ycahome »

Logread wrote: Tuesday 23 January 2018 19:16 @ycahome,
I actually found some spare time... testing the code for now. Will share updated plugin for your testing if you do not mind
Nice
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

New version 0.2.0 is available. For install/upgrade, please follow instructions from the wiki (https://www.domoticz.com/wiki/Plugins/NUT_UPS.html)

As suggested by @ycahome, the plugin now handles many more UPS status states and corresponding alert levels, as per list below:

Code: Select all

           #code       (display,           alarm level)
            "OL":       ("ONLINE",          1), # On line (mains is present)
            "OB":       ("ONBATTERY",       4), # On battery (mains is not present)
            "LB":       ("LOWBATTERY",      4), # Low battery
            "HB":       ("HIGHBATTERY",     1), # High battery
            "RB":       ("REPLACEBATTERY",  3), # The battery needs to be replaced
            "CHRG":     ("CHARGING",        1), # The battery is charging
            "DISCHRG":  ("DISCHARGING",     3), # The battery is discharging (inverter is providing load power)
            "BYPASS":   ("BYPASS",          3), # UPS bypass circuit is active - no battery protection is available
            "CAL":      ("CALLIBRATION",    1), # UPS is currently performing runtime calibration (on battery)
            "OFF":      ("OFF",             0), # UPS is offline and is not supplying power to the load
            "OVER":     ("OVERLOAD",        4), # UPS is overloaded
            "TRIM":     ("SMARTTRIM",       3), # UPS is trimming incoming voltage (called "buck" in some hardware)
            "BOOST":    ("BOOST",           3), # UPS is boosting incoming voltage
            "FSD":      ("FORCE_SHUTDOWN",  4)  # Forced Shutdown
 
Partially tested only, so please report any issue/bug (excluding general Domoticz Python Plugins framework issues please... nothing I can do about these).
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python plugin: UPS Monitor

Post by ycahome »

Logread wrote: Wednesday 31 January 2018 8:36 New version 0.2.0 is available.
Thanks a lot LogRead for this upgraded version.
eeco800.JPG
eeco800.JPG (19.06 KiB) Viewed 6041 times
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Python plugin: UPS Monitor

Post by hamster »

@Logread It seems that when I don't have the domoticz GUI open, the virtual devices do not continue to update. Is this expected behavior? For example, I set a notification for "last update" to 10 minutes. Well, exactly 10 minutes (or any amount I set) after I close the GUI, the notification fires.

On that note, how do you recommend setting alarms for different values such as time remaining, charge amount, etc?

Thanks!
Last edited by hamster on Thursday 08 February 2018 3:03, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python plugin: UPS Monitor

Post by waaren »

Logread wrote: Wednesday 31 January 2018 8:36 New version 0.2.0 is available. For install/upgrade, please follow instructions from the wiki (https://www.domoticz.com/wiki/Plugins/NUT_UPS.html)

Partially tested only, so please report any issue/bug (excluding general Domoticz Python Plugins framework issues please... nothing I can do about these).
@logread

Many thanks for this excellent plugin. I already used it on my other domoticz installations and because I am testing with Jessie on my PI3 to investigate if I encounter less problems with domoticz beta with Python plugins in general, I installed it on that instance as well.

The problem I encountered there was:

Error: (Synology UPS) Error reading UPS variables_: ERR ACCESS-DENIED

after quite some comparing between the working (Stretch) instance and the on Jessie, I finally came to the network settings.

on the working version (Stretch)
ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.xxx.51 netmask 255.255.255.0 broadcast 192.168.xxx.255
...........

and on the failing one (Jessie)
ifconfig eth0
eth0 Link encap:Ethernet HWaddr b8:27:eb:95:ca:49
inet addr:192.168.xxx.97 Bcast:0.0.0.0 Mask:255.255.255.0
.........

After the command ifconfig eth0 broadcast 192.168.xxx.255
and a restart of the plugin (disable / enable ) in domoticz. The information from my UPS came in and the device got updated.

Is this something worthwhile to add to the wiki ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Python plugin: UPS Monitor

Post by hamster »

In addition to previous question: Do you have any plans to create a plugin version to work with beta versions? The way the beta handles plugins will eventually be the stable way, so was hoping you might be willing to have two versions until the merge :)
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

@waaren,

Interesting catch but in my view this is more to be reported under raspberry pi network configuration (localhost loopback), as it is not specific to this plugin.

@hamster: not sure I get your question. The plugin had factored the breaking changes to the python framework long ago and it works well with betas (putting aside some issues certain users seem to have with stability of the plugin framework, that are not specific to this particular plugin it seems).
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Python plugin: UPS Monitor

Post by hamster »

odd, I recently went from stable to beta and now the plugin doesnt show in the hardware list at all. completely disappeared.

edit: DONKEY BALLS. so, apparently the "enabled" slider for lua/events/scripts wasnt showing properly in Chrome, so the thing was disabled this whole time. finally ran across another forum post that mentioned it and got it fixed... geez. sorry for false report. Thanks for the nice plugin!

edit2: note to any future readers, dont rename any of the devices from their defaults. will break any script you might want to use with this.
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Python plugin: UPS Monitor

Post by hamster »

new question:

I'm currently troubleshooting a stale data issue with nut, I know that isn't your territory BUT, I'm noticing that even when nut is reporting stale data AND the errors are showing in domoticz log, that the plugin is still refreshing the virtual sensors with the stale data as if everything is normal. Is there a way for the plugin to make the virtual sensors stop updating? That would allow me to monitor "last seen" to be notified when data goes stale.

Or, do you know how I might send a notification when "Error: (CyberPower) Error reading UPS variables: ERR DATA-STALE" shows up in the domoticz log?

Thanks!
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

hamster wrote: Wednesday 14 February 2018 23:52 the plugin is still refreshing the virtual sensors with the stale data as if everything is normal. Is there a way for the plugin to make the virtual sensors stop updating? That would allow me to monitor "last seen" to be notified when data goes stale.
Yes, this is on my to do list... easy to implement. Bear with me please.
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Python plugin: UPS Monitor

Post by Logread »

New version 0.2.1 is available. For install/upgrade, please follow instructions from the wiki (https://www.domoticz.com/wiki/Plugins/NUT_UPS.html).

This version changes the handling of communication errors with the UPS or the NUT server, as suggested by @hamster: in this event:
  • the plugin stops updating the devices
  • the "UPS Status" device is marked as "Timed Out" (Red bar in GUI) if the host domoticz version handles this (only recent betas do)
  • the "UPS Status" device shows "COMMUNICATION ERROR and its alert level is 0 (grey icon)
Partially tested only, so please report any issue/bug (excluding general Domoticz Python Plugins framework issues please... nothing I can do about these).
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Python plugin: UPS Monitor

Post by ycahome »

Logread wrote: Thursday 15 February 2018 14:13 so please report any issue/bug (excluding general Domoticz Python Plugins framework issues please... nothing I can do about these).
Hello Logread.

I think that your wiki guide for upgrade has an error

Code: Select all

get reset –-hard
should be?

Code: Select all

git reset –-hard
regards,
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest