Get status from my device

Hi! I need to get status from my smart switch. I have a python code for it:

pi@rpi:~ $ light -ch B1 -cmd stat
OFF
pi@rpi:~ $

It is necessary for me that the status of the switch automatic changed in openhab when I change it manually (not from openhab)…

I wait for your help.

Exec binding to periodically poll the status of the light switch for its current state.

That is the only way unless your device somehow reports its changed states itself in a way that OH can receive it.

What kind of switch?
What OH binding?

How it made?

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)

http://docs.openhab.org/addons/bindings/exec/readme.html