Send Color Parameter to Device

Hi,
I have a couple of devices that share identical codes.
They control LED strips and I want them to have their indivudal color.

I need some kind of parameter that I can set in home assistant to set them to their individual color for the single color effects.

The Problem ist that a dissconnect overwrites the color that I picked for the light platform with red and stays red,

so I thought of a colorpicker in HA that writes into a template on the ESP32, but how can I achieve that?

All start with this code

esphome:
  name: strippy-nr1
  friendly_name: Strippy Nr 1
  compile_process_limit: 2
  platformio_options:
    board_build.flash_mode: dio
  on_boot:
    - light.turn_on:
        id: led_strip
        red: 100%
        green: 0%
        blue: 0%
        brightness: 60%
        effect: "Scan Effect"

  on_client_disconnected:
    - light.turn_on:
        id: led_strip
        effect: "Slow Pulse"
        red: 80%
        green: 0%
        blue: 0%
        brightness: 50%  

  on_client_connected:
    - delay: 50ms
    - light.turn_off: led_strip

and later they have a couple of effects like this:

light:
  - platform: esp32_rmt_led_strip
    id: led_strip
    rgb_order: GRB
    pin: GPIO09
    num_leds: 4
    chipset: ws2812
    name: "Led Strip"
    effects:
      - pulse:
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%
      - pulse:
          name: "Slow Pulse"
          transition_length: 1s
          update_interval: 1s
          min_brightness: 0%
          max_brightness: 100%
      - pulse:
          name: "Listening"
          transition_length: 1s
          update_interval: 1s
          min_brightness: 30%
          max_brightness: 60%
      - addressable_scan:
          name: "Scan Effect With Custom Values"
          move_interval: 200ms
          scan_width: 1      
      - addressable_scan:
          name: "Scan Effect With Custom Values_slow"
          move_interval: 600ms
          scan_width: 1   
      - random:
          name: "Random Effect With Custom Values"
          transition_length: 5s
          update_interval: 2s
      - flicker:
          name: "Flicker Effect With Custom Values"
          alpha: 95%
          intensity: 40%
      - addressable_random_twinkle:
          name: "Random Twinkle Effect With Custom Values"
          twinkle_probability: 5%
          progress_interval: 32ms
      - addressable_fireworks:
          name: "Fireworks Effect With Custom Values"
          update_interval: 32ms
          spark_probability: 50%
          use_random_color: true
          fade_out_rate: 120

Because that’s what you coded on esphome.

correct.
Ho would a template look like that I can manipulate in home assistant?

Like this:

globals:
  - id: rot_wert
    type: float
    restore_value: true  # Sicherstellen, dass der Wert nach einem Reboot erhalten bleibt
    initial_value: '1.6'  # Der Startwert, falls keine gespeicherten Werte existieren
  - id: gruen_wert
    type: float
    restore_value: true  # Sicherstellen, dass der Wert nach einem Reboot erhalten bleibt
    initial_value: '66'
  - id: blau_wert
    type: float
    restore_value: true  # Sicherstellen, dass der Wert nach einem Reboot erhalten bleibt
    initial_value: '95'

text:
  - platform: template
    min_length: 0
    max_length: 100
    mode: text
    name: "Hex-Farbe"
    id: hex_farbe
    optimistic: true
    restore_value: true
    on_value:
      lambda: |-
        std::string hex = id(hex_farbe).state.c_str();  // Holen des Hex-Farbwerts
        uint32_t color = strtol(hex.c_str(), nullptr, 16);  // Hex in Zahl umwandeln
        uint8_t red = ((color >> 16) & 0xFF);  // Extrahieren des Rot-Werts (höchstes Byte)
        uint8_t green = ((color >> 8) & 0xFF);  // Extrahieren des Grün-Werts (mittleres Byte)
        uint8_t blue = (color & 0xFF);  // Extrahieren des Blau-Werts (niedrigstes Byte)
        id(rot_wert) = red / 255.0;
        id(gruen_wert) = green / 255.0;
        id(blau_wert) = blue / 255.0;

And the light gets controlled like this:


# beginn der sprachausgabe
  on_tts_stream_start:
    - light.turn_on:
        id: led_strip
        effect: "Fireworks Effect With Custom Values"
        red: !lambda "return id(rot_wert);"
        green: !lambda "return id(gruen_wert);"
        blue: !lambda "return id(blau_wert);"
        brightness: 60%