Ikea remote with Ikea bulb, cycle through list of colors using left/right buttons

Hi

I’m using Z2M addon in HA and I have one Ikea E2002 remote and one Ikea Light Bulb (LED1924G9). I have tried to bind the remote to the bulb in z2m which works but it cannot change color for some reason. So I tried to create an automation directly in HA instead using a blueprint I found for the remote.

I can get most of it to work but I’m stuck when it comes to changing colors with left/right arrows. I’m able to add 1 color to left and 1 color to right. But I would like to use a list of for example 8 colors which it will cycle though when pressing left or right buttons on the remote.

I guess when I press for example the left button/arrow it needs to know which color is used on the bulb right now in order to go to the next one on the list.

The states on the Bulb shows:

supported_color_modes:

  • color_temp
  • xy

So I was thinking of using xy_color to check which color is used and set new color using color_name

In template view I got this to work:

{% if state_attr("light.living_room_celling_lamp","xy_color") == (0.6942, 0.2963) %} 
red
{% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.5524, 0.4079) %} 
gold
{% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.4339, 0.5008) %} 
yellow
{% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.1704, 0.709) %} 
green
{% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.1355, 0.0399) %} 
blue
{% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.4066, 0.1643) %} 
purple
{% else %}
white
{% endif %} 

Depending on which color I use it will display what next option should be if I pressed left button/arrow. But it does not work when I put the same code in a real automation template:

    arrow_left_push:
      - service: light.turn_on
        metadata: {}
        data:
          color_name: >
            {% if state_attr("light.living_room_celling_lamp","xy_color") ==
            (0.6942, 0.2963) %} red {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.5524,
            0.4079) %} gold {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.4339,
            0.5008) %} yellow {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.1704,
            0.709) %} green {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.1355,
            0.0399) %} blue {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.4066,
            0.1643) %}  purple {% else %} white {% endif %}          
        target:
          entity_id: light.living_room_celling_lamp
        enabled: true

I have the same issue if I use xy_color instead of color_name:

    arrow_right_push:
      - service: light.turn_on
        metadata: {}
        data:
          xy_color: >
            {% if state_attr("light.living_room_celling_lamp","xy_color") == (0.6942, 0.2963) %} 
            - 0.5524
            - 0.4079
            {% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.5524, 0.4079) %} 
            - 0.4339
            - 0.5008
            {% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.4339, 0.5008) %} 
            - 0.1704
            - 0.709
            {% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.1704, 0.709) %} 
            - 0.1355
            - 0.0399
            {% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.1355, 0.0399) %} 
            - 0.4066
            - 0.1643
            {% elif state_attr("light.living_room_celling_lamp","xy_color") == (0.4066, 0.1643) %} 
            - 0.6942
            - 0.2963
            {% else %}
            - 0.6942
            - 0.2963
            {% endif %          
        target:
          entity_id: light.living_room_group

What am I doing wrong here?
Or perhaps there is a better solution?
I just want to have a predefined list of colors which I can cycle thought when I press left or right on the Ikea remote.

Or perhaps someone know how to bind the remote directly in z2m to the bulb and get all functions working including color changes, more or less like it works from factory when they are paired together.

I have solved it, for anyone that want to know what I did please check below solution, perhaps it could even be done better:

    arrow_left_push:
      - service: light.turn_on
        metadata: {}
        data:
          color_name: >
            {% if state_attr("light.living_room_celling_lamp","xy_color") ==
            (0.701, 0.299) %}  orange {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.494,
            0.474) %}  red {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.172,
            0.747) %}  gold {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.444,
            0.517) %}  green {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.136,
            0.04) %}  yellow {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.385,
            0.155) %}  blue {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.323,
            0.329) %}  purple {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.355,
            0.349) %}  white {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.562,
            0.417) %}  antiquewhite {% else %} red {% endif %} 
        target:
          entity_id: light.living_room_celling_lamp
        enabled: true
    arrow_right_push:
      - service: light.turn_on
        metadata: {}
        data:
          color_name: >
            {% if state_attr("light.living_room_celling_lamp","xy_color") ==
            (0.701, 0.299) %}  gold {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.494,
            0.474) %}  green {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.172,
            0.747) %}  yellow {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.444,
            0.517) %}  blue {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.136,
            0.04) %}  purple {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.385,
            0.155) %}  white {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.323,
            0.329) %}  antiquewhite {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.355,
            0.349) %}  orange {% elif
            state_attr("light.living_room_celling_lamp","xy_color") == (0.562,
            0.417) %}  red {% else %} red {% endif %}          
        target:
          entity_id: light.living_room_celling_lamp
        enabled: true

I use following blueprint: KeviinCosmos/Blueprint - IKEA Styrbar E2001-2002.yaml

The idea is following:

  • I use the “xy_color” command produced when choosing colors in the “color_name” drop down
  • In order to see this dropdown and many other options you need to choose “Add Action” → “Light” → “Turn on”, choose correct entity (bulb or led or whatever light source you want to control and then you will see a list of choices. There you will find color name drop down to play around with.
  • If the bulb is on any other color/setting besides what is found in the below list; start at the color red from either direction (right or left button/arrow pressed).
  • Color list is following order when pressing the right button/arrow:
    • red
    • gold
    • green
    • yellow
    • blue
    • purple
    • white
    • antiquewhite
    • orange
    • AND then back to red again and the circle continues.
  • Opposite way when pressing left button/arrow
2 Likes