ZHA - IKEA Styrbar - White Spectrum Lights

This Blueprint was made to control White Spectrum Lights via an IKEA Styrbar Remote connected trough ZHA.
Check out @niro1987 's awesome blueprint for the Tradfri 5 Button remote, this blueprint is based on his work and adopted to work with the Styrbar remote. Thank @niro1987!

Button Duration Action
Dim-Up short Turn on
Dim-Down short Turn off
Dim-Up long Increase brightness
Dim-Down long Decrease brightness
Right short/long Increase temperature
Left short/long Decrease temperature

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
    name: ZHA - IKEA Styrbar - Warm White Lights
    description: Control a light with white spectrum and dimming via a Ikea Styrbar Remote connected trough ZHA
    domain: automation


    input:
        remote:
            name: IKEA Styrbar remote control
            description: Select the remote control you wish to use.
            selector:
                device:
                    integration: zha
                    manufacturer: IKEA of Sweden
                    model: Remote Control N2

        light:
            name: Light
            description: Select the light entity you wish to control.
            selector:
                entity:
                    domain: light
                    
mode: restart
max_exceeded: silent
variables:
  var_light: !input light

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input remote

action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "on" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "off" }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input light
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    brightness_step_pct: 10
                    transition: 0.5
                - delay:
                    milliseconds: 500
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "move" }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    brightness_step_pct: -10
                    transition: 0.5
                - delay:
                    milliseconds: 500
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "press" }}'
          - condition: template
            value_template: '{{ trigger.event.data.args == [256,13,0] }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
            data:
              color_temp: |-
                {% if state_attr(var_light, "color_temp") - 25 < 153 %}
                  {{ 153 }}
                {% else %}
                  {{ state_attr(var_light, "color_temp") - 25 }}
                {% endif %}
              transition: 0.5
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "hold" }}'
          - condition: template
            value_template: '{{ trigger.event.data.args == [3328,0] }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    color_temp: |-
                      {% if state_attr(var_light, "color_temp") - 25 < 153 %}
                        {{ 153 }}
                      {% else %}
                        {{ state_attr(var_light, "color_temp") - 25 }}
                      {% endif %}
                    transition: 0.5
                - delay:
                    milliseconds: 500
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "press" }}'
          - condition: template
            value_template: '{{ trigger.event.data.args == [257,13,0] }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
            data:
              color_temp: |-
                {% if state_attr(var_light, "color_temp") + 25 > 500 %}
                  {{ 500 }}
                {% else %}
                  {{ state_attr(var_light, "color_temp") + 25 }}
                {% endif %}
              transition: 0.5
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "hold" }}'
          - condition: template
            value_template: '{{ trigger.event.data.args == [3329,0] }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    color_temp: |-
                      {% if state_attr(var_light, "color_temp") + 25 > 500 %}
                        {{ 500 }}
                      {% else %}
                        {{ state_attr(var_light, "color_temp") + 25 }}
                      {% endif %}
                    transition: 0.5
                - delay:
                    milliseconds: 500
    default: []
11 Likes

Hi, can you help me with setting this up?
I have my remote connected, lights I want to control are in a group and I have set the automation to use the remote to control the lights.

Now I get following errors in the log and remote is not doing anything. I dont know how to solve this and googlefu didnt help.

Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'

and

2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "on" }}'
2021-12-15 17:27:44 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'
2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "off" }}'
2021-12-15 17:27:44 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'
2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "move_with_on_off" }}'
2021-12-15 17:27:44 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'
2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "move" }}'
2021-12-15 17:27:44 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'
2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "press" }}'
2021-12-15 17:27:44 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'
2021-12-15 17:27:44 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command == "hold" }}'

Hey wondrej,
hmm, the ZHA Event doesn’t seem to contain the expected information.
Would you please check the content of the zha events fired by your remote?
In order to do so, go to developer tools > events, enter “zha_event” in the “listen to” text input and click on “start listening”. You should then see events popping up when pressing a button on your remote.

Hi! sorry for confusion. I thought its something wrong with the blueprint, but repairing the remote fixed all the issues.

Thank you for the blueprint, it works great!

great to hear!

Do you know how to convert this to z2m? Im new to home assistant so i cant get get it to work by myself

Hey revedar,
Have a look at the AwesomeHA Blueprint projekt: Awesome HA Blueprints | Awesome HA Blueprints

Hi Jeff, I need to use this code and apply it to a group of Ikea rgb lights, but I’m at a loss. How could I adapt it?
Thank you very much!!

Maybe this helps you:

1 Like

Thank you! Exactly what I’m looking for.

1 Like

Hi, worked first time without any issue and performed like it should. Well done, thank you for this blueprint. I’m still trying to have the controller and light work to work. Regards, Luis Sismeiro

Thank you, this was so easy to implement!
I made some changes to speed up the transitions (because I’m impatient) and to always start a specific scene instead of turning on my light group.
I could not have done it without the simplifications you have made to ZHA - IKEA TRADFRI - 5 Button Remote - Warm White Lights.

This is the best blueprint that worked with my pair of styrbar and tradfri bulbs.

I’ve made some changes to make it more customizable and fix some things that worked better for me but hopefully will work better for more people.

I’m a bit new to Home Assistant so I still don’t know all the tidbits of how to contribute to existing blueprints, so I’m pasting the full blueprint with my changes here. LMK if there’s a better way.

blueprint:
  name: ZHA - IKEA Styrbar - Warm White Lights
  description: Control a light with white spectrum and dimming via a Ikea Styrbar
    Remote connected trough ZHA
  domain: automation
  input:
    remote:
      name: IKEA Styrbar remote control
      description: Select the remote control you wish to use.
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: Remote Control N2
          multiple: false
    light:
      name: Light
      description: Select the light entity you wish to control.
      selector:
        entity:
          domain:
          - light
          multiple: false
    brightness_step:
      name: Brightness Step
      description: Rate at which brightness goes up and down
      default: 2
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: "%"
    color_temp_step:
      name: Color Temp Step
      description: Kelvin at which color temperature goes up and down on button hold
      default: 100
      selector:
        number:
          min: 0
          max: 1000
          unit_of_measurement: "kelvin"
    color_temp_step_press:
      name: Color Temp Step On Press
      description: Kelvin at which color temperature goes up and down on button press
      default: 500
      selector:
        number:
          min: 0
          max: 1000
          unit_of_measurement: "kelvin"
    min_color_temp:
      name: Minimum Color Value
      description: Minimum device supported color temperature in Kelvin
      default: 2202
      selector:
        number:
          min: 2000
          max: 6500
          unit_of_measurement: "kelvin"
    max_color_temp:
      name: Maximum Color Value
      description: Maximum device supported color temperature in Kelvin
      default: 4000
      selector:
        number:
          min: 2000
          max: 6500
          unit_of_measurement: "kelvin"
    transition_time:
      name: Transition time
      description: Time in seconds in which transitions happen 
      default: 0.5
      selector:
        number:
          min: 0.0
          max: 5.0
          step: 0.1
          unit_of_measurement: seconds
  source_url: https://community.home-assistant.io/t/zha-ikea-styrbar-warm-white-lights/341688
mode: restart
max_exceeded: silent
variables:
  var_light: !input light
  var_brightness_step: !input brightness_step
  var_color_temp_step: !input color_temp_step
  var_color_temp_step_press: !input color_temp_step_press
  var_min_color_temp: !input min_color_temp
  var_max_color_temp: !input max_color_temp
  var_transition_time: !input transition_time
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input remote
action:
- choose:
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "on" }}'
    sequence:
    - service: light.turn_on
      target:
        entity_id: !input light
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "off" }}'
    sequence:
    - service: light.turn_off
      target:
        entity_id: !input light
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
    sequence:
    - repeat:
        while: []
        sequence:
        - service: light.turn_on
          target:
            entity_id: !input light
          data:
            brightness_step_pct: !input brightness_step
            transition: !input transition_time
        - delay:
            milliseconds: "{{ var_transition_time * 1000 }}"
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "move" }}'
    sequence:
    - repeat:
        while: []
        sequence:
        - service: light.turn_on
          target:
            entity_id: !input light
          data:
            brightness_step_pct: "-{{ var_brightness_step }}"
            transition: !input transition_time
        - delay:
            milliseconds: "{{ var_transition_time * 1000 }}"
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "press" }}'
    - condition: template
      value_template: '{{ trigger.event.data.args == [256,13,0] }}'
    sequence:
    - service: light.turn_on
      target:
        entity_id: !input light
      data:
        color_temp_kelvin: '{{ max(state_attr(var_light, "color_temp_kelvin") - var_color_temp_step_press, var_min_color_temp) }}'
        transition: !input transition_time
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "hold" }}'
    - condition: template
      value_template: '{{ trigger.event.data.args == [3328,0] }}'
    sequence:
    - repeat:
        while: []
        sequence:
        - service: light.turn_on
          target:
            entity_id: !input light
          data:
            color_temp_kelvin: '{{ max(state_attr(var_light, "color_temp_kelvin") - var_color_temp_step, var_min_color_temp) }}'
            transition: !input transition_time
        - delay:
            milliseconds: "{{ var_transition_time * 1000 }}"
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "press" }}'
    - condition: template
      value_template: '{{ trigger.event.data.args == [257,13,0] }}'
    sequence:
    - service: light.turn_on
      target:
        entity_id: !input light
      data:
        color_temp_kelvin: '{{ min(state_attr(var_light, "color_temp_kelvin") + var_color_temp_step_press, var_max_color_temp) }}'
        transition: !input transition_time
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "hold" }}'
    - condition: template
      value_template: '{{ trigger.event.data.args == [3329,0] }}'
    sequence:
    - repeat:
        while: []
        sequence:
        - service: light.turn_on
          target:
            entity_id: !input light
          data:
            color_temp_kelvin: '{{ min(state_attr(var_light, "color_temp_kelvin") + var_color_temp_step, var_max_color_temp) }}'
            transition: !input transition_time
        - delay:
            milliseconds: "{{ var_transition_time * 1000 }}"
  default: []

What changes ?

Simplified the code a bit, made the steps for brightness and color temperature configurable (both on button presses and clicks), tied the transition time to the delay (and made it configurable) as it will avoid problems on holding for longer and stacking multiple events…

I think those are what I remember. This made it almost perfect to me as the color temp still has a bit of a delay to start triggering whilst holding, but this is also true in other blueprints, so I think might be a styrbar integration issue.