'IF' with a local LED

I know this is possible but I’m missing something and can’t get it right so any help would be appreciated.

I have 4 door and window sensors set up as binary sensors on an ESP32. I want to turn a local LED, configured as a light, on when one or more of the door or windows are open - and turn it off when they are all closed.

Has anyone got a code snippet they can share please before I tear out what’s left of my hair?

Thanks, I have that.I also realise that I didn’t express myself well in my frustration!

My query was more about the approach. Is it better to use on_loop and check every cycle, or to monitor for status changes and then set the LED on or off? Is one better than the other and, if so, why?

Thanks.

This is what I’ve ended up with. It works but if there is a better way please let me know.

  on_loop:
    then:
      - if:
          condition:
            or:
              - binary_sensor.is_on: pir2
              - binary_sensor.is_on: pir3
          then:
            - light.turn_on: utility_led
          else:
            - light.turn_off: utility_led
1 Like