Mirror Light State

I have to switches that in my kitchen area and I’m trying to have the Light over my kitchen sink mirror the on/off state of my other lights. I’m still pretty new at rules and understanding them, but just tried the below thinking it would work to no affect.

Should this work?

rule "Match Kitchen Sink light"
  when
    Item Light_Kitchen_Cooking received update
  Then
    var String state = Light_Kitchen_Cooking.state.toString()
    //sendCommand(Light_Kitchen_Sink, state.upperCase)
    sendCommand(Light_Kitchen_Sink, ON)
end

EDIT. Just saw the typo after staring at it for 30 minutes. its a lower case t in the Then statement !

Try the following:

rule "Match Kitchen Sink light"
when
    Item Light_Kitchen_Cooking received command
then
    Light_Kitchen_Sink.sendCommand(receivedCommand)
end

The above rule should makes sure that whatever command (ON or OFF) you send to you Cooking light get propagate to your Sink light. I am using this in a similar setup, and it works just fine.

Hello, sorry to Jump in on this thread, do you know how it works if I want to mirror the state each other?

I mean, if I use the same rule to mirror from Kitchen_Sink to Light_Kitchen_Cooking, doesn’t it create a loop of events? Is it possible to avoid this loop in some way?

Thanks,
Raffaele.

It certainly can. It’s up to you to take care and think about what you try to set up.

Separating commands and states is often useful.

For example, trigger rules from state changes not commands.

rule "lamp X"
when
   Item LampY changed
then
   if (LampX.state != LampY.state) {
      LampX.sendCommand(LampY.state.toString)
   }
end
// and the mirror rule for LampY

Work out what happens when you send a command to Lamp Y, it changes in the usual way due to binding, triggers that rule, which sends a command to Lamp X, which changes state, which triggers the Lamp Y version of the rule … which does nothing this time.

Thanks a lot, so managing the loops directly in the rule. Tested and working, thanks a lot.