You will want to use Rules and Design Pattern: Proxy Item.
-
Create a proxy Item that represents your Light switch’s state to OH
-
Continue to use the Exec binding or use executeCommandLine in a rule to call your script, I’ll assume you continue to use the Exec binding
-
Rules that get triggered when the Proxy Item receives a command and when the Item linked to the output channel receives an update
rule "Proxy Item received command"
when
Item MySwitchProxy received command
then
MySwitchInput.sendCommand(receivedCommand) // set the argument to the script, I think this kicks off the script if not
MySwitch.sendCommand(ON) // trigger the script to run
end
rule "Process result from script"
when
Item MySwitchOutput received update
then
if(MySwitchOutput.state != MySwitchProxy.state) MySwitchProxy.postUpdate(MySwitchOutput.state)
end
If you use executeCommandLine you can do it all in one Rule
rule "Proxy Item received command"
when
Item MySwitchProxy received command
then
val result = executeCommandLine("/path/to/script " + receivedCommand, 1000)
if(result != MySwitchProxy.state.toString) MySwitchProxy.postUpdate(result)
end