Hi All,
Hoping someone can help - I have a String item bound to a TCP socket that isn’t updating when a string comes in over the socket.
(I couldn’t get it to work on OH2, so now on OH1.8 and having the exact same issue)
I have in openhab.cfg:
tcp:updatewithresponse=true
My item:
String amx {tcp="<[10.0.1.63:*:default]"}
I see this in the terminal so I know the string is coming into the socket:
2018-04-07 17:36:00.019 [INFO ] [runtime.busevents ] - amx state updated to testString
But my rule is not triggering:
rule “Test”
when
Item amx received update testString
then
sendCommand(amx, “String received!”)
end
Seems like the String item is always in a state of ‘Null’.
If I change the rule to:
“when
Item amx received update”
Then it triggers on any string that comes in and I receive “String received!” on my tcp client.
rule “Test”
when
Item amx received update "testString"
then
amx.sendCommand(“String received!”)
end
Note that I have used the item method amx.sendCommand instead of the action sendCommand(String, String). It is recommended to use the method when you know what item to send a command to. Use the action only for some reserved cases like:
I had already tried this as well with no luck - see below. Sending in testString didn’t trigger the rule.
With the code block you posted, is there a difference with the double quotes? Some are angled and some are vertical. When I pasted yours straight into mine it changed the syntax highlighting based on the different double quotes.
rule "Test"
when
Item amx received update "testString"
then
amx.sendCommand("String received!")
end
I can also try this as a test to see what “String” is being held it the item “amx” after sending in a string:
rule "Test"
when
Item amx received update
then
amx.sendCommand(amx)
end
The log:
2018-04-07 19:41:51.752 [INFO ] [runtime.busevents ] - amx state updated to something
2018-04-07 19:41:51.783 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Test': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null
rule "Test"
when
Item amx received update
then
logInfo("TEST", amx.state.toString)
if (amx.state.toString == "something") {
logInfo("TEST2", amx.state.toString)
}
//amx.sendCommand(amx.state.toString)
end
rule "Test"
when
Item amx received update
then
logInfo("TEST", amx.state.toString)
if (amx.state.toString == "something") {
logInfo("TEST2", amx.state.toString)
}
//amx.sendCommand(amx.state.toString)
end
2018-04-07 21:26:26.043 [INFO ] [runtime.busevents ] - amx state updated to something
2018-04-07 21:26:26.064 [INFO ] [org.openhab.model.script.TEST ] - something
I wonder if there is a carriage return / line feed attached to it somehow?
This would also explain why I had no trouble doing almost exactly the same thing a few years ago with openHAB1.7.0 but with a serial connection instead of the tcp socket. I wonder if the socket is passing through the carriage return.
I’m using netcat on a MAC terminal to connect to the openHAB socket, and just typing “something” (without the quotes) and hitting enter.
I could try using packet sender on a windows machine with could probably send the string without a carriage return.
Is there a way in openhab to test the if statement with a carriage return as well? Like “something”\r ?