Hello people, i need some help.
When i connect to my switch device, i get message string: MAC: 5c:cf:7f:0f:6f:2d,ON . Can this be parsed in transformation rule, and how open hab treat special charachters like , : etc? Also when i want to send command ON for exp, i use different string, 1#111#222.
I write transformationrule like this:
MAC: 5c:cf:7f:0f:6f:2d,ON=ON
and vice versa, and tried
ON=1#111#222
but still getting error, could not parse.Any advice?
Thank you anyway!
Yes, shouldn’t be a problem.
Shouldn’t have a problem with them coming in to openHAB. You may need to escape them when you define your transform, depending on which transform you want to do.
Please post your Items definitions.
Thank you Rich Koshak!
Anyway item looks like:
Switch Cswitch “Switched [%s °C]” (Weather) {tcp=">[ON:192.168.1.191:25503:‘MAP(dev.map)’], >[OFF:192.168.1.191:25503:‘MAP(dev.map)’], <[192.168.1.191::'REGEX(.))’]"}
In the transfomation rule i wrote as i said above:
MAC: 5c:cf:7f:0f:6f:2d,ON=ON
(PS: icons and groups are left from demo example, dont be confused,im still in exploration process)
My first scan tells me you need to have your REGEX be REGEX((.*))
. What is above is missing a paren and without the “*” is will only match on the first character of the message.
In your dev.map you may need to escape the space:
MAC:\ 5c:cf:7f:0f:6f:2d,ON=ON
Once you make these changes, if they still don’t work, post what errors are printed in the logs.
For item:
Switch Cswitch “Switched [%s °C]” (Weather) {tcp=“>[ON:192.168.1.191:25503:‘MAP(dev.map)’], >[OFF:192.168.1.191:25503:‘MAP(dev.map)’], <[192.168.1.191:*:‘REGEX(.*))’]”}
AND RULE:
rule “TurnSwitchON”
when
System started
then
sendCommand(Cswitch,ON)
//say(“This is test”)
logInfo(“Test”, "SendingCommand " +Cswitch)
end
AND Transf.rule
MAC:\ 5c:cf:7f:0f:6f:2d,OFF=TEST
ON=1#111#222
i got this in logs. There is no probles now, but didn sent anything to switch.
Also i want you to describe you whole process. When i connect to device, i get message MAC: 5c:cf:7f:0f:6f:2d,ON (or OFF, it stands for state of device,but this is just info, dont need that), after that, im sending commands for device using 1#111#222 or 0#111#222 to switch on or off respectively. When i send command(on or off) i get info again, it looks like OFF 010110 (again just ordinery response that device has been updated). So what im doing wrong?
PS: Note in logs
The channel for /192.168.1.191:25503 is now connected
and
there is no channel that services [itemName=Cswitch, command=ON]
think imdoing 2016.pdf (132.0 KB)something wrong in basic?
Also when i send command from rules, sendCommand(Cswitch,ON), is this passed first to trasformtion rule, to match ON command with trasfromation (ON=1#111#222), and then passed to item in .items file, and then send on specified ip, or i missunderstood concept?
What i noticed now, when server loads demo items, and when i exit the console, it runs a command? Im very confused, dont bother him parse, but why runs only then command, when i exit the console?
Well there won’t be any logs until you send or receive something.
OK, first of all, if you don’t care what you are getting back get rid of the incoming part of the binding (i.e. <[192.168.1.191::'REGEX((.))']
). Second of all, the binding is going to try and set your Item to whatever is coming back and since “MAC…” doesn’t map to ON or OFF it has no idea what to do. You would need to transform that MAC string on the incoming and parse out the ON or OFF instead of REGEX((.)). But again, if you don’t care then don’t mess with it and make your switch only send commands and not read data on the socket.
Then for your map, try to escape the “#” and make sure you have mappings for ON and OFF. Get rid of “TEST” as that will just cause problems. And for good measure go ahead and map it both directions.
ON=1\#111\#222
OFF=0\#111\#222
1\#111\#222=ON
0\#111\#222=OFF
That means it doesn’t know how to translate ON to the String that needs to go out on the socket. (NOTE: In the future you should just paste your logs into your posting and put surround it with three backticks so it is nicely formatted.)
```
your logs pasted here
```
The order of what happens is sendCommand posts the command to the Item. The Item updates its state to ON. The update gets put out on the event bus and passed to the binding. The binding gets the new state and figures out what to do with it based on the binding config. In your case it sees that it needs to transform it using dev.map and then sends out the result of the transformation out to the device, in this case putting the message on the socket.
System started triggered rules will execute when OH starts or when the timestamp on the .rules file changes and it reloads the file.
Yea,it works, everything works fine, but you was right, i need to map 5c:cf:7f:0f:6f:2d,ON because of state,now again struggling
I don’t know why. I do know that happens on some types of devices. You
can write a ride to and it multiple times per press.
Its okey now, i wrote rule, and its fine, but now to find how to mapp MAC: 5c…again
thank you! i really appreciate your help!