HowTo: Node Red - Read UPS status

Eine dieser Schwachstellen eines SmartHome-Systems die einem erst so richtig bewusst wird, wenn etwas schief läuft ist „Energie“. Die ganzen Sensoren, Aktoren und die steuernde Intelligenz dahinter laufen ja nun leider nicht mit Luft und Liebe. Und auch wenn die von dem System genutzte Energie nicht sehr hoch und generell die Ersparnis dadurch sicherlich höher als die „verbrauchte“ Energie ist, so ist die Versorgungsenergie doch essenziell. Sprich: Kein Strom-> kein SmartHome.

But that's a luxury problem that I could live with for the time being. What I find much worse is the thought that my RaspberryPi, or any computer in general, could be swallowed up by a sudden power failure in such a way that it might no longer boot up afterwards.
If your SmartHome system (RaspberryPi, BeagleBone, Windows PC, etc.) is interrupted just at the moment when it is writing important (system) data, it is possible that it will no longer boot up properly after the power supply is restored. In extreme cases, this can lead to a painful loss of data and often to a considerable loss of time. In extreme cases, there is no backup of the system and the entire system, including all system components, has to be reinstalled and reconfigured.

However, it seems that other people have also encountered this problem. Uninterruptible power supplies (UPSs) were invented for this case. These devices are connected between the socket and the load (in this case your RaspberryPi, etc.) and from then on continuously monitor the quality of your mains voltage. In other words, they continuously monitor whether the incoming AC voltage and frequency are within the permitted range. If an undervoltage or overvoltage occurs, or if something else is wrong with the supply voltage, the UPS switches off the voltage input within milliseconds and switches to an internal buffer battery. This then takes over the supply to the connected loads until the buffer battery is empty.

UPSs are now available in all kinds of forms. The smallest ones look like somewhat clunky multiple sockets. Others - or rather their batteries - can fill an entire room.

For the normal SmartHome user, the smaller versions will certainly suffice. Like for example ...

This article explains how you can integrate your own UPS into NodeRed and react to changes.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
So that you can control/configure your UPS via your RaspberryPi and NodeRed, it should of course be prepared so that NodeRed runs on it and you can access it via SSH.

RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed - import and export node code
NodeRed - Send pushbullet messages for events
NodeRed - Create a user interface with dashboard nodes

Required material:

In the following list you will find all the parts you need to implement this article.


Reading out a UPS connected to the RaspberryPi

The disadvantage of an uninterruptible power supply is that the RaspberryPi does not notice anything as soon as something is not (or no longer) right with the power supply. This is actually what is desired. On the other hand, the RaspberryPi cannot react to this change.

Even if the battery of a UPS is quite large compared to the consumption of a RaspberryPi, the battery capacity is finite. For this reason, the RaspberryPi should shut down automatically before the battery is fully depleted. This minimizes the risk of data loss and allows a controlled response to the power failure.

The UPS must be connected to the RasperryPi via a USB or serial connection so that the RasperryPi can be informed about changes.

Für den RaspberryPi gibt es dazu das Programm „Apcupsd“, welches es Euch ermöglicht den Status Eurer USV einzulesen. Diesen Status könnt Ihr dann ebenfalls dazu nutzen um per NodeRed darauf zu reagieren.

For example, it would also be possible to switch off certain components or shut down other RaspberryPi's - if they have not already failed due to the power failure.

Bevor Ihr allerdings den Status Eurer USV in NodeRed auslesen könnt, muss zunächst „apcupsd“ installiert werden.


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

After entering your username and password you can enter the first commands.

Update package management

The package management in Linux is a "central place" through which various software packages can be installed. In order for this to work reliably, the lists and sources of the package management should be updated before each installation of new packages.

To start the update of the package management you have to enter the following command.
sudo apt-get update && sudo apt-get upgrade
Depending on how long ago your last update of the package management was, this process can now take a while. The lists that refer to the individual package sources are updated first.
After that, the packages themselves are updated. Since additional memory is occupied, you will be asked again for your consent. You have to confirm this with a "J" and "Enter".
Once the update is complete, you will see a small summary of the duration and scope of the update.

„apcupsd“ auf dem RaspberryPi installieren

To enable your RaspberryPi to communicate with the connected UPS, you must first install a few packages.

Ein Programm dass direkt mit Eurer über USB angeschlossenen USV kommunizieren kann ist das Programm „apcupsd“, welches Ihr mit folgendem Befehl installiert.
sudo apt-get install apcupsd
Eventuelle Nachfragen, dass durch das Programm zusätzlicher Speicher belegt wird, bestätigt Ihr mit „J“.
The installation takes about two minutes.

Configure Apcupsd

Bevor Ihr „apcupsd“ nutzen könnt, muss dieses zunächst natürlich noch konfiguriert werden. Dazu müssen ein paar Konfigurationsdateien bearbeitet werden.

Open the first configuration file with the following command.
sudo nano /etc/apcupsd/apcupsd.conf
In the opened configuration file you must now first use the arrow keys to...
…bis zur dargestellten Zeile navigieren. Dort wird festgelegt, über welchen Kabeltyp die USV mit Eurem RaspberryPi verbunden ist. Sehr wahrscheinlich ist Eure USV über den USB-Anschluss mit Eurem RaspberryPi verbunden. Deshalb stellt Ihr hier auch „UPSCABLE usb“ ein.
UPSCABLE usb
Since you have connected a USB cable, you must of course also set the UPSTYPE to usb.
UPSTYPE usb
Damit die Verbindung zur USV über USB funktioniert, müsst Ihr nun noch den Parameter „DEVICE“ bearbeiten. Diesem darf kein Wert zugewiesen werden. Entfernt dazu also den abgebildeten Teil „/dev/ttsyS0“ neben „DEVICE“.
This should look like this.
Nun könnt Ihr noch ein paar Einstellungen vornehmen, wie sich apcupsd im Fall eines Stromausfalls verhalten soll. Mit dem Parameter „BATTERYLEVEL“ lässt sich zum Beispiel einstellen, dass der RaspberryPi bei einem verbleibenden Ladezustand der USV von 5% heruntergefahren wird.
Der Parameter „MINUTES“ gibt dabei an bei welcher Restlaufzeit in Minuten der RaspberryPi heruntergefahren werden soll.
Mit dem Parameter „NETSERVER“ könnt Ihr einen Nertzwerkserver aktivieren, der die Informationen der USV über das Netzwerk zur Verfügung stellt. So können auch andere Netzwerkteilnehmer im Falle eines Stromausfalls ebenfalls auf diesen reagieren und zum Beispiel herunterfahren. Um den Netzwerkserver zu aktivieren müsst Ihr den Parameter auf „NETSERVER on“ einstellen.
Mithilfe des Parameters „NISIP“ könnt Ihr einstellen auf welche IP-Adresse der Server „höhrt“. Dies ist nur dann nötig, wenn Ihr mehr als eine Netzwerkinterface an dem betreffendem System habt. An einem RaspberryPi könntet Ihr damit zum Beispiel einstellen, dass der Server nur anfragen Beantwortet die er über das WLAN-Interface und nicht über das LAN-Interface erhält. In den meisten Fällen könnt Ihr diesen Parameter allerdings auf „NISIP 0.0.0.0“ einstellen. Dies bedeutet, dass alle Anfragen, unabhängig vom Netzwerk-Interface, beantwortet werden.
Durch den Parameter „NISPORT“ wird der Port festgelegt unter dem die Informationen des Servers abgerufen werden können. Diesen solltet Ihr unverändert auf dem Wert „3551“ eingestellt lassen.
Diese Konfiguration speichert Ihr dann mit einem Druck auf „STRG-X“ und „J“…
…und „Enter“.
Now you have to tell apcupsd that a configuration exists. To do this, open another configuration file with the following command.
sudo nano /etc/default/apcupsd
Stellt den Parameter „ISCONFIGURED“ dazu auf…
…“yes“ ein.
Diese Konfiguration speichert Ihr dann wieder mit einem Druck auf „STRG-X“ und „J“…
…und „Enter“.
The apcupsd service can then be started with the following command.
sudo /etc/init.d/apcupsd start
Once the program has started successfully, it should look like this.
Mit dem Befehl „apcaccess status“ lässt sich dann der aktuelle Status der USV anzeigen. Sollte keine Verbindung zur USV hergestellt werden können sieht die Antwort wie abgebildet aus.
apcaccess status
If the connection to the UPS is established and the information can be read out, the information shown will be displayed.
Solltet Ihr „apcupsd“ mal neustarten müssen reicht die Eingabe des folgenden Befehls.
sudo /etc/init.d/apcupsd restart

You now have the option of displaying the UPS information on the RaspberryPi. To use this information for your SmartHome, you can use the following NodeCode.


Import node code

You can use the following NodeCode to display a few details of the current status of your UPS. This allows you to react individually to certain properties.

For example, it would be possible to be notified of a power failure via a pushbullet message or to display the most important data on the dashboard, as in the example below. To ensure that pushbullet messages can be sent in the event of a power failure, you should of course make sure that your entire network infrastructure is also protected by the UPS. However, if the power failure is very extensive, even this will of course no longer help. Therefore, communication via the Internet is of course not guaranteed in the event of a power failure.

How to import NodeCode into your NodeRed configuration is described in the article NodeRed - import and export node code described above. After importing, you may also need to configure the pushbullet node. You can find information on this in the article NodeRed - Send pushbullet messages for events. Dashboard nodes are used to display the UPS data. You can find information about this in the article NodeRed - Create a user interface with dashboard nodes.

View the UPS status display in the dashboard.
Overview of the NodeCode configuration in the NodeRed configuration interface.
[{"id":"e2a1a48.9207858","type":"exec","z":"8c9f8f17.13eb78","command":"/sbin/apcaccess","append":"","useSpawn":"","name":"apcaccess","x":390,"y":1740,"wires":[["c5f64040.b7a32","9ef1333b.1cf96"],[],[]]},{"id":"ebe2e46e.660788","type":"inject","z":"8c9f8f17.13eb78","name":"status request","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":200,"y":1740,"wires":[["e2a1a48.9207858"]]},{"id":"c5f64040.b7a32","type":"trigger","z":"8c9f8f17.13eb78","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"1","extend":true,"units":"min","reset":"","bytopic":"all","name":"status","x":570,"y":1700,"wires":[["c65a87d0.d60ef8"]]},{"id":"c65a87d0.d60ef8","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"change","p":"topic","pt":"msg","from":"^(.*)$","fromt":"re","to":"online","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":1700,"wires":[["e9c65962.f1bd98"]]},{"id":"9ef1333b.1cf96","type":"function","z":"8c9f8f17.13eb78","name":"convert2Json","func":"const ans = {}

Array.prototype.map.call( msg.payload.trim().split("\n"), function(line) 
{
    if ( line.trim() === '' ) return
    let part = line.split(':')
    // Some values contain ':', when they do, we have to rejoin
    if ( part.length > 2 ) {
        let newPart = []
        newPart.push( part.shift() )
        newPart.push( part.join(':') )
        part = newPart
    }
    
    let payloadName = part[0].toLowerCase().trim()
    let payloadValue = part[1].trim()
    ans[payloadName] = payloadValue
    return
    
} )

msg.payload = ans

return msg","outputs":1,"noerr":0,"x":600,"y":1760,"wires":[["7177d00d.0f8c1","f49b6561.709b18","9cd3b15b.3aa0a","cbdff947.6252f8","9a68559b.2e0408","a998a9f0.b4c2f8","cbb1400b.8107f","4db0abb3.948d94"]]},{"id":"e9c65962.f1bd98","type":"debug","z":"8c9f8f17.13eb78","name":"online/offline-Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":980,"y":1700,"wires":[]},{"id":"7177d00d.0f8c1","type":"debug","z":"8c9f8f17.13eb78","name":"Data as JSON payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":840,"y":1760,"wires":[]},{"id":"90dd24c3.50c968","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Battery charge","group":"c8fbbc62.c288a","order":4,"width":0,"height":0,"gtype":"gage","title":"Battery charge:","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#ca3838","#e6e600","#00b500"],"seg1":"","seg2":"","x":1080,"y":1800,"wires":[]},{"id":"4b7d84af.22ddfc","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Batterie-Temperature","group":"c8fbbc62.c288a","order":5,"width":0,"height":0,"gtype":"gage","title":"Batterie-Temperature:","label":"°C","format":"{{value}}","min":"20","max":"40","colors":["#00b500","#00b500","#ca3838"],"seg1":"","seg2":"","x":1100,"y":1840,"wires":[]},{"id":"c655e83c.23f538","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Batterie-Voltage","group":"c8fbbc62.c288a","order":6,"width":0,"height":0,"gtype":"gage","title":"Batterie-Voltage:","label":"V","format":"{{value}}","min":"11","max":"15","colors":["#ca3838","#00b500","#ca3838"],"seg1":"","seg2":"","x":1080,"y":1880,"wires":[]},{"id":"3ce99364.46890c","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Mains voltage","group":"c8fbbc62.c288a","order":7,"width":0,"height":0,"gtype":"gage","title":"Mains voltage:","label":"V","format":"{{value}}","min":"220","max":"240","colors":["#ca3838","#00b500","#ca3838"],"seg1":"","seg2":"","x":1080,"y":1920,"wires":[]},{"id":"810aaaf7.ec4f48","type":"ui_text","z":"8c9f8f17.13eb78","group":"c8fbbc62.c288a","order":1,"width":0,"height":0,"name":"Status","label":"Status:","format":"{{msg.payload}}","layout":"row-spread","x":1050,"y":1960,"wires":[]},{"id":"f49b6561.709b18","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.bcharge","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1800,"wires":[["90dd24c3.50c968"]]},{"id":"9cd3b15b.3aa0a","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.itemp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1840,"wires":[["4b7d84af.22ddfc"]]},{"id":"cbdff947.6252f8","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battv","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1880,"wires":[["c655e83c.23f538"]]},{"id":"9a68559b.2e0408","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.linev","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1920,"wires":[["3ce99364.46890c"]]},{"id":"a998a9f0.b4c2f8","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1960,"wires":[["810aaaf7.ec4f48"]]},{"id":"5f70becf.c02b8","type":"ui_text","z":"8c9f8f17.13eb78","group":"c8fbbc62.c288a","order":2,"width":0,"height":0,"name":"Last Update","label":"Last Update:","format":"{{msg.payload}}","layout":"row-spread","x":1070,"y":2000,"wires":[]},{"id":"cbb1400b.8107f","type":"function","z":"8c9f8f17.13eb78","name":"","func":"msg.payload=Date(Date.now());
return msg;","outputs":1,"noerr":0,"x":790,"y":2000,"wires":[["5f70becf.c02b8"]]},{"id":"4db0abb3.948d94","type":"function","z":"8c9f8f17.13eb78","name":"","func":"if (msg.payload.linev<=100)
{
    msg.payload="Power failure: UPS-Mains-voltage below 100V!";
    return msg;
}","outputs":1,"noerr":0,"x":790,"y":2040,"wires":[["f62fd4e0.66c8b8"]]},{"id":"f62fd4e0.66c8b8","type":"pushbullet","z":"8c9f8f17.13eb78","config":"e3daf163.eeb16","pushtype":"note","title":"SmartHome","chan":"","name":"","x":1070,"y":2040,"wires":[]},{"id":"622137c.74419c8","type":"inject","z":"8c9f8f17.13eb78","name":"Test Power failure","topic":"","payload":"60","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":2040,"wires":[["4f72d77f.af5ee8"]]},{"id":"4f72d77f.af5ee8","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"temp","pt":"flow","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.linev","pt":"msg","to":"temp","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":2040,"wires":[["4db0abb3.948d94"]]},{"id":"c8fbbc62.c288a","type":"ui_group","z":"","name":"USV2","tab":"4719e8d9.2a46f8","disp":true,"width":"6","collapse":false},{"id":"e3daf163.eeb16","type":"pushbullet-config","z":"","name":"FabsPushbullet"},{"id":"4719e8d9.2a46f8","type":"ui_tab","z":"","name":"Einstellungen","icon":"dashboard"}]

Reading a UPS connected to a Synology NAS

If you have a Synology NAS or a NAS in general, the issue of data loss is even more important. After all, the family photos (or some of them) shouldn't disappear into data nirvana in the event of a power outage. That's why many manufacturers offer the function of protecting your own NAS from power failures with a UPS. The UPS is then connected to the NAS via USB in order to be able to provide information about a status change. If a power failure occurs, the NAS detects this and shuts down automatically and in a controlled manner. Practical and good for the data stored on the NAS. At the same time, it is impractical that the other network participants do not find out about the situation (except that the power has gone out).

At least the NAS from Synology offer a solution for this: via an integrated network UPS server, other network participants can also record the status of the UPS connected to the NAS. This means you can ultimately record the status on the RaspberryPi and therefore also in NodeRed.

In order for the network UPS server to work, it must first be set up. To do this, go to the Control Panel of the DiskStationManager (DSM) interface...
… und zur Kategorie „Hardware & Energie“. Dort klickt Ihr auf die Karteikarte „USV“.
Dort sollte die angeschlossene USV bereits konfiguriert sein. In diesem Fall wird das NAS nach dem Auftreten eines Stromausfalls nach 3 Minuten automatisch heruntergefahren. Um nun den Netzwerk-USV-Server zu aktivieren, setzt Ihr einen Haken bei „Netzwer-USV-Server aktivieren“ und klickt auf den Button „Zugelassene DiskStation Geräte“.
In dem sich nun öffnendem Fenster könnt Ihr mehrere IP-Adressen von Geräten in Eurem Netzwerk eintragen, denen es erlaubt ist auf die Informationen des Netzwerk-USV-Servers zuzugreifen. Dieses so genannte „Whitelist“-Verfahren stellt sicher, dass nur berechtigte Netzwerkteilnehmer diese Informationen erhalten können. In diesem Feld tragt Ihr wie abgebildet die IP-Adresse Eures RaspberryPi’s ein von dem Ihr per NodeRed den USV-Status einlesen wollt. Wie Ihr die IP-Adresse der Geräte in Eurem Netzwerk herausfindet ist im Artikel Display/find out the IP address of the devices in the network beschrieben. Habt ihr die IP-Adresse eingetragen klickt Ihr auf „OK“…
…und im darauffolgenden Fenster auf „Übernehmen“.

Install the NetworkUpsTools(NUT) on the RaspberryPi to retrieve UPS data from a UPS server

Nun wo der Server zur Bereitstellung der USV Informationen eingerichtet ist, muss natürlich auch die Client-Seite(also Euer RaspberryPi) entsprechend konfiguriert werden. Denn dieser muss natürlich auch Kontakt zu dem Netzwerk-USV-Server auf Eurem NAS aufnehmen können. Ein Programm dass dies ermöglicht ist das „NetworkUpsTool“, welches wie folgt installiert werden kann.

Zum installieren der Anwendung „NUT“ müsst Ihr folgenden Befehl eingeben.
sudo aptitude install nut

A notice: Für die Installation von „NUT“ benötigt Ihr die Erweiterung „aptitude“ für die Paketverwaltung „APT“. Diese lässt sich – falls nicht bereits vorhanden – mit folgendem Befehl installieren.

sudo apt-get install aptitude

Eventuelle Fragen während der Installation bestätigt Ihr mit einem „y“ und „Enter“. Meistens(wie auch in diesem Beispiel) beziehen sich diese Fragen darauf, ob durch die zu installierenden Tools zusätzlicher Speicherplatz belegt und ob auch weitere (benötigte) Pakete installiert werden dürfen.

Nach der Installation muss „NUT“ noch konfiguriert werden. Dazu öffnet Ihr die Konfigurationsdatei mit dem folgenden Befehl.
sudo nano /etc/nut/nut.conf
In the now open configuration file, use the arrow keys to navigate to the line shown.
Dort angekommen ändert Ihr die Zeile von „Mode=none“ zu „Mode=netclient“. Dies teil „NUT“ mit, dass es als Netzwerk-Client für einen Netzwerk-USV-Server fungieren soll.
mode=netclient
Diese Konfiguration speichert Ihr mit einem Druck auf „STRG-X“ und „J“…
…und letztendlich auf „Enter“.
Now, of course, you still have to configure the address at which the network UPS server can be reached. To do this, open another configuration file with the following command.
sudo nano /etc/nut/upsmon.conf
Navigiert dann mit den Pfeiltasten bis Ihr in der angegebenen Zeile angekommen seid. Dort muss die Zeile „MONITOR ups@*IP-ADRESSE-EURER-NAS* 1 monuser secret slave“ eingefügt werden. Dabei muss *IP-ADRESSE-EURER-NAS* natürlich durch die IP-Adresse Eures Netzwerk-USV-Servers also Eurer NAS ersetzt werden. Nur so weiß NUT woher es die USV-Informationen beziehen kann.
MONITOR ups@*IP-ADDRESS-YOUR-NAS* 1 monuser secret slave
Diese Konfiguration speichert Ihr dann wieder mit einem Druck auf „STRG-X“ und „J“…
…und letztendlich auf „Enter“.
Damit die Änderungen an der Konfigurationsdatei übernommen werden müsst Ihr den NUT-Clienten nun nur noch neu starten. Dies geht mit dem Befehl „sudo service nut-client restart“.
sudo service nut-client restart
Mithilfe des Befehls „sudo upsc ups@*IP-ADRESSE-EURER-NAS*“ könnt Ihr nun die aktuellen Informationen zu Eurer USV vom Netzwerk-USV-Server abrufen. Dabei muss *IP-ADRESSE-EURER-NAS* natürlich wieder durch die IP-Adresse Eures Netzwerk-USV-Servers also Eurer NAS ersetzt werden.
sudo upsc ups@*IP-ADDRESS-YOUR-NAS*
The information will then be displayed to you according to the specified pattern. This displays, for example, the charging status, the model and various voltages.

Import node code

With the following NodeCode you can display a few details of the current status of your UPS connected to your Synology NAS. This means you can react individually to certain characteristics.

For example, it would be possible to be notified of a power failure via a pushbullet message or to display the most important data on the dashboard, as in the example below. To ensure that pushbullet messages can be sent in the event of a power failure, you should of course make sure that your entire network infrastructure is also protected by the UPS. However, if the power failure is very extensive, even this will of course no longer help. Therefore, communication via the Internet is of course not guaranteed in the event of a power failure.

How to import NodeCode into your NodeRed configuration is described in the article NodeRed - import and export node code described above. After importing, you may also need to configure the pushbullet node. You can find information on this in the article NodeRed - Send pushbullet messages for events. Dashboard nodes are used to display the UPS data. You can find information about this in the article NodeRed - Create a user interface with dashboard nodes.

View the UPS status display in the dashboard.
Overview of the NodeCode configuration in the NodeRed configuration interface.
[{"id":"b7aefd76.e8bf9","type":"comment","z":"8c9f8f17.13eb78","name":"USV-Server data request","info":"","x":170,"y":2160,"wires":[]},{"id":"66e7a9bd.eb6c58","type":"inject","z":"8c9f8f17.13eb78","name":"","topic":"status request","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":180,"y":2240,"wires":[["d3649b9.f1b5468"]]},{"id":"d3649b9.f1b5468","type":"exec","z":"8c9f8f17.13eb78","command":"sudo upsc ups@192.168.3.59","addpay":false,"append":"","useSpawn":"","timer":"","oldrc":false,"name":"get UPS status","x":420,"y":2240,"wires":[["22edb893.55ed38"],[],[]]},{"id":"22edb893.55ed38","type":"function","z":"8c9f8f17.13eb78","name":"convert2Json","func":"const convertData = {}

Array.prototype.map.call( msg.payload.trim().split("\n"), function(line) 
{
    if ( line.trim() === '' ) return
    let part = line.split(':')
    
    // Some values contain ':', when they do, we have to rejoin
    if ( part.length > 2 ) {
        let newPart = []
        newPart.push( part.shift() )
        newPart.push( part.join(':') )
        part = newPart
    }
    
    let payloadName = part[0].toLowerCase().trim()
    payloadName = part[0].replace(/\./g, "_")
    let payloadValue = part[1].trim()
    convertData[payloadName] = payloadValue
    return
    
} )

msg.payload = convertData

return msg","outputs":1,"noerr":0,"x":630,"y":2240,"wires":[["61f07a9c.f54824","a1504bd4.049f18","4e4d02.d85ad3","641d6b8a.a25e34","49343e5b.85218","3c698623.45215a","83b9ebee.451878","282426fe.c5650a","50224b5b.8a4164"]]},{"id":"61f07a9c.f54824","type":"debug","z":"8c9f8f17.13eb78","name":"Data as JSON payload","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":920,"y":2240,"wires":[]},{"id":"21f21239.2c2bce","type":"ui_text","z":"8c9f8f17.13eb78","group":"6f8a5651.9e0318","order":0,"width":0,"height":0,"name":"Test:","label":"Test:","format":"{{msg.payload}}","layout":"row-spread","x":1130,"y":2480,"wires":[]},{"id":"a1504bd4.049f18","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery_charge","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2280,"wires":[["3442fea.41d6702"]]},{"id":"4e4d02.d85ad3","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery_temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2320,"wires":[["5362d4fa.9026ac"]]},{"id":"641d6b8a.a25e34","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery_voltage","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2360,"wires":[["bd21c5da.510bc8"]]},{"id":"49343e5b.85218","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.input_voltage","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2400,"wires":[["22a47d9.d019982"]]},{"id":"3c698623.45215a","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ups_status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2440,"wires":[["6a33c3ab.06088c"]]},{"id":"83b9ebee.451878","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ups_test_result","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":2480,"wires":[["21f21239.2c2bce"]]},{"id":"282426fe.c5650a","type":"function","z":"8c9f8f17.13eb78","name":"","func":"msg.payload=Date(Date.now());
return msg;","outputs":1,"noerr":0,"x":870,"y":2520,"wires":[["12142ef5.0928f1"]]},{"id":"50224b5b.8a4164","type":"function","z":"8c9f8f17.13eb78","name":"","func":"if (msg.payload.input_voltage<=100)
{
    msg.payload="Stromausfall: USV-Eingangsspannung unter 100V!";
    return msg;
}","outputs":1,"noerr":0,"x":870,"y":2560,"wires":[["b4128198.758dd"]]},{"id":"b4128198.758dd","type":"pushbullet","z":"8c9f8f17.13eb78","config":"","pushtype":"note","title":"SmartHome","chan":"","name":"","x":1150,"y":2560,"wires":[]},{"id":"88e174da.1ab6d8","type":"inject","z":"8c9f8f17.13eb78","name":"Test Power failure","topic":"","payload":"60","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":490,"y":2560,"wires":[["b7ac5f17.07bbb"]]},{"id":"b7ac5f17.07bbb","type":"change","z":"8c9f8f17.13eb78","name":"","rules":[{"t":"set","p":"temp","pt":"flow","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.input_voltage","pt":"msg","to":"temp","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":2560,"wires":[["50224b5b.8a4164"]]},{"id":"3442fea.41d6702","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Battery charge","group":"c8fbbc62.c288a","order":4,"width":0,"height":0,"gtype":"gage","title":"Battery charge:","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#ca3838","#e6e600","#00b500"],"seg1":"","seg2":"","x":1160,"y":2280,"wires":[]},{"id":"5362d4fa.9026ac","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Batterie-Temperature","group":"c8fbbc62.c288a","order":5,"width":0,"height":0,"gtype":"gage","title":"Batterie-Temperature:","label":"°C","format":"{{value}}","min":"20","max":"40","colors":["#00b500","#00b500","#ca3838"],"seg1":"","seg2":"","x":1180,"y":2320,"wires":[]},{"id":"bd21c5da.510bc8","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Batterie-Voltage","group":"c8fbbc62.c288a","order":6,"width":0,"height":0,"gtype":"gage","title":"Batterie-Voltage:","label":"V","format":"{{value}}","min":"11","max":"15","colors":["#ca3838","#00b500","#ca3838"],"seg1":"","seg2":"","x":1160,"y":2360,"wires":[]},{"id":"22a47d9.d019982","type":"ui_gauge","z":"8c9f8f17.13eb78","name":"Mains voltage","group":"c8fbbc62.c288a","order":7,"width":0,"height":0,"gtype":"gage","title":"Mains voltage:","label":"V","format":"{{value}}","min":"220","max":"240","colors":["#ca3838","#00b500","#ca3838"],"seg1":"","seg2":"","x":1160,"y":2400,"wires":[]},{"id":"6a33c3ab.06088c","type":"ui_text","z":"8c9f8f17.13eb78","group":"c8fbbc62.c288a","order":1,"width":0,"height":0,"name":"Status","label":"Status:","format":"{{msg.payload}}","layout":"row-spread","x":1130,"y":2440,"wires":[]},{"id":"12142ef5.0928f1","type":"ui_text","z":"8c9f8f17.13eb78","group":"c8fbbc62.c288a","order":2,"width":0,"height":0,"name":"Last Update","label":"Last Update:","format":"{{msg.payload}}","layout":"row-spread","x":1150,"y":2520,"wires":[]},{"id":"6f8a5651.9e0318","type":"ui_group","z":"","name":"USV","tab":"fe022c7.d9788d","disp":true,"width":"6","collapse":false},{"id":"c8fbbc62.c288a","type":"ui_group","z":"","name":"USV2","tab":"4719e8d9.2a46f8","disp":true,"width":"6","collapse":false},{"id":"fe022c7.d9788d","type":"ui_tab","z":"","name":"Einstellungen","icon":"dashboard"},{"id":"4719e8d9.2a46f8","type":"ui_tab","z":"","name":"Einstellungen","icon":"dashboard"}]

Further information

https://wiki.ubuntuusers.de/USV/NUT/
https://flows.nodered.org/flow/cf9813fbca341607a73786c31df362c9
http://www.gtkdb.de/index_36_2203.html


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.