Help with counter lights

This is what I have…very crude…
What I’m trying to do to make this a bit better and ‘smarter’ is that if a light wasn’t on then don’t turn it on…

- alias: 111a - Kitchen counter light off
  id: Counter Lights off
  trigger:
    - platform: state
      entity_id: switch.table_light
      to: "off"
  action:
    - service: switch.turn_on
      entity_id: switch.counter_lights
    

- alias: 111b - Kitchen Counter Light back on
  id: Counter lights on
  trigger:
    - platform: state
      entity_id: switch.table_light
      to: "on"
  action:
      - service: switch.turn_off
        entity_id: switch.counter_lights 

So lets say it’s night and the counter lights are on it’ll work great :slight_smile:
BUT lets say the counter lights aren’t on but I need a bit of light so I turn on the table light that’s great but when I turn it off it’s going to turn on the counter lights which if they aren’t on I don’t need to turn them on… If that makes sense…

I’m looking for suggestions to do a ‘check’ to see if they were on turn them back on … if they weren’t on do not turn them on when I turn off the table light…

Thank you!!!

Is it possible to check how it was las turned off? I know you can see it in history but not sure how to check for this.

Condition would be, If last turned off by automation, action turn on.

1 Like

You really need to be able to store the state of your counter lights when you turn on the table lights. I often use a helper entity for this. In your case, you could use a boolean helper. When you turn on the table lights, checknif the counter lights are on. If so, set the boolean helper to on and counter lights to off.

Then when you turn off the table light, if your boolean helper is on, turn it off and turn on the counter lights. If it is off, do nothing.

EDIT: by boolean helper i mean toggle helper. This will also survive a HA restart unlike using a wait routine in an automation.

1 Like