Instantly share code, notes, and snippets.
Created
January 22, 2022 12:44
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save psy/e30c93fbb85e86272ef5d7a1a40ff479 to your computer and use it in GitHub Desktop.
zha blueprint to control ligts with tradfri remote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This automation simulates the use of the IKEA TRADFRI Remote control | |
# connected through ZHA. | |
# based on: https://community.home-assistant.io/t/zha-ikea-tradfri-5-button-remote-color-lights/276816 | |
# | Button | Action | | |
# | -------- | ------------------- | | |
# | Power | Toggle the light | | |
# | Dim-Up | Increase brightness | | |
# | Dim-Down | Decrease brightness | | |
# | Right | Change color | | |
# | Left | Change color | | |
blueprint: | |
name: ZHA - IKEA TRADFRI - 5 Button Remote - Colored light | |
description: >- | |
This automation simulates the use of the IKEA TRADFRI remote control | |
connected through ZHA. | |
domain: automation | |
input: | |
remote: | |
name: IKEA TRADFRI remote control | |
description: Select the remote control you wish to use. | |
selector: | |
device: | |
integration: zha | |
manufacturer: IKEA of Sweden | |
model: TRADFRI remote control | |
light: | |
name: Light | |
description: Select the light entity you wish to control. | |
selector: | |
entity: | |
domain: light | |
speed: | |
name: Speed | |
description: The speed in which to update the light when the button is held. | |
selector: | |
number: | |
min: 100 | |
max: 1000 | |
step: 100 | |
unit_of_measurement: milliseconds | |
mode: slider | |
default: 500 | |
mode: restart | |
max_exceeded: silent | |
variables: | |
var_light: !input light | |
var_speed: !input speed | |
trigger: | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input remote | |
action: | |
- choose: | |
# Short-Press on the power button. | |
- conditions: | |
- condition: template | |
value_template: '{{ trigger.event.data.command == "toggle" }}' | |
sequence: | |
- service: light.toggle | |
target: | |
entity_id: !input light | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
brightness: 254 | |
hs_color: | |
- 38.222 | |
- 52.941 | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
brightness_step_pct: 20 | |
transition: "{{ (var_speed / 1000)|float }}" | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
brightness_step_pct: 10 | |
transition: "{{ (var_speed / 1000)|float }}" | |
- delay: | |
milliseconds: !input speed | |
# Short-Press on the dim-down button. | |
- conditions: | |
- condition: template | |
value_template: '{{ trigger.event.data.command == "step" }}' | |
sequence: | |
- service: light.turn_on | |
target: | |
entity_id: !input light | |
data: | |
brightness_step_pct: -20 | |
transition: "{{ (var_speed / 1000)|float }}" | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
brightness_step_pct: -10 | |
transition: "{{ (var_speed / 1000)|float }}" | |
- delay: | |
milliseconds: !input speed | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
hs_color: | |
- >- | |
{% if state_attr(var_light, "hs_color")[0] + 18 > 360 %} | |
{{ state_attr(var_light, "hs_color")[0] + 18 - 360 }} | |
{% else %} | |
{{ state_attr(var_light, "hs_color")[0] + 18 }} | |
{% endif %} | |
- '{{ state_attr(var_light, "hs_color")[1] }}' | |
transition: "{{ (var_speed / 1000)|float }}" | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
hs_color: | |
- >- | |
{% if state_attr(var_light, "hs_color")[0] + 18 > 360 %} | |
{{ state_attr(var_light, "hs_color")[0] + 18 - 360 }} | |
{% else %} | |
{{ state_attr(var_light, "hs_color")[0] + 18 }} | |
{% endif %} | |
- '{{ state_attr(var_light, "hs_color")[1] }}' | |
transition: "{{ (var_speed / 1000)|float }}" | |
- delay: | |
milliseconds: !input speed | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
hs_color: | |
- >- | |
{% if state_attr(var_light, "hs_color")[0] - 18 < 0 %} | |
{{ state_attr(var_light, "hs_color")[0] - 18 + 360 }} | |
{% else %} | |
{{ state_attr(var_light, "hs_color")[0] - 18 }} | |
{% endif %} | |
- '{{ state_attr(var_light, "hs_color")[1] }}' | |
# 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 | |
target: | |
entity_id: !input light | |
data: | |
hs_color: | |
- >- | |
{% if state_attr(var_light, "hs_color")[0] - 18 < 0 %} | |
{{ state_attr(var_light, "hs_color")[0] - 18 + 360 }} | |
{% else %} | |
{{ state_attr(var_light, "hs_color")[0] - 18 }} | |
{% endif %} | |
- '{{ state_attr(var_light, "hs_color")[1] }}' | |
transition: "{{ (var_speed / 1000)|float }}" | |
- delay: | |
milliseconds: !input speed | |
# Any other event will cancel the repeat loops. | |
default: [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment