Hi everyone,
I use OH3.2 on Raspberry Pi which is connected to my PLC by modbus binding and everything works well, but… Recently I wanted to get rid of one problems I’ve had from the begining with Google Home.
The way that PLC works is that it changes state on rasing or falling a signal (when 0 is becoming 1, and 1 is becoming 0). To marriage my OH installation I used a very simple transformation file one.js
(function(inputData) {
return "1" ;
})(input)
So when I send a command ON, transformation makes the job and sends 1 to PLC over modbus binding, a similary when commands is OFF it send also 1 to PLC.
All works but when I started playing with Google Home I noticed that when I ask Google Assistant to switch ON light which was previously turned on my transformation sends “1” to plc, reversing it states. Aparently Google always sends commands without checking for current state of the device.
So when I have light turned on and ask to turn it on, it will switch off. It’s not a huge problem until we have a few lights in one room, and they have different states. Asking Google to switch all lights will switch off turned on lights, but turned on the one that were off before.
I need to check state before sending command to PLC so when the item is on and gets ON command it should do nothing, and when is off and gets command OFF also do nothing. I thought I would do it via transformation, but it looks like it is not possible on that “level”. Can any one help me to figure out how to make this check with simple rule for all lights item in my system?