Martin Sebald
7 years ago
6 changed files with 126 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||
# APC UPS devices |
|||
Receiving and using information like online status (on AC power or running on battery), battery charging level, autonomy time and more from APC UPS devices. |
|||
|
|||
All you need is a APC UPS device which is connected to a [apcupsd](http://www.apcupsd.org) daemon. The daemon can run locally on the openHAB machine and or somewhere else. If it runs remote you need to install apcupsd as we access the remote apcupsd installation using the apcaccess command. |
|||
|
|||
First you need to put the USV_dump_log bash script somewhere where you can access it. I created a directory */home/openhabian/scripts* for scripts like this one. |
|||
|
|||
Then create a thing in Paper UI. Use the Exec binding and enter the following parameters: |
|||
|
|||
* **Name:** USV_dump_log |
|||
* **Command:** /home/openhabian/scripts/USV_dump_log 3551 |
|||
* **Transform:** REGEX((.*)) |
|||
* **Interval:** 60 |
|||
|
|||
The port for accessing the UPS device through apcupsd is a parameter as I check three UPS devices and only want to use one script. This is also the reason why I configured the remote UPS devices (all my UPS devices just have a USB cable, no network interfaces) in the local apcupsd. The data is received from the remote apcupsd installations. |
|||
|
|||
The new thing *USV_dump_log* gets an id like *exec:command:**a1b2c3d4*** which you then need to enter in the item created through the *ups.items* file. |
|||
|
|||
* **ups.items**: Put this file into your */etc/openhab2/items* directory and modify it for your specific setup. Maybe everything suits your needs, but you need to modify the string item *USV_Log* and match the command id in the channel command to the thing you created earlier in Paper UI. |
|||
* **ups.map**: Put this file into your */etc/openhab2/transform* directory. |
|||
* **ups.rules**: Put this file into your */etc/openhab2/rules* directory. You may want to modify it for your specific setup. |
|||
* **ups.map**: Put the bash script into */home/openhabian/scripts* (or somewhere else you like) and *chmod 755* it to make it executable. |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
export UPS_LOG="$(/sbin/apcaccess status 172.27.0.31:$1)" |
|||
echo $UPS_LOG |
@ -0,0 +1,10 @@ |
|||
String USV_Log "kompletter Inhalt des Logs [%s]" { channel="exec:command:a1b2c3d4:output" } |
|||
String USV_Status "USV Status [MAP(ups.map):%s]" |
|||
Number USV_Load "USV Load [%.1f %%]" |
|||
Number USV_BattCharge "USV Battery Charge [%.1f %%]" |
|||
Number USV_TimeLeft "USV Time Left [%.1f Minuten]" |
|||
Number USV_BattVoltage "USV Battery Volts [%.1f V]" |
|||
Number USV_LineV "USV Input Volts [%.1f V]" |
|||
Number USV_OutputV "USV Output Volts [%.1f V]" |
|||
Number USV_ITemp "USV Temperatur [%.1f °C]" |
|||
String USV_BattDate "USV Battery Date [%s]" |
@ -0,0 +1,7 @@ |
|||
ONLINE=Online |
|||
OL=Online |
|||
OL\ CHRG=Online |
|||
ONBATT=Offline |
|||
OB\ DISCHRG=Offline |
|||
NULL=unbekannt |
|||
-=unbekannt |
@ -0,0 +1,81 @@ |
|||
import java.util.regex.Pattern |
|||
import java.util.regex.Matcher |
|||
|
|||
val org.eclipse.xtext.xbase.lib.Functions$Function4<StringItem, GroupItem, String, String, Void> UPS_GetNumValue = [ |
|||
StringItem logITem, |
|||
NumberItem upsITem, |
|||
String sExpr, |
|||
String logline | |
|||
var String ups_log |
|||
ups_log = logITem.state.toString |
|||
var Pattern ups_pattern |
|||
ups_pattern = Pattern::compile(sExpr) |
|||
var Matcher ups_matcher |
|||
ups_matcher = ups_pattern.matcher(ups_log) |
|||
ups_matcher.find() |
|||
var String ups_result |
|||
ups_result = ups_matcher.group(1) |
|||
upsITem.postUpdate(ups_result) |
|||
] |
|||
|
|||
val org.eclipse.xtext.xbase.lib.Functions$Function4<StringItem, StringItem, String, String, Void> UPS_GetStrValue = [ |
|||
StringItem logITem, |
|||
StringItem upsITem, |
|||
String sExpr, |
|||
String logline | |
|||
var String ups_log |
|||
ups_log = logITem.state.toString |
|||
var Pattern ups_pattern |
|||
ups_pattern = Pattern::compile(sExpr) |
|||
var Matcher ups_matcher |
|||
ups_matcher = ups_pattern.matcher(ups_log) |
|||
ups_matcher.find() |
|||
var String ups_result |
|||
ups_result = ups_matcher.group(1) |
|||
upsITem.postUpdate(ups_result) |
|||
] |
|||
|
|||
rule "USV Handling" |
|||
when |
|||
Item USV_Log received update |
|||
then |
|||
UPS_GetStrValue.apply(USV_Log,USV_Status,"(?<=STATUS : )(.*?)(?= )","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_LineV,"LINEV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_OutputV,"OUTPUTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_Load,"LOADPCT \\: ([-+]?[0-9]*\\.?[0-9]) Percent","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_BattCharge,"BCHARGE \\: ([-+]?[0-9]*\\.?[0-9]) Percent","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_TimeLeft,"TIMELEFT \\: ([-+]?[0-9]*\\.?[0-9]) Minutes","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_ITemp,"ITEMP \\: ([-+]?[0-9]*\\.?[0-9]) C","LogLine") |
|||
UPS_GetNumValue.apply(USV_Log,USV_BattVoltage," BATTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") |
|||
UPS_GetStrValue.apply(USV_Log,USV_BattDate,"(?<=BATTDATE : )(.*?)(?= )","LogLine") |
|||
end |
|||
|
|||
rule "USV off battery" |
|||
when |
|||
Item USV_Status changed to "ONLINE" |
|||
then |
|||
if(SystemStarting.state == OFF) { |
|||
sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Stromversorgung wiederhergestellt") |
|||
sendTelegram("telegrambot", new DateTimeType() + ": USV: Stromversorgung wiederhergestellt") |
|||
} |
|||
end |
|||
|
|||
rule "USV on battery" |
|||
when |
|||
Item USV_Status changed to ONBATT |
|||
then |
|||
if(SystemStarting.state == OFF) { |
|||
sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Stromausfall!!!") |
|||
sendTelegram("telegrambot", new DateTimeType() + ": USV: Stromausfall!!!") |
|||
} |
|||
end |
|||
|
|||
rule "USV Comm lost" |
|||
when |
|||
Item USV_Status changed to COMMLOST |
|||
then |
|||
if(SystemStarting.state == OFF) { |
|||
sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Kommunikationsverbindung verloren") |
|||
sendTelegram("telegrambot", new DateTimeType() + ": USV: Kommunikationsverbindung verloren") |
|||
} |
|||
end |
Loading…
Reference in new issue