APC SmartUPS Binding

1,129 views
Skip to first unread message

Marcolino

unread,
Feb 12, 2015, 11:39:12 AM2/12/15
to ope...@googlegroups.com
Hi all,
I have a couple of APC SmartUPS one with USB and other with serial cable. I'm able to control it from my PC with apcupsd.
I would like to know if is there a binding or a way to have data as load, battery runtime, battery voltage into openhab.

Thanks

Marco

Greg

unread,
Feb 12, 2015, 12:26:58 PM2/12/15
to ope...@googlegroups.com
Not for apcupsd, but there was a Network UPS Tools (NUT) binding added:

Tiana tianata

unread,
Feb 19, 2015, 4:24:17 PM2/19/15
to ope...@googlegroups.com
apsupsd have a web interface, maybe is possible to get ups status data using http binding

Will be good if you share some information about apcupsd web interface and http binding... possible ot not possible

Marco Pozzuolo

unread,
Feb 19, 2015, 4:27:17 PM2/19/15
to ope...@googlegroups.com
I solved in another mode.
apcupsd have a command that get a list of all parameter of UPS.
with ./apcaccess status i get all value i need.
I white a bash script called by exec binding that update an item every 60 seconds.
Then with a rule and regex i get any singre value i need.

Thanks

Marco


-----------------------------------------------------------------------------------------------------------------
Marco Pozzuolo
PS. Realizzo PCB artigianali con piste stagnate.

2015-02-19 22:24 GMT+01:00 Tiana tianata <masu...@gmail.com>:
apsupsd have a web interface, maybe is possible to get ups status data using http binding

Will be good if you share some information about apcupsd web interface and http binding... possible ot not possible

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/W4xj_JAlWtA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/438773fc-251b-4fd1-9c71-3f8d7a5c6ca8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Richard Trenchard

unread,
Feb 20, 2015, 3:25:11 AM2/20/15
to ope...@googlegroups.com
Marco can you share that script please..

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.

To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.

Marcolino

unread,
Feb 20, 2015, 5:09:05 AM2/20/15
to
Hi,
all scripts following, presume that apcupsd is working and apcaccess is able to download UPS parameters.

Bash script:
#!/bin/bash
export UPS_LOG="$(/sbin/apcaccess status localhost:$1)"
echo $UPS_LOG

this script simply take as input the port on where apcupsd is listening, and return a list of parameter with value.

Item to collect the raw ups values string:
String UPS_1_LOG "Stringa di Log Completa [%s]" { exec="<[/opt/openhab/configurations/myscript/ups_dump_log 3551:60000:REGEX((.*))]"}

this iterm execute bash script every minutes and update the raw data returned from apcaccess.

Items to store single ups values:
String UPS_1_NAME "Nome UPS [%s]" 
String UPS_1_LASTUPDATE "Ultimo Aggiornamento [%s]" <calendar>
String UPS_1_STATUS "Stato UPS [%s]" <power_light>
Number UPS_1_RUNTIME "Runtime [%.1f Minuti]" <stopwatch>
Number UPS_1_LINEVOLTAGE "Tensione di Linea [%.1f Volt]" <voltmeter>
Number UPS_1_OUTVOLTAGE "Tensione Output [%.1f Volt]" <voltmeter>
Number UPS_1_LOAD "Carico [%.1f %%]" <power_load>
Number UPS_1_BATTVOLTAGE "Tensione Batteria [%.1f Volt]" <voltmeter>
Number UPS_1_BATTCHARGE "Percentuale Carica Batteria [%.1f %%]" <battery_100>
Number UPS_1_ITEMP "Temperatura Interna [%.1f °C]" <temperature>

And at last, the rule to perfom raw data manipulation. In order to make code clean, i used function in rule as described here: https://github.com/openhab/openhab/wiki/Reusable-Rules-via-Functions.

The rules are:
val org.eclipse.xtext.xbase.lib.Functions$Function4 UPS_GetNumValue = [
    org.openhab.core.library.items.StringItem logITem,
    org.openhab.core.library.items.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 UPS_GetStrValue = [
org.openhab.core.library.items.StringItem logITem,
    org.openhab.core.library.items.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 "UPS 1500 Handling"
when
Item UPS_1_LOG received update
then
//Nome UPS
UPS_GetStrValue.apply(UPS_1_LOG,UPS_1_NAME,"(?<=UPSNAME : )(.*?)(?= )","LogLine")
logInfo("UPS.1.Handler","Log "+UPS_1_NAME.state.toString+" recuperato")
//Ultimo Aggiornamento
UPS_GetStrValue.apply(UPS_1_LOG,UPS_1_LASTUPDATE,"(?<=DATE : )(.*?)(?= HOSTNAME)","LogLine")
logInfo("UPS.1.Handler","Ultimo Aggiornamento: "+UPS_1_LASTUPDATE.state.toString+"")
//Stato UPS
UPS_GetStrValue.apply(UPS_1_LOG,UPS_1_STATUS,"(?<=STATUS : )(.*?)(?= )","LogLine")
logInfo("UPS.1.Handler","Stato UPS: "+UPS_1_STATUS.state.toString+"")
//Runtime
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_RUNTIME,"TIMELEFT \\: ([-+]?[0-9]*\\.?[0-9]) Minutes","LogLine")
logInfo("UPS.1.Handler","Runtime: "+UPS_1_RUNTIME.state.toString+" Minuti")
//Tensione Di Linea
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_LINEVOLTAGE,"LINEV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine")
logInfo("UPS.1.Handler","Tensione di Linea: "+UPS_1_LINEVOLTAGE.state.toString+" Volt")
//Tensione di Uscita
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_OUTVOLTAGE,"OUTPUTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine")
logInfo("UPS.1.Handler","Tensione d'Uscita: "+UPS_1_OUTVOLTAGE.state.toString+" Volt")
//Carico
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_LOAD,"LOADPCT \\: ([-+]?[0-9]*\\.?[0-9]) Percent Load Capacity ","LogLine")
logInfo("UPS.1.Handler","Carico: "+UPS_1_LOAD.state.toString+" %")
//Tensione di Batteria
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_BATTVOLTAGE," BATTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine")
logInfo("UPS.1.Handler","Tensione di Batteria: "+UPS_1_BATTVOLTAGE.state.toString+" Volt")
//Carica Batteria
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_BATTCHARGE,"BCHARGE \\: ([-+]?[0-9]*\\.?[0-9]) Percent","LogLine")
logInfo("UPS.1.Handler","Carica Batteria: "+UPS_1_BATTCHARGE.state.toString+" %")
//Temperatura Interna
UPS_GetNumValue.apply(UPS_1_LOG,UPS_1_ITEMP,"ITEMP \\: ([-+]?[0-9]*\\.?[0-9]) C","LogLine")
logInfo("UPS.1.Handler","Temperatura Interna: "+UPS_1_ITEMP.state.toString+" C")

end


the rule simply calls functions one time for each parameters you need, passing items and regex pattern to match value you need.

Each UPS can vary it's parameters, so this rule may need fine tuning.

MArco



Tiana tianata

unread,
Feb 27, 2015, 10:46:36 PM2/27/15
to ope...@googlegroups.com
Thank you for sharing this code.

I want to try Network UPS Tools (NUT) but cannot find addon.

Were can i find Network UPS Tools (NUT) addon????

kristoffer johansson

unread,
Jul 26, 2015, 2:27:32 PM7/26/15
to openhab, masu...@gmail.com
When i add the script to openhab 1.7.0
I get the following error
[ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'UPS 1500 Handling': The name 'compile(<XFeatureCallImplCustom>)' cannot be resolved to an item or type.


 The bash script returns the following string
APC : 001,045,1084 DATE : 2015-07-26 20:02:11 +0200 HOSTNAME : nas VERSION : 3.14.10 (13 September 2011) debian UPSNAME : MINUPS CABLE : USB Cable DRIVER : USB UPS Driver UPSMODE : Stand Alone STARTTIME: 2015-07-26 19:00:04 +0200 MODEL : Back-UPS BF350 STATUS : ONLINE LINEV : 232.0 Volts LOADPCT : 22.0 Percent Load Capacity BCHARGE : 100.0 Percent TIMELEFT : 31.5 Minutes MBATTCHG : 15 Percent MINTIMEL : 10 Minutes MAXTIME : 0 Seconds OUTPUTV : 230.0 Volts SENSE : Medium DWAKE : 000 Seconds DSHUTD : 000 Seconds LOTRANS : 180.0 Volts HITRANS : 266.0 Volts RETPCT : 000.0 Percent ITEMP : 29.2 C Internal ALARMDEL : No alarm BATTV : 13.6 Volts LINEFREQ : 50.0 Hz LASTXFER : Low line voltage NUMXFERS : 0 TONBATT : 0 seconds CUMONBATT: 0 seconds XOFFBATT : N/A SELFTEST : NO STESTI : None STATFLAG : 0x07000008 Status Flag MANDATE : 2004-05-21 SERIALNO : AB0421122454 BATTDATE : 2004-05-21 NOMOUTV : 230 Volts NOMINV : 230 Volts NOMBATTV : 12.0 Volts NOMPOWER : 225 Watts FIRMWARE : 813.s3.I USB FW:s3 END APC : 2015-07-26 20:02:13 +0200

The rule for parsing the output from the script is
Anyone have an any idea what i can do to make it work?
Reply all
Reply to author
Forward
0 new messages