Hi
Thanks for all the great ideas and scripts in this post.
I couldn’t get my head around how the python script worked, but I did find a solution using the Exec binding.
I created a Thing in paperUI using the Exec Binding with the simple command of
apcaccess -u
I then linked the output to a String Item - in my case I called it “APCUPSQuery_Output”
this rule then splits the string into separate variables
(testtrigger is just a virtual switch that I use to trigger rules when I’m developing)
rule "APC UPS String spliting"
when
Item APCUPSQuery_Output received update // Change this Item to your "apcaccess -u" exec query output
// or Item testtrigger changed // Only a test switch to force the rule to run for testing
then
logInfo("APC Info", "APC UPS Query update = "+APCUPSQuery_Output.state) // Change this Item to your "apcaccess -u" exec query output // Comment out this line to stop it populating your openhab.log file
var String APCQUERY = APCUPSQuery_Output.state.toString // Change this Item to your "apcaccess -u" exec query output
var APCname = (APCQUERY.split(':').get(14)).split('\n').get(0) // The (\n) split removes the line feed and wrapped text from the result.
var APCOnline = (APCQUERY.split(':').get(15)).split('\n').get(0)
var linev = (APCQUERY.split(':').get(16)).split('\n').get(0)
var LOAD = (APCQUERY.split(':').get(17)).split('\n').get(0)
var loadNo = Float::parseFloat(String::format("%s",LOAD)) // turns the string into a usable number
var batterych = (APCQUERY.split(':').get(18)).split('\n').get(0)
var batterychNo = Float::parseFloat(String::format("%s",batterych)) // turns the string into a usable number
var timeleft = (APCQUERY.split(':').get(19)).split('\n').get(0)
var timeleftNo = Float::parseFloat(String::format("%s",timeleft)) // turns the string into a usable number
var outputv = (APCQUERY.split(':').get(23)).split('\n').get(0)
var outputvNo = Float::parseFloat(String::format("%s",outputv )) // turns the string into a usable number
var itemp = (APCQUERY.split(':').get(30)).split('\n').get(0)
var itempNo = Float::parseFloat(String::format("%s",itemp )) // turns the string into a usable number
var battv = (APCQUERY.split(':').get(32)).split('\n').get(0)
var battvNo = Float::parseFloat(String::format("%s",battv )) // turns the string into a usable number
logInfo("APC Info","APC UPS Named "+APCName+" is "+APCOnline+", with an internal temperature of "+itempNo+"°C, Load = "+loadNo+" Percent, Current Line Voltage is "+linev+" Battery is at "+batterychNo+" percent, giving "+timeleftNo+" minutes at current load, at "+outputvNo+" Vac. Current battery voltage "+battvNo+" Vdc") // Comment out this line once you're happy the rule is working for you.
// You could use the values to populate Items for use elsewhere, for example
// APCname.postUpdate(APCName)
// APCOnline.postUpdate(APCOnline)
// APClinev.postUpdate(linev)
// APCLoad.postUpdate(loadNo)
// APCbatterycharge.postUpdate(batterychNo)
// APCtimeleft.postUpdate(timeleftNo)
// APCoutputv.postUpdate(outputvNo)
// APCbatteryvoltage.postUpdate(battvNo)
end
This gives me a loginfo output of :-
2019-02-21 10:53:25.870 [INFO ] [ipse.smarthome.model.script.APC Info] - APC UPS Named Smart-UPS 2200 XL is ONLINE , with an internal temperature of 11.2°C, Load = 7.1 Percent, Current Line Voltage is 239.0 Battery is at 100.0 percent, giving 1020.0 minutes at current load, at 239.0 Vac. Current battery voltage 55.4 Vdc
Thanks to @rlkoshak for his help yesterday with splitting strings, I’m still not entirely sure how to implement his parts idea, but I’m working on it