Hi Ingo,
I use a rule to import the SMA inverter data (not by me written by the way, all credits go to the guys who wrote this):
executeCommandLine("sudo /home/pi/SBFspot/SBFspot.sh > /dev/null")
// var String PVd = String::format( “%1$tY%1$tm%1$td”, new Date() )
// var String PVt = String::format( “%1$tH:%1$tM”, new Date() )
var String smaspotlogfile = String::format( "/home/pi/smadata/%1$tY/PV_Dak-Spot-%1$tY%1$tm%1$td.csv", new Date() )
// var String smaspotlogfile = String::format( “/home/pi/smadata/2016/PV_Dak-Spot-20160203.csv”, new Date() )
val fileReader = new java.io.FileReader(smaspotlogfile)
var String line
var String nextline
try {
val values = new java.io.BufferedReader(fileReader)
nextline = values.readLine
while (nextline != null) {
line = nextline
nextline = values.readLine
}
}
finally {
try { fileReader.close() } catch (Exception e) {}
}
var String[] pvbuffer = line.replace(",",".").split(";")
postUpdate (PVPac1, Float::parseFloat(pvbuffer.get(10)))
postUpdate (PVIac1, Float::parseFloat(pvbuffer.get(13)))
postUpdate (PVUac1, Float::parseFloat(pvbuffer.get(16)))
postUpdate (PVEtoday, Float::parseFloat(pvbuffer.get(22)))
postUpdate (PVEtotal, Float::parseFloat(pvbuffer.get(23)))
postUpdate (PVFreq, Float::parseFloat(pvbuffer.get(24)))
postUpdate (PVPdc1, Float::parseFloat(pvbuffer.get(4)))
postUpdate (PVIdc1, Float::parseFloat(pvbuffer.get(6)))
postUpdate (PVUdc1, Float::parseFloat(pvbuffer.get(8)))
postUpdate (PVPdc2, Float::parseFloat(pvbuffer.get(5)))
postUpdate (PVIdc2, Float::parseFloat(pvbuffer.get(7)))
postUpdate (PVUdc2, Float::parseFloat(pvbuffer.get(9)))
postUpdate (PVConditie, pvbuffer.get(28))
postUpdate (PVTemp, Float::parseFloat(pvbuffer.get(30)))
// var String v1 = (PVEtoday.state as DecimalType * 1000).intValue().toString
// var String v2 = (PVPac1.state as DecimalType).intValue().toString
// var String v5 = String::format("%.1f", (PVTemp.state as DecimalType).floatValue())
// var String PVOutputGET = “http://pvoutput.org/service/r2/addstatus.jsp?key=xxxxx&sid=xxxxx&d=” + PVd + “&t=” + PVt + “&v1=” + v1 + “&v2=” + v2 + “&v5=” + v5
// logInfo(“PV-GET”,PVOutputGET)
logInfo(“PV-GET”,smaspotlogfile)
Most important in this is the filename is in the variable smaspotlogfile (which is being setup as the date is a variable; change it towards the filename you want it to be and that probably makes this example a lot easier.
Next: the variable ‘line’ contains the last line read. Use this to do your REGEX expressions on it and calculate your variables.
Last: the variables have to be put back into the openhab variables (beware of the local = within a rule and global = within the sitemap definitions variables difference). Use postUpdate to do this.
Hopefully you will succeed. It isn’t that hard to make your own version of this. I am not familiar with REGEX, so can’t help you any further with that part. This is the most extensive rule I use for this kind of questions. An easy one is:
logInfo("Get Itho State","Start Getting Itho State")
executeCommandLine("sudo /home/pi/GetIthoState.sh > /dev/null")
logInfo("Get Itho State","Itho State Requested")
var String IthoCurrentStateLog = String::format( "/home/pi/itho.state", new Date() )
val fileReader = new java.io.FileReader(IthoCurrentStateLog)
var String line
var String nextline
try {
val values = new java.io.BufferedReader(fileReader)
nextline = values.readLine
while (nextline != null) {
line = nextline
nextline = values.readLine
}
}
finally {
try { fileReader.close() } catch (Exception e) {}
}
logInfo("Get Itho State","Itho State read = {}", line)
postUpdate (Itho_Current_State, line)
executeCommandLine("sudo /home/pi/GetIthoState.sh > /dev/null")
logInfo("Get Itho State","End Getting Itho State")
In here I call a bash-script which does the curl command and puts the output into a file. Then I open the file itho.state which should have only 1 line, but could be empty if the command went wrong (don’t process that however). Next I doe the postupdate and… ready to be displayed in the sitemap.
Best regards,
HWL