Hi, I have made a simple setup on raspberry with openhab. I have one Thing and one Item like this:
Thing:
Thing exec:command:temperature [command="sudo python /home/pi/share/hab_dht22.py 22 4 T", interval=2, timeout=10]
Item:
String Temp2 "[%s]" <temperature> (gDHT) {channel="exec:command:temperature:output"}
Thing and Item works like a charm, but the rule that parse the string to float no:
rule "DHT Temp"
When
Item Temp2 changed
Then
logInfo("DHT", Temp2.state)
End
When the String Temp2 changed value (I can see that in Karaf), the rule is not triggered, I have no log in Karaf console.
Can you help me?
Thanks!!
sihui
(SiHui)
February 8, 2017, 5:47pm
2
I’m pretty sure that key words are case sensitive, try lower case
when
, then
, end
Leave “Item” uppercase, though.
Thanks! Right!
But now I get a null exception: When “Temp2 changed from 20.9 to 21.0” (as in Karaf console), I get:
Rule 'DHT Temp': An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null.
It seems that Temp2 has null value…
Thanks
Roberto
rgerrans
(Rgerrans)
February 8, 2017, 7:24pm
4
Try this to see what is in your Temp2 and eliminate the error:
logInfo("DHT","Temp2: " + Temp2)
I get;
Temp2: Temp2 (Type=StringItem, State=21.7, Label=, Category=temperature, Groups=[gDHT])
So, in my code, if I put:
logInfo("DHT", "Temp2: "+Temp2.State)
I get:
Rule 'DHT Temp': An error occured during the script execution: The name '<XFeatureCallImplCustom>.State' cannot be resolved to an item or type
Ok, now I have understand: if I put:
logInfo("DHT", Temp2.state)
I get the null exception; If I concat the value with a string, I get the right value:
logInfo("DHT", "Temp2: "+Temp2.state)
Thanks a lot!
gersilex
(SiLeX)
February 8, 2017, 7:37pm
8
This works because concatenation with a string will cast the item state to a string too.
Temp2.state.toString should work, too, without concatenation.
sihui
(SiHui)
February 8, 2017, 7:49pm
9
Roberto_Santini:
Thanks! Right!
You really should use the Smarthome Designer to get rid of those typos!
http://docs.openhab.org/installation/designer.html