Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Home Assistant - Control a light with zigbee buttons
---
#
# This automation simulates the use of the IKEA TRADFRI Remote control
# connected through zha but should also work for other type of events.
# Requires Home Assistant 0.113 or higher.
#
id: 'living_room-ikea_remote'
alias: IKEA Remote
description: ''
mode: restart
trigger:
- platform: event
event_type: zha_event
condition:
- condition: template
# Change this to your own device_ieee (lookup on the device page)
value_template: '{{ trigger.event.data.device_ieee == "14:b4:57:ff:fe:50:4c:58" }}'
action:
- choose:
# Short-Press on the power button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "toggle" }}'
sequence:
- service: light.toggle
data_template:
entity_id: light.living_room
# Short-Press on the dim-up button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "step_with_on_off" }}'
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness_step_pct: 20
transition: 0.5
# Short-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "step" }}'
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness_step_pct: -20
transition: 0.5
# Short-Press on the color-up button.
- 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
data_template:
entity_id: light.living_room
hs_color:
- >-
{% if state_attr("light.living_room", "hs_color")[0] + 18 > 360 %}
{{ state_attr("light.living_room", "hs_color")[0] + 18 - 360 }}
{% else %}
{{ state_attr("light.living_room", "hs_color")[0] + 18 }}
{% endif %}
- '{{ state_attr("light.living_room", "hs_color")[1] }}'
transition: 0.5
# Short-Press on the color-down button.
- 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
data_template:
entity_id: light.living_room
hs_color:
- '{{ state_attr("light.living_room", "hs_color")[0] }}'
- >-
{% if state_attr("light.living_room", "hs_color")[1] - 20 < 0 %}
{{ state_attr("light.living_room", "hs_color")[1] - 20 + 100 }}
{% else %}
{{ state_attr("light.living_room", "hs_color")[1] - 20 }}
{% endif %}
transition: 0.5
# Long-Press on the power button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move_to_level_with_on_off" }}'
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness: 254
hs_color:
- 38.222
- 52.941
# Long-Press on the color-up button.
- 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
data_template:
entity_id: light.living_room
hs_color:
- >-
{% if state_attr("light.living_room", "hs_color")[0] + 18 > 360 %}
{{ state_attr("light.living_room", "hs_color")[0] + 18 - 360 }}
{% else %}
{{ state_attr("light.living_room", "hs_color")[0] + 18 }}
{% endif %}
- '{{ state_attr("light.living_room", "hs_color")[1] }}'
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the color-down button.
- 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
data_template:
entity_id: light.living_room
hs_color:
- '{{ state_attr("light.living_room", "hs_color")[0] }}'
- >-
{% if state_attr("light.living_room", "hs_color")[1] - 10 < 0 %}
{{ state_attr("light.living_room", "hs_color")[1] - 10 + 100 }}
{% else %}
{{ state_attr("light.living_room", "hs_color")[1] - 10 }}
{% endif %}
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the dim-up button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness_step_pct: 10
transition: 0.5
- delay:
milliseconds: 500
# Long-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move" }}'
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness_step_pct: -10
transition: 0.5
- delay:
milliseconds: 500
# Any other event will cancel the repeat loops.
default: []
@J-Lindvig

This comment has been minimized.

Copy link

@J-Lindvig J-Lindvig commented Aug 17, 2020

Hello....

Thank you for your excellent work on the remotes for ZHA - I have used the code and altered it to fit a more generic and extendable use.
You are able to see my work here:
https://github.com/J-Lindvig/Home-Assistant-Master/blob/master/include/packages/lights/zha_remotes.yaml

In my automation, I have a list of remotes and thier lights, then I call a script to handle determine which function to call.

/Jacob

@niro1987

This comment has been minimized.

Copy link
Owner Author

@niro1987 niro1987 commented Sep 19, 2020

Hi @J-Lindvig,
yw, I've tried to make it as customizable and easy on the eye as possible.
Your link seems to be broken, would you mind posting it as a gist so that it doesn't get effected by updates on your git repo?

@J-Lindvig

This comment has been minimized.

Copy link

@J-Lindvig J-Lindvig commented Sep 19, 2020

@maxwood

This comment has been minimized.

Copy link

@maxwood maxwood commented Dec 3, 2020

Hey @niro1987, thanks for creating this. As a total n00b it's extremely helpful to me!

Is this intended to be used with the Tradfri colour temp bulbs? The colour up and down buttons don't seem to have any effect for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.