Simple rule non triggered

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!!

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

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

Lower case .state

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!

This works because concatenation with a string will cast the item state to a string too.

Temp2.state.toString should work, too, without concatenation.

You really should use the Smarthome Designer to get rid of those typos!

http://docs.openhab.org/installation/designer.html