Was liegt da näher, als auch den openHAB-Raspi und die Fritzbox(!) an die USV anzuschließen?
So laufen im Falle eines Stromausfalls Internet, Netzwerk und OH zunächst weiter und OH kann im worst-Worstcase (wenn die USV leer genudelt ist) geordnet herunterfahren.
Damit OH auch weiß, was dann zu tun ist, habe ich mir ein Skript auf dem NAS gebastelt, das jede Minute einmal läuft.
Dies schickt die Daten der USV an einen MQTT Broker.
Dafür nutze ich https://mqttx.app/cli in einem Docker Container.
Code: Alles auswählen
#!/usr/bin/env bash
CHARGE=$(upsc ups | grep battery.charge: | awk '{print $2}')
RUNTIME=$(upsc ups | grep battery.runtime: | awk '{print $2}')
MODEL=$(upsc ups | grep device.model: | cut -c 15-)
VOLTAGE=$(upsc ups | grep output.voltage.nominal: | awk '{print $2}')
JSON='{"Charge": '$CHARGE',"Voltage": '$VOLTAGE',"Runtime": '$RUNTIME',"Model": '$MODEL'}'
docker exec mqttx-cli mqttx pub -t 'Eaton/USV' -h 192.168.178.60 -p 1883 -m "$JSON"
.things
Code: Alles auswählen
Thing mqtt:topic:mosquitto:Eaton "MQTT Eaton USV" (mqtt:broker:mosquitto) {
Channels:
Type number : charge [ stateTopic="Eaton/USV", transformationPattern="JSONPATH:$.Charge" ]
Type number : voltage [ stateTopic="Eaton/USV", transformationPattern="JSONPATH:$.Voltage" ]
Type number : runtime [ stateTopic="Eaton/USV", transformationPattern="JSONPATH:$.Runtime" ]
Type string : model [ stateTopic="Eaton/USV", transformationPattern="JSONPATH:$.Model" ]
}
Code: Alles auswählen
//USV
Number USV_charge "Ladestand [%s]" {channel="mqtt:topic:mosquitto:Eaton:charge", stateDescription=""[pattern="%.0f %%"]}
Number USV_voltage "Spannung [%s]" {channel="mqtt:topic:mosquitto:Eaton:voltage", unit="V", stateDescription=""[pattern="%.0f V"]}
Number:Time USV_runtime "Laufzeit [%s]" {channel="mqtt:topic:mosquitto:Eaton:runtime", unit="s", stateDescription=""[pattern="%.0f min"]}
String USV_model "USV [%s]" {channel="mqtt:topic:mosquitto:Eaton:model"}
Code: Alles auswählen
rule "USV: Akkustand fällt ab."
when
Item USV_charge changed
then
switch newState {
case (newState < 20) : { sendNotification("me@mail.de","⚠ Achtung: USV unter 20% ! \nSystem wird heruntergefahren.")
executeCommandLine("sudo","poweroff")
return; }
case (newState < 90) : sendNotification("me@mail.de","⚠ Achtung: USV unter 90% ! \nStromversorgung prüfen!")
}
end