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!
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, 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: []
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.
I’ve made some changes on it today to work with scenes instead if anyone’s interested.
It will:
Clicking the turn-on button with all lights off will restore the last activated scene
Doing the same with at least one set of lights active, will cycle through the configured list of scenes
Holding on or of will decrease or increase the brightness of the lights turned on
Pressing left or right will increase or decrease color temperature by a big step of the lights turned on
Holding left or right doesn’t work well, but it was supposed to granularly increase or decrease color warmth, but it’s confusing everything at the moment.
There’s a few requirements
You need to have only one light group on a specific scene
You need to have a light group which includes all lights (to detect if any are on and to turn all of them off just in case)
blueprint:
name: ZHA - IKEA Styrbar - Switch scenes
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 which has all the lights to power off
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
included_scenes:
name: Included Scenes
description: Additional scenes to be included
default: []
selector:
entity:
filter:
domain: scene
multiple: true
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
included_scenes: !input "included_scenes"
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: scene.turn_on
data_template:
transition: !input transition_time
entity_id: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set index_of_last_activated_scene = all_scenes.index(last_activated_scene) %}
{% if is_state(var_light,'on') %}
{% set new_index = index_of_last_activated_scene + 1 %}
{% else %}
{% set new_index = index_of_last_activated_scene %}
{% endif %}
{% if new_index == all_scenes | count %}
{{ all_scenes[0] }}
{% else %}
{{ all_scenes[new_index] }}
{% endif %}
- 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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: >
{% set all_scenes = (included_scenes | list) %}
{% set scenes_sorted_by_activation = expand(all_scenes) | sort(attribute='state', reverse = true) | map(attribute='entity_id') | list %}
{% set last_activated_scene = scenes_sorted_by_activation[0] %}
{% set scene_entities = state_attr(last_activated_scene, 'entity_id') %}
{% for entity in scene_entities %}
{% if 'light.' in entity and states(entity) == 'on' %}
{{ entity }}
{% endif %}
{% endfor %}
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: []
It works for the for the time being so I’m not in a rush to fix or simplify the argument in a template. I found it pretty useful in a kitchen/living room area with different scenes set.