Change LED color on state change of another entity

Hi community, as I’m new to all of this, I ask if someone can point me to a solution.

I have a entity (it’s a mover) with different states. Here is what I coded so far:

- platform: template
    sensors:
      lieschen_status_friendly:
        friendly_name: "Lieschen Status"
        value_template: >-
          {% if is_state("sensor.lieschen_status_raw", "0") -%}
            kein Strom
          {% elif is_state("sensor.lieschen_status_raw", "1") -%}
            geparkt
          {% elif is_state("sensor.lieschen_status_raw", "2") -%}
            mäht
          {% elif is_state("sensor.lieschen_status_raw", "4") -%}
            laden
          {% elif is_state("sensor.lieschen_status_raw", "5") -%}
            sucht
          {% elif is_state("sensor.lieschen_status_raw", "17") -%}
            schläft
          {% elif is_state("sensor.lieschen_status_raw", "3") -%}
            Heimweg
          {% elif is_state("sensor.lieschen_status_raw", "7") -%}
            Kollision
          {% elif is_state("sensor.lieschen_status_raw", "16") -%}
            Hauptschalter AUS
          {% else -%}
            Figure out what state {{ states("sensor.lieschen_status_raw") }} means
          {%- endif %}

Now I want to change the color of an LED stripe (Arilux-LC06) depending on the state. I.e. if status_raw = 2 then light.statuslight.color = green.

What’s best to do this?

Do it with an autoamtion.

trigger:
  platform: state
  entity_id: sensor.lieschen_status_friendly
  to: "mäht"
action:
  service: light_trun_on
  target:
    entity_id: light.your_light_strip_here
  data:
    color_name: green
1 Like

Or you could use the raw value diectly.

Either way you will need to come up with a “look up table” for the different raw values that cooresponds to the desired color.

trigger:
  platform: state
  entity_id: sensor.lieschen_status_raw
action:
  service: light.turn_on
  target:
    entity_id: light.your_light_strip_here
  data:
    color_name: >
      {% set color_map = {"0":"your_color_0", 
                          "1":"your_color_1", 
                          "2":"green", 
                          "4":"your_color_4", 
                          "5":"your_color_5", 
                          etc} %}
      {{color_map[states("sensor.lieschen_status_raw")] }}
2 Likes

Many thanks, works like a charme…

1 Like

Did something changed with the last update?
I did a cleanup with all my devices and had some issues with autodiscover. Also updated HA core and the OS. But works now.
Now the automation sends RGB 255,255,255 all the time independant from the given color_name. RGB picker directly works fine.

Found the issue. Just an error in the syntax…