Esphome set led according to sensor state

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