[SOLVED] Rule to command sonoff with interlock

Hi
i have a sonoff dual where i set by Tasmota an interlock.
The update of the status is not correct. Infact when i turn ON a switch the other must be at OFF. On sonoff is so but in openhab is not so.
I want to create a rule to do it.
I created this but doesn’t work:

rule "interlock1"
when
item LivingRoom_Light1 received command
then
if (receivedCommand == ON) LivingRoom_Light2.sendCommand(OFF)
    else LivingRoom_Light2.sendCommand(ON)

end
 
rule "interlock2"
when
item LivingRoom_Light2 received command
then
if (receivedCommand == ON) LivingRoom_Light1.sendCommand(OFF)
    else LivingRoom_Light1.sendCommand(ON)

end

Try it this way.:wink:

rule "interlock1"
when
Item LivingRoom_Light1 received update
then
    if ( LivingRoom_Light1.state == ON) 
        LivingRoom_Light2.sendCommand(OFF)
    else 
        LivingRoom_Light2.sendCommand(ON)

end
 
rule "interlock2"
when
Item LivingRoom_Light2 received update
then
    if (LivingRoom_Light2.state == ON) 
        LivingRoom_Light1.sendCommand(OFF)
    else 
        LivingRoom_Light1.sendCommand(ON)

end

it doesn’t work

What doesn’t work? Any errors in the logs to indicate why? Are the items used in the rule all created via PaperUI?

the sonoff has gone mad. alternately and incessantly lit the two relè
Look thay

2019-03-17 22:00:13.451 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light1' received command ON

2019-03-17 22:00:13.477 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from OFF to ON

2019-03-17 22:00:14.319 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light1' received command OFF

2019-03-17 22:00:14.336 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from ON to OFF

2019-03-17 22:00:15.356 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light2' received command ON

2019-03-17 22:00:15.366 [nt.ItemStatePredictedEvent] - LivingRoom_Light2 predicted to become ON

2019-03-17 22:00:15.376 [vent.ItemStateChangedEvent] - LivingRoom_Light2 changed from OFF to ON

2019-03-17 22:00:16.239 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light2' received command OFF

2019-03-17 22:00:16.246 [nt.ItemStatePredictedEvent] - LivingRoom_Light2 predicted to become OFF

2019-03-17 22:00:16.254 [vent.ItemStateChangedEvent] - LivingRoom_Light2 changed from ON to OFF

2019-03-17 22:00:17.120 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light2' received command ON

2019-03-17 22:00:17.132 [nt.ItemStatePredictedEvent] - LivingRoom_Light2 predicted to become ON

2019-03-17 22:00:17.143 [vent.ItemStateChangedEvent] - LivingRoom_Light2 changed from OFF to ON

2019-03-17 22:00:17.935 [ome.event.ItemCommandEvent] - Item 'LivingRoom_Light2' received command OFF

2019-03-17 22:00:17.943 [nt.ItemStatePredictedEvent] - LivingRoom_Light2 predicted to become OFF

2019-03-17 22:00:17.957 [vent.ItemStateChangedEvent] - LivingRoom_Light2 changed from ON to OFF

Not sure what you mean by setting an interlock in Tasmota but I would try to keep all the rules in either OH or tasmota, but not in both.

The problem is that if i set by Tasmota the interlock the update in openhab is not correct
So i’d like to create e rule to update the state in real time

I would try it likre:

rule "interlock1"
when
Item LivingRoom_Light1.state changed to ON
then
        LivingRoom_Light2.sendCommand(OFF)
end

You can do the second one yourself.
Reason for changes, trigger only when the state really changed to ON and do nothing when it changed to OFF. The constant switching was probably caused by reacting on EACH update.

1 Like

If you just want to check the state and update then something like this may work.

rule "interlock1"
when
Item LivingRoom_Light1 received update or
Item LivingRoom_Light received update
then
    if ( LivingRoom_Light1.state == ON) 
        LivingRoom_Light1.postUpdate(ON)
    if ( LivingRoom_Light2.state == ON)
        LivingRoom_Light2.postUpdate(ON)

You’ll need to add the OFF part but on each update the state will be checked.

Sorry for the mistyped post above. That is what happens when doing it from a mobile.

i tried but it doesn’t work

rule "interlock1"
 when
Item LivingRoom_Light1.state changed to ON
 then
        LivingRoom_Light2.sendCommand(OFF)
 end

rule "interlock2"
 when
Item LivingRoom_Light2.state changed to ON
 then
        LivingRoom_Light1.sendCommand(OFF)
 end

Try the rule without the item state in the when section.
Example:

rule "interlock1"
 when
Item LivingRoom_Light1 changed to ON
 then
        LivingRoom_Light2.sendCommand(OFF)
 end

rule "interlock2"
 when
Item LivingRoom_Light2 changed to ON
 then
        LivingRoom_Light1.sendCommand(OFF)
 end

If that doesn’t work you might want to create a proxy item, add it to your sitemap, and test with the proxy that something is working.

Example:

rule "interlock1"
 when
Item Proxy_switch changed to ON
 then
        LivingRoom_Light1.sendCommand(ON)
 end

rule "interlock2"
 when
Item Proxy_switch changed to ON
 then
        LivingRoom_Light1.sendCommand(OFF)
 end

After testing LivingRoom_Light1, try with LivingRoom_Light2, if neither work then there is something else going on with the OH setup.

1 Like

Thanks for stepping in and sorry for the faulty code.
Away from home doing babysitting for a week, bear with me!

ok now it works.
Thank’s

Good to hear.:+1:

Please click the square box on the post that provided the solution.

Thanks