Skip to content

Instantly share code, notes, and snippets.

@niro1987
Last active November 30, 2023 18:51
Show Gist options
  • Save niro1987/f6e84c27b304f0bf3be16a8f439e8efd to your computer and use it in GitHub Desktop.
Save niro1987/f6e84c27b304f0bf3be16a8f439e8efd to your computer and use it in GitHub Desktop.
Home Assistant - Blueprint - Zigbee2MQTT - IKEA TRADFRI - 5 Button Remote - Warm White Lights
---
# This automation simulates the use of the IKEA TRADFRI Remote control
# connected through Zigbee2MQTT.
# | Button | Action |
# | -------- | -------------------- |
# | Power | Toggle the light |
# | Dim-Up | Increase brightness |
# | Dim-Down | Decrease brightness |
# | Right | Increase temperature |
# | Left | Decrease temperature |
blueprint:
source_url: https://gist.github.com/niro1987/f6e84c27b304f0bf3be16a8f439e8efd
name: Zigbee2MQTT - IKEA TRADFRI - 5 Button Remote - Warm White Lights
description: >-
This automation simulates the use of the IKEA TRADFRI Remote control
connected through Zigbee2MQTT.
domain: automation
input:
remote_entity:
name: Remote Sensor Entity
description: The sensor entity created by Zigbee2MQTT
selector:
entity:
domain: sensor
light_entity:
name: Light
description: The light entity to control.
selector:
target:
entity:
domain: light
mode: restart
variables:
var_light_entities: !input light_entity
trigger:
- platform: state
entity_id: !input remote_entity
to:
- "toggle"
- "toggle_hold"
- "brightness_up_click"
- "brightness_down_click"
- "arrow_left_click"
- "arrow_right_click"
- "brightness_up_hold"
- "brightness_down_hold"
- "arrow_left_hold"
- "arrow_right_hold"
- "brightness_up_release"
- "brightness_down_release"
- "arrow_left_release"
- "arrow_right_release"
action:
- choose:
# Short-Press on the power button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "toggle" }}'
sequence:
- service: light.toggle
target: !input light_entity
# Short-Press on the dim-up button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "brightness_up_click" }}'
sequence:
- service: light.turn_on
target: !input light_entity
data:
brightness_step_pct: 20
transition: 0.5
# Short-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "brightness_down_click" }}'
sequence:
- service: light.turn_on
target: !input light_entity
data:
brightness_step_pct: -20
transition: 0.5
# Short-Press on the color-up button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "arrow_left_click" }}'
sequence:
- service: light.turn_on
target: !input light_entity
data:
color_temp: >-
{% if state_attr(var_light_entities.entity_id[0], "color_temp") - 18 < 153 %}
{{ 153 }}
{% else %}
{{ state_attr(var_light_entities.entity_id[0], "color_temp") - 18 }}
{% endif %}
transition: 0.5
# Short-Press on the color-down button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "arrow_right_click" }}'
sequence:
- service: light.turn_on
target: !input light_entity
data:
color_temp: >-
{% if state_attr(var_light_entities.entity_id[0], "color_temp") + 18 > 500 %}
{{ 500 }}
{% else %}
{{ state_attr(var_light_entities.entity_id[0], "color_temp") + 18 }}
{% endif %}
transition: 0.5
# Long-Press on the power button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "toggle_hold" }}'
sequence:
- service: light.turn_on
target: !input light_entity
data:
brightness: 254
color_temp: 400
# Long-Press on the dim-up button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "brightness_up_hold" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
target: !input light_entity
data:
brightness_step_pct: 10
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "brightness_down_hold" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
target: !input light_entity
data:
brightness_step_pct: -10
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the color-up button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "arrow_left_hold" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
target: !input light_entity
data:
color_temp: >-
{% if state_attr(var_light_entities.entity_id[0], "color_temp") - 18 < 153 %}
{{ 153 }}
{% else %}
{{ state_attr(var_light_entities.entity_id[0], "color_temp") - 18 }}
{% endif %}
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the color-down button.
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "arrow_right_hold" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
target: !input light_entity
data:
color_temp: >-
{% if state_attr(var_light_entities.entity_id[0], "color_temp") + 18 > 500 %}
{{ 500 }}
{% else %}
{{ state_attr(var_light_entities.entity_id[0], "color_temp") + 18 }}
{% endif %}
transition: 0.5
- delay:
milliseconds: 500
# Any other event will cancel the repeat loops.
default: []
@niro1987
Copy link
Author

Great to hear that you've got it working now!
By the looks of it, the light group does allow a color_temp to be set but it does not actually report what it's current color_temp value is.

@dbara
Copy link

dbara commented Jul 4, 2021

Hey Niro, I now had the Time to fork it, but somehow it doesn't seem to work.. I already deleted it, as I thought my edits were the issue, now I have a fresh fork but it still doesn't work properly.
I get the error "Error rendering data template: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'"
Happenes for the light color (color temp).

Do you have any idea?

The fork is here:
https://gist.github.com/dbara/911b76bb842bf2c76362c0ac9abb443b

@dbara
Copy link

dbara commented Jul 5, 2021

Hey again, I found the issue and how to fix it. When you select one entity, it adds it differently than when you add multiple. You have to edit the automation as yaml and correct it.

Wrong:
light_entity:
entity_id: light.0xbc...

Correct:
light_entity:
entity_id:
- light.0xbc...

Have a good day

@RaulVKoNe
Copy link

Hola de nuevo, encontré el problema y cómo solucionarlo. Cuando selecciona una entidad, la agrega de manera diferente que cuando agrega varias. Tienes que editar la automatización como yaml y corregirla.

Incorrecto: light_entity: entity_id: light.0xbc ...

Correcto: light_entity: entity_id: - light.0xbc ...

Que tenga un buen día

Thanks! I had the same problem with the Ikea bulbs and solved it with your tip

@jelflein
Copy link

replace every var_light_entities.entity_id[0] with var_light_entities.entity_id

@legionGer
Copy link

legionGer commented Nov 30, 2023

Okay, can someone help me out here? I got the same issue with the colors. The Tradfri bulb has the property of "color_temp" but it won't change the color, always gives the same error:

Logger: homeassistant.components.automation.zigbee2mqtt_ikea_tradfri_5_button_remote_warm_white_lights
Source: components/automation/__init__.py:676
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 17:48:25 (57 occurrences)
Last logged: 19:48:19

Error while executing automation automation.zigbee2mqtt_ikea_tradfri_5_button_remote_warm_white_lights: Error rendering data template: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
Error while executing automation automation.zigbee2mqtt_ikea_tradfri_5_button_remote_warm_white_lights: Error rendering data template: TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

I already repaired the bulb twice, no change. I can change the color using the dev menu or my own automatisation just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment