Hi,
first I want to say: thanks for that great system!
I am coming from Pilight and controlling my 433MhZ transmitter and receiver mostly with bash scripts and Pilight.
I switched two places to openhab and its incredible how much and complex you can control stuff!
I will dive into Z-Wave or other solutions later, but for now I try to use my current setup as good as possible. Most of the stuff is working so far (controlling my switchable power outlets), but I have some sensor data (for example I use an old android phone to get the light data). This data is written into a log file on the raspi.
As far as I red, bash script results from reading files always come in a string-format. This I can see in the rest-api:
link "http://192.168.0.150:8080/rest/items/licht_homer"
state "1254"
stateDescription
pattern "%s"
readOnly true
options []
editable false
type "String"
But I cannot figure out, why it is not possible to convert that string-state into a number…
Here is my items config:
String licht_homer “Licht [%s]” { channel=“exec:command:licht_homer:output” }
Number licht_homer_number “Licht [%.1f]”
My things:
Thing exec:command:licht_homer [command="/etc/openhab2/scripts/licht_homer.sh", interval=60, timeout=5]
And my rule:
import org.openhab.core.library.types.DecimalType
import java.lang.Double.parseDouble
var boolean Abend = false
var String licht_homer
var Number licht_homer_number
rule “Abenddaemmerung”
when
Channel ‘astro:sun:Abenddaemmerung:set#event’ triggered START
//or Time cron “/10 * * * * ?” //for testing
then
//var licht_homer_number = (Float::parseFloat(String::format("%s",licht_homer.state).replace(’ ‘,’’)))
//var licht_homer_number = licht_homer.state.toString.replace(" “,”")
//var Integer licht_homer_number = Integer::parseInt(licht_homer.state)
//var Number licht_homer_number = (licht_homer.state as DecimalType).intValue()
//licht_homer_number.postUpdate(Float::parseFloat(String::format("%s",licht_homer.state).replace(’ ‘,’’)))
//var licht_homer_number = (Double::parseDouble(licht_homer.state) as Number)
var licht_homer_number = (licht_homer.state as Number)
logInfo(“light”, (licht_homer_number))
if (licht_homer_number < 300) {
logInfo(“light”, “night”)
}
else {
logInfo(“light”, “day”)
}
end
gives me this log-entry:
2019-02-18 15:06:50.052 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Abenddaemmerung’: ‘state’ is not a member of ‘java.lang.String’; line 176, column 27, length 17
to be shure that the state is there, changed it:
var licht_homer_number = (licht_homer as Number)
gives me:
2019-02-18 15:11:50.025 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Abenddaemmerung’: Could not cast licht_homer (Type=StringItem, State=958, Label=Licht, Category=null) to java.lang.Number; line 176, column 27, length 21
all right, but the “state” is there…
I tried “postUpdate” (gives me: ‘postUpdate’ is not a member of java.lang.String…), “item.state.toString” (again: ‘state’ is not a member of java.lang.String…), all the different Integer::parse; Float::parseFloat and so on…
I am using a raspi 2B, Openhab 2.4 and Java 1.8.0_201.
Does anyone have an idea, why this ‘state’ error shows up?
I think it is a dumb error on my side, but I can’t see it…
Any help is very appreciated.
Thanks a lot!