Turn on LED on GPIO, based on HA Sensor State (initially after reboot ESP)

Hi,
I want to read sensor states from home assistant (binary sensors or switches) and show their status (on/off) via LEDs connected to a ESP8266 Board.
Basically it is working except that initially after booting the ESP, the current state of the sensors are not published to the LEDs because of the “on_state”-Trigger which only triggers on a new state.
Here is my config:

output:
  # LED at GPIO15
  - platform: gpio
    pin: GPIO15
    id: brennerled

binary_sensor:
  - platform: homeassistant
    id: brennerstatus
    entity_id: binary_sensor.brennerstatus
    internal: true
    on_state:
      then:
        - if:
            condition:
              binary_sensor.is_on: brennerstatus
            then:
              - logger.log: "ON"
              - output.turn_on: brennerled
              #- delay: 1s
            else:
              - logger.log: "OFF"
              - output.turn_off: brennerled      

So when the state is changing the LEDs turn on or off. But when the initial state is on and the ESP boots, the LED stays off until the next “off” and “on” state. Is there a possibility that the automation is always checked, and not only on some trigger events? Or are there alternative ways to implement this feature?

Regards
Michael

You’ll probably need to use the on_boot to trigger an automation.

DeadEnd

1 Like

did you figure out how to do it? i did on_boot… it doesn’t work… tried on_loop and it work…but it execute every 16 ms…which is annoying

1 Like