Light on WHILE open.. not just when state changes to 'open'

I have a notification light which turns on and off as expected when door changes it’s state.
However, I’m trying to use the light to notify on other actions.

for example.
My light currently turns on Green when the garage door is Open and turns off when it’s Closed (since it changes the state)

I’d like to have it change another color (Blue) when a different door opens.
I can make that happen since the other door it changing it’s state.

What I’d like to do is when the other door closes and the Blue light turn off, the other light sees the garage is Open and turns Green.

Is there a do this While option instead of a do this when state changes?

thanks

The approach I would take here is to have an automation that triggers on any state change of your two doors.
Then I would create scripts - one for each target state, i.e. light_off, light_green and light_blue.
The action of your automation can then use a template to determine what to do based on the states of the doors.

automation:
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.door1
        - binary_sensor.door2
  action:
    - service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.door1', 'on') %}
            script.light_green
          {% elif is_state('binary_sensor.door1', 'off') and is_state('binary_sensor.door2', 'on') %}
            script.light_blue
          {% else %}
            script.light_off
          {% endif %}

(I haven’t actually tested this code, so there may be typos in the code.)

I don’t think that’s what the OP is asking to do.

They want to turn on a green light if the garage is open. then turn the light blue when a different door opens. then when the different door closes then turn the light back to green.

no nothing like that.

you could capture the scene that the light was in prior to the other door being opened and then restore that scene when that door closes.

But you likely will have to make a condition that checks if the garage door is still open before you switch back to that scene or just turn the light off if not.

as you can see this is going to get complex the more doors you want to trigger different colors then reverting back to a previous scene.

Ah, OK. Well, my proposed approach would still work, just need to modify the template a bit:

...
  action:
    - service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.door1', 'on') and is_state('binary_sensor.door2', 'off') %}
            script.light_green
          {% elif is_state('binary_sensor.door1', 'on') and is_state('binary_sensor.door2', 'on') %}
            script.light_blue
          {% else %}
            script.light_off
          {% endif %}

I had already started going the path you mention. However, as you mentioned if I wanted more conditions it would add to the complexity which is why I was hoping for a do WHILE something is true.

thanks

1 Like