Esphome set led according to sensor state

Hi,
I’m struggling with something and I’m hopping someone here came across similar problem.
I have a M4Atom Lite box and I want to use the built-in led to reflect the status of an automation.

here is the relevant bit of my esphome config:

binary_sensor:
  - platform: homeassistant
    id: workshop_alarm
    entity_id: automation.workshop_alarm
    internal: true
    on_state:
      then:
        - if:
            condition:
              binary_sensor.is_on: workshop_alarm
            then:
              - light.turn_on:
                  id: led
                  red: 100%
                  green: 0%
                  blue: 0%
            else:
              - light.turn_on:
                  id: led
                  red: 0%
                  green: 100%
                  blue: 0%

light:
  - platform: fastled_clockless
    name: ${friendly_name}
    pin: GPIO27
    chipset: SK6812
    num_leds: 1
    rgb_order: grb
    restore_mode: ALWAYS_ON
    on_turn_on:
      then:
        - light.turn_on:
            id: led
            red: 100%
            green: 0%
            blue: 0%

Right now when I switch on the device the LED will turn red, then I have to manually toggle the automation and after that everything works as I want it to.

what I want to achieve is that when the device is switched on the light should turn either red or green depending if one of my automatons is on or off.
Is that possible?

found the answer to my own question - I’m posting it here as there are quite a few similar unanswered posts on this forum - hopefully this will help someone:

binary_sensor:
  - platform: homeassistant
    id: workshop_alarm
    entity_id: automation.workshop_alarm
    internal: true
light:
  - platform: fastled_clockless
    id: led
    name: ${friendly_name}
    pin: GPIO27
    chipset: SK6812
    num_leds: 1
    rgb_order: grb
    restore_mode: ALWAYS_ON
    on_turn_on:
      then:
        - if:
            condition:
              binary_sensor.is_on: workshop_alarm
            then:
              - light.turn_on:
                  id: led
                  red: 100%
                  green: 0%
                  blue: 0%
            else:
              - light.turn_on:
                  id: led
                  red: 0%
                  green: 100%
                  blue: 0%
1 Like