Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shannon/ec2785e67badde18eacfc4f88b959534 to your computer and use it in GitHub Desktop.

Select an option

Save shannon/ec2785e67badde18eacfc4f88b959534 to your computer and use it in GitHub Desktop.
Home Assistant - Blueprint - IKEA TRADFRI 5 Button Remote
---
# This automation simulates the use of the IKEA TRADFRI Remote control
# connected through ZHA.
# | Button | Action |
# | -------- | ------------------- |
# | Power | Toggle the light |
# | Dim-Up | Increase brightness |
# | Dim-Down | Decrease brightness |
# | Right | Increate color temp |
# | Left | Decrease color temp |
blueprint:
name: IKEA TRADFRI 5 Button Remote with brightness and color temp
description: >-
This automation simulates the use of the IKEA TRADFRI Remote control
connected through ZHA.
domain: automation
input:
control_device:
name: Control
description: The control to use for controling the lights.
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI remote control
light_target:
name: Lights
description: The lights to control.
selector:
target:
entity:
domain: light
default: null
switch_target:
name: Switches
description: The switches to flip (power toggle only)
selector:
target:
entity:
domain: switch
light_step:
name: "Step the lights this much (%)"
default: 5
selector:
number:
min: 1
max: 25
step: 1
light_delay_ms:
name: "Step the lights this often (ms)"
default: 300
selector:
number:
min: 100
max: 5000
step: 50
mode: restart
max_exceeded: silent
variables:
var_control_device: !input control_device
var_light_target: !input light_target
var_switch_target: !input switch_target
var_light_step: !input light_step
var_light_delay_ms: !input light_delay_ms
trigger:
- platform: event
event_type: zha_event
condition:
- condition: template
value_template: "{{ trigger.event.data.device_id == var_control_device }}"
action:
- choose:
# Short-Press on the power button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "toggle" }}'
sequence:
- service: light.toggle
target: !input light_target
- service: switch.toggle
target: !input switch_target
# 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: !input light_target
data_template:
brightness: 254
# 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: !input light_target
data_template:
brightness_step_pct: '{{var_light_step}}'
transition: '{{(var_light_delay_ms|int)/1000}}'
# Short-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "step" }}'
sequence:
- service: light.turn_on
target: !input light_target
data_template:
brightness_step_pct: '-{{var_light_step}}'
transition: '{{(var_light_delay_ms|int)/1000}}'
# 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: !input light_target
data_template:
brightness_step_pct: '{{var_light_step}}'
transition: '{{(var_light_delay_ms|int)/1000}}'
- delay:
milliseconds: '{{var_light_delay_ms}}'
# 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: !input light_target
data_template:
brightness_step_pct: '-{{var_light_step}}'
transition: '{{(var_light_delay_ms|int)/1000}}'
- delay:
milliseconds: '{{var_light_delay_ms}}'
# 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: !input light_target
data_template:
color_temp: >-
{% set current_temp = state_attr((var_light_target.entity_id | first), "color_temp") %}
{% set max_temp = state_attr((var_light_target.entity_id | first), "max_mireds") %}
{% if current_temp < 153 %}
{{[153, max_temp]|min}}
{% elif current_temp < 166 %}
{{[166, max_temp]|min}}
{% elif current_temp < 200 %}
{{[200, max_temp]|min}}
{% elif current_temp < 240 %}
{{[240, max_temp]|min}}
{% elif current_temp < 333 %}
{{[333, max_temp]|min}}
{% elif current_temp < 370 %}
{{[370, max_temp]|min}}
{% elif current_temp < 500 %}
{{[500, max_temp]|min}}
{% else %}
{{max_temp}}}
{% endif %}
transition: '{{(var_light_delay_ms|int)/1000}}'
# 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: !input light_target
data_template:
color_temp: >-
{% set current_temp = state_attr((var_light_target.entity_id | first), "color_temp") %}
{% set min_temp = state_attr((var_light_target.entity_id | first), "min_mireds") %}
{% if current_temp > 500 %}
{{[500, min_temp]|max}}
{% elif current_temp > 370 %}
{{[370, min_temp]|max}}
{% elif current_temp > 333 %}
{{[333, min_temp]|max}}
{% elif current_temp > 240 %}
{{[240, min_temp]|max}}
{% elif current_temp > 200 %}
{{[200, min_temp]|max}}
{% elif current_temp > 166 %}
{{[166, min_temp]|max}}
{% elif current_temp > 153 %}
{{[153, min_temp]|max}}
{% else %}
{{min_temp}}
{% endif %}
transition: '{{(var_light_delay_ms|int)/1000}}'
# 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: !input light_target
data_template:
color_temp: >-
{% set current_temp = state_attr((var_light_target.entity_id | first), "color_temp") %}
{% set min_temp = state_attr((var_light_target.entity_id | first), "min_mireds") | int %}
{% set max_temp = state_attr((var_light_target.entity_id | first), "max_mireds") | int %}
{% set color_step = var_light_step * ((max_temp - min_temp)/100) %}
{{[current_temp + color_step, max_temp] | min}}
transition: '{{(var_light_delay_ms|int)/1000}}'
- delay:
milliseconds: '{{var_light_delay_ms}}'
# 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: !input light_target
data_template:
color_temp: >-
{% set current_temp = state_attr((var_light_target.entity_id | first), "color_temp") %}
{% set min_temp = state_attr((var_light_target.entity_id | first), "min_mireds") %}
{% set max_temp = state_attr((var_light_target.entity_id | first), "max_mireds") %}
{% set color_step = var_light_step * ((max_temp - min_temp)/100) %}
{{[current_temp - color_step, min_temp]|max}}
transition: '{{(var_light_delay_ms|int)/1000}}'
- delay:
milliseconds: '{{var_light_delay_ms}}'
# Any other event will cancel the repeat loops.
default: []
# color temps
# 153 - snow
# 166 - ivory
# 200 - daylight
# 240 - cool white
# 333 - warm white
# 370 - incandescent
# 500 - candlelight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment