Change light color using helper and input select ikea tradfri

Hello

I need to make my ikea styrbar remote change color on my ikea tradfri lightbulps, using a helper containing a dropdown helper, containing the color names.

Im using this blueprint: Malte/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002.yaml

Bulps: TRADFRI bulb E27 CWS 806lm
Remote: Remote Control N2
sensor group: light.bedroom_lightbulps (containing both bulps)

Problem: When changing the bulp colors with input.select_next and input.select_previous - i changes the colors, but it seems a bit random, wich color is selected.

Can anyone spot any obvious mistakes?

alias: Bedroom color cycle
description: ""
use_blueprint:
  path: Malte/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002.yaml
  input:
    remote: 129cd9955d663409e9870e58286a4f2c
    light:
      entity_id:
        - light.bedroom_lightbulps
    button_left_short:
      - service: light.turn_on
        data:
          color_name: "{{ states('input_select.color_list_1') }}"
        target:
          entity_id: light.bedroom_lightbulps
      - service: input_select.select_next
        target:
          entity_id: input_select.color_list_1
        data:
          cycle: true
    button_right_short:
      - service: light.turn_on
        data:
          color_name: "{{ states('input_select.color_list_1') }}"
        target:
          entity_id: light.bedroom_lightbulps
      - service: input_select.select_previous
        target:
          entity_id: input_select.color_list_1
        data:
          cycle: true

Hopefully someone knows what is wrong here - thank you in advance

I did a lot of research and found a solution:

My setup for this to work is:

Bulps: 2xTRADFRI bulb E27 CWS 806lm
Remote: Remote Control N2

Helper group: light.sovevaerelse_paerer (containing both bulps)
Watch this to see how: https://www.youtube.com/watch?v=Al9RKee3_NI

Blueprint: Malte/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002.yaml

Out of the box, the blueprint give on/off and brightness control for the up and down buttons

I now did the short/long press for left and right buttons

short left click: change one color back
short right click: change one color forward

Long press left: change color_temp down
Long press right: change color_temp up

You need to create a helper that contains the colors you want or your bulp(s) supports.

Inspired by: https://www.youtube.com/watch?v=BG0VvQlePkI

settings → devices & services → select helpers → create helper → select dropdown

Now you just need to add the colors you want, you can find color names here:

or a shorter list here:

Don’t expect every color to be supported by your bulps.

Name the color list: Color List 1

alias: Soveværelse lys color cycle with Color Temperature Adjustment
description: ""
use_blueprint:
  path: Malte/zha-ikea-four-button-remote-styrbar-for-lights-e2001-e2002.yaml
  input:
    remote: 129cd9955d663409e9870e58286a4f2c
    light:
      entity_id:
        - light.sovevaerelse_paerer
    button_left_short:
      - service: input_select.select_option
        data_template:
          entity_id: input_select.color_list_1
          option: >
            {% set current_color = states('input_select.color_list_1') %} {% set
            color_list = states.input_select.color_list_1.attributes.options %}
            {% set max_index = color_list | length - 1 %} {% set current_index =
            color_list.index(current_color) %} {{ color_list[current_index - 1]
            if current_index > 0 else color_list[max_index] }}
      - service: light.turn_on
        data_template:
          color_name: "{{ states('input_select.color_list_1') }}"
        target:
          entity_id: light.sovevaerelse_paerer
      - service: input_text.set_value
        data_template:
          entity_id: input_text.bedroom_last_color_selected
          value: "{{ states('input_select.color_list_1') }}"
      - service: logbook.log
        data_template:
          name: Bedroom light color changed on left button press
          message: Color changed to {{ states('input_select.color_list_1') }}
    button_right_short:
      - service: input_select.select_option
        data_template:
          entity_id: input_select.color_list_1
          option: >
            {% set current_color = states('input_select.color_list_1') %} {% set
            color_list = states.input_select.color_list_1.attributes.options %}
            {% set max_index = color_list | length - 1 %} {% set current_index =
            color_list.index(current_color) %} {{ color_list[current_index + 1]
            if current_index < max_index else color_list[0] }}
      - service: light.turn_on
        data_template:
          color_name: "{{ states('input_select.color_list_1') }}"
        target:
          entity_id: light.sovevaerelse_paerer
      - service: input_text.set_value
        data_template:
          entity_id: input_text.bedroom_last_color_selected
          value: "{{ states('input_select.color_list_1') }}"
      - service: logbook.log
        data_template:
          name: Bedroom light color changed on right button press
          message: Color changed to {{ states('input_select.color_list_1') }}
    button_left_long:
      - repeat:
          while:
            - condition: template
              value_template: >-
                {{ state_attr('light.sovevaerelse_paerer', 'color_temp') |
                default(454, true) | int > 250 }}
          sequence:
            - service: light.turn_on
              data_template:
                entity_id: light.sovevaerelse_paerer
                color_temp: >
                  {% set current_temp = state_attr('light.sovevaerelse_paerer',
                  'color_temp') | default(454, true) | int %} {% set new_temp =
                  current_temp - 20 %} {{ [new_temp, 250] | max }}
            - delay: 0.5
      - service: logbook.log
        data_template:
          name: Bedroom light color temperature decreased on left long press
          message: Color temperature decreased for light.sovevaerelse_paerer
    button_right_long:
      - repeat:
          while:
            - condition: template
              value_template: >-
                {{ state_attr('light.sovevaerelse_paerer', 'color_temp') |
                default(250, true) | int < 454 }}
          sequence:
            - service: light.turn_on
              data_template:
                entity_id: light.sovevaerelse_paerer
                color_temp: >
                  {% set current_temp = state_attr('light.sovevaerelse_paerer',
                  'color_temp') | default(250, true) | int %} {% set new_temp =
                  current_temp + 20 %} {{ [new_temp, 454] | min }}
            - delay: 0.5
      - service: logbook.log
        data_template:
          name: Bedroom light color temperature increased on right long press
          message: Color temperature increased for light.sovevaerelse_paerer

If you look in the code you see i have 250 and 454 multiple times - These numbers are my min_mireds and max_mireds, so if your bulps have different numbers for min/max mireds, adjust in the code.

Last i want to say, i have no idea if this is the best way to doit or not… but it works :slight_smile:
Hopefully this will save you some time, as i spent alot on figuring this out :wink: