(SOLVED) Rule for status return

Hello guys,

I have an ESP that receives a TCP command string to trigger a relay (string = {“ObjType”: 0, “Id”: 1, “OnState”: 1, “InvertedState”: 0, “ToggleState”: 0, "Send2 ": 0}).

When it receives this string, it triggers the relay and sends back to the other string (string = {“ObjType”: 0, “Send2”: 2}), confirming that it received the command. The value 2 within Send2 is the confirmation. All this works perfectly.

But I would like to create a rule to capture this return and show the “OK” result. But I have no idea how to do it, and I did not find anything in the tutorials I could help.

Currently, when I send the command, the result of the log is:
2017-08-26 17: 59: 20.514 [WARN] [rm.AbstractFileTransformationService] - Could not transform ‘{“ObjType”: 0, “Send2”: 2}’ with the file ‘test.map’: Target value not found In map for '{“ObjType”: 0, “Send2”: 2}'
2017-08-26 17: 59: 20.514 [WARN] [ing.tcp.protocol.internal.TCPBinding] - Can not parse input {“ObjType”: 0, “Send2”: 2} to match command ON on item Swicth01

Could you help, please?

I don’t think you can do a MAP transform on a JSON object.

Your rule will need to process the JSON to do something useful with it.

Hello,

In fact, I was not thinking about doing this with MAP. My idea is to capture this return with a rule that will parse with JSONPATH. The problem is that I can not get the rule to capture this retarget message. Is this possible?

Show your item bindings.

Hello,

This is my item:

Switch Test01 “Test01 - Last command send = [%s]” (Living) {tcp="<[192.168.100.159:*:MAP(test.map)]"}

This is my map:

ON={“ObjType”: 0, “Id”: 1, “OnState”: 1, “InvertedState”: 0, “ToggleState”: 0, "Send2 ": 0}
OFF={“ObjType”: 0, “Id”: 1, “OnState”: 0, “InvertedState”: 0, “ToggleState”: 0, "Send2 ": 0}

Thanks for the help

If it’s your goal to not use a MAP transform, you need to remove the MAP transform.

Then you can have your rule operate on the value.

Could you give me an example of how to put MAP into a rule? And how would the item look? I have tried many ways, but without success.

You may not need to use a map transform in your rule.

You could use a JSONPATH transform like is described in the wiki.

Hello,

As I said, the documentation is not helping me much. I tried several configurations, but nothing works. For example:

Item:

Item:
Switch TestRelay01 “Test Relay01” (FF_Bed, Lights)
String Test “Test” (Config) {tcp="<[192.168.100.159:*:JSONPATH($.devstatus)]"}

Rule:
rule “TestRelay01"
when
Item TestRelay01 changed
then
if(TestRelay01.state==ON)
{
sendCommand(Test,”{“devstatus”: {“ObjType”:0,“Id”:1,“OnState”:1}}")
}
else if (TestRelay01.state==OFF)
{
sendCommand(Test,"{“devstatus”: {“ObjType”:0,“Id”:1,“OnState”:0}}")
}
end

Log:
2017-08-27 23:37:40.957 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘demo.rules’ has errors, therefore ignoring it: [16,29]: missing ‘)’ at ‘devstatus’
[16,75]: extraneous input ‘)’ expecting ‘}’
[20,29]: missing ‘)’ at ‘devstatus’
[20,75]: extraneous input ‘)’ expecting ‘}’

2017-08-27 23:37:41.009 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘demo.rules’ has errors, therefore ignoring it: [16,29]: missing ‘)’ at ‘devstatus’
[16,75]: extraneous input ‘)’ expecting ‘}’
[20,29]: missing ‘)’ at ‘devstatus’
[20,75]: extraneous input ‘)’ expecting ‘}’

Any idea?

Hello,

Good news !!

I managed to delete the map and send the ccomando through the rules. It looks like this:

Item:
Switch TestRelay01 “Test Relay01” (FF_Bed, Lights)
String Test “Test” (LIving) {tcp="<[192.168.100.159:*:default]" }

Rule:
rule "TestRelay01"
when
Item TestRelay01 changed
then
if(TestRelay01.state==ON)
{
var String json = '{“ObjType”:0,“Id”:1,“OnState”:1}'
logInfo(“jsonON”, json)
sendCommand(Test, json)
}
else if (TestRelay011.state==OFF)
{
var String json = '{“ObjType”:0,“Id”:1,“OnState”:0}'
logInfo(“jsonOFF”, json)
sendCommand(Test, json)
}
end

However, the ESP returns a confirmation string. And this string still can not capture.

Would you have any tips on how to do this?

Finally, after many tests, the rule is working correctly. I’ll leave the solution here so that you have the same problem:

Rule "SensorTemperatureStatus"
When
Item Sensor changed
Then
Var String json = Sensor.state.toString
LogInfo (“jsonState”, json)
End

Congratulations to all!