RGB indicator for Climate status

I’m going to try to use an IR remote with an ESP32 and get my AC unit into home assistant. As there will be an ESP board connected to the IR led’s, I figured I could add a single WS2812 led too, and have it shine in red if heating mode is selected, in blue if cooling… etc.

However, I cant work out how to do it!
I’ve got the climate integration working (software only, the IR LED’s have not arrived yet) and I have the WS2812 working as a ‘light’ too.
So I can ‘control’ the AC from home assistant, and I can control the color of the LED, but I’m not sure how to best get them to link together.

I want to have code in the .yaml file, that detects when the mode is changed, and changes the color of the LED depending on the selected mode.

Here’s what I have so far, just the basics:

substitutions:
  devicename: ir1
  upper_devicename: IR 1
  platform: ESP32
  board: wemos_d1_mini32
  ip: 192.168.3.219

packages:
  standard: !include includes/standardConf.yaml

esphome:
  platformio_options:
    lib_deps: [email protected]

status_led:
  pin: 
    number: GPIO02
    inverted: False

sensor:
  - platform: homeassistant
    id: sensor_br
    internal: true
    entity_id: sensor.temperature_br

remote_transmitter:
  pin: GPIO32
  carrier_duty_percent: 50%

climate:
  - platform: daikin
    name: "Bedroom AC"
    receiver_id: reciever
    sensor: sensor_br
    supports_cool: true
    supports_heat: true
    visual:
      min_temperature: 16 °C
      max_temperature: 24 °C
      temperature_step: 1.0 °C
    
remote_receiver:
  id: reciever
  dump: all
  pin:
    number: GPIO33
    inverted: True
    mode: INPUT_PULLUP
  tolerance: 55%

light:
  - platform: neopixelbus
    type: GRB
    pin: GPIO16
    method: ESP32_I2S_1
    num_leds: 1
    id: ${devicename}_mode_led
    name: ${upper_devicename} mode light

The climate component page lists methods to get the mode https://next.esphome.io/components/climate/index.html#lambda-calls

Ah, I overlooked that, thanks.

I’ve put together some (not good) code that does achieve what I was looking for, but there’s an issue. Because I’m running the code in the lambda for the effect for the light, when the AC is set to off, the LED is set to off, which turns off the effect mode, and stops the code. So turning the AC back on, does not turn the LED back on, because the effect of the light is set to ‘none’ when it turns off.

This is clearly the wrong way to do it, and I should be changing the color of the lamp rather than using an effect, but I dont know how to do that and would appreciate some help?

Here’s the full yaml file (with horrible if blocks instead of nice code)

substitutions:
  devicename: ir1
  upper_devicename: IR 1
  platform: ESP32
  board: wemos_d1_mini32
  ip: 192.168.3.219

packages:
  standard: !include includes/standardConf.yaml

esphome:
  on_boot:
    priority: -10
    then:
      - light.turn_on:
          id: ${devicename}_mode_led
          effect: "AC Mode"
  platformio_options:
    lib_deps: [email protected]

status_led:
  pin: 
    number: GPIO02
    inverted: False

sensor:
  - platform: homeassistant
    id: sensor_br
    internal: true
    entity_id: sensor.temperature_br

remote_transmitter:
  pin: GPIO32
  carrier_duty_percent: 50%

climate:
  - platform: daikin
    name: "Bedroom AC"
    id: ${devicename}
    receiver_id: reciever
    sensor: sensor_br
    supports_cool: true
    supports_heat: true
    visual:
      min_temperature: 16 °C
      max_temperature: 24 °C
      temperature_step: 1.0 °C
    
remote_receiver:
  id: reciever
  dump: all
  pin:
    number: GPIO33
    inverted: True
    mode: INPUT_PULLUP
  tolerance: 55%

light:
  - platform: neopixelbus
    internal: true
    type: GRB
    pin: GPIO16
    method: ESP32_I2S_1
    num_leds: 1
    id: ${devicename}_mode_led
    name: ${upper_devicename} mode light
    on_turn_on:
      - light.turn_on:
          id: ${devicename}_mode_led
          effect: "AC Mode"

    effects:
      - lambda:
          name: AC Mode
          update_interval: 1s
          lambda: |-
            static int previousMode;
            int mode = id($devicename).mode;

            if (previousMode == mode) {return;}
            previousMode = mode;
            
            if (mode == 0) {
              auto call = id(${devicename}_mode_led).turn_off();
              call.perform();
            }

            if (mode == 1) { // heat/cool
              auto call = id(${devicename}_mode_led).turn_on();
              call.set_brightness(0.8);
              call.set_rgb(0.0, 1.0, 0.0);
              call.perform();
            }

            if (mode == 2) { // cool
              auto call = id(${devicename}_mode_led).turn_on();
              call.set_brightness(0.8);
              call.set_rgb(0.0, 0.0, 1.0);
              call.perform();
            }

            if (mode == 3) { // heat
              auto call = id(${devicename}_mode_led).turn_on();
              call.set_brightness(0.8);
              call.set_rgb(1.0, 0.0, 0.0);
              call.perform();
            }

            if (mode == 4) { // fan only
              auto call = id(${devicename}_mode_led).turn_on();
              call.set_brightness(0.5);
              call.set_rgb(1.0, 1.0, 1.0);
              call.perform();
            }

            if (mode == 5) { // dry
              auto call = id(${devicename}_mode_led).turn_on();
              call.set_brightness(0.7);
              call.set_rgb(1.0, 1.0, 0.0);
              call.perform();
            }
             
            ESP_LOGI("main", "mode set to: %d", id($devicename).mode);