It’s DIY smart switch on ESP-12E. ESP send http request to my home server and set relay status. ESP can also send get request to change status, if i push hardware button.
I’m connect OH2 with my switch via python. OH2 execute python code by rules.
Here is rules code:
rule "Light Control"
when
Item Light1 received command OFF
then
var String cmd = "python3 /home/pi/light.py -ch B1 -cmd OFF"
executeCommandLine(cmd)
end
rule "Light Control"
when
Item Light1 received command ON
then
var String cmd = "python3 /home/pi/light.py -ch B1 -cmd ON"
executeCommandLine(cmd)
end
I’m try this code, but it don’t work…
rule "Light Control"
when
Item Light1 received update
then
var String cmd = "python3 /home/pi/light.py -ch B1 -cmd stat"
executeCommandLine(cmd)
end
Your last rule is basically doing the opposite of what you want, since it reacts to an update of an item in OpenHAB and executes a command (your script) when this happens.
I guess what you want is for your script to be called, and the output to update an item in OpenHAB.
I suggest you take a look at the Exec binding (as propsoed by @rlkoshak 4 months ago)