Skip to content

Instantly share code, notes, and snippets.

@jeromecornet
Last active February 4, 2024 16:59
Show Gist options
  • Select an option

  • Save jeromecornet/c055a4cc1214e77e0d9bdc3800612cb1 to your computer and use it in GitHub Desktop.

Select an option

Save jeromecornet/c055a4cc1214e77e0d9bdc3800612cb1 to your computer and use it in GitHub Desktop.
---
# This automation simulates the use of the IKEA TRADFRI Remote control
# connected through ZHA.
blueprint:
source_url: https://github.com/niro1987/homeassistant-config/blob/main/blueprints/automation/niro1987/zha_ikea_tradfri_styrbar_custompreset.yaml
name: ZHA - IKEA TRADFRI - STYRBAR - Custom Preset with color cycling and night light
description: >-
This automation simulates the use of the IKEA TRADFRI STYRBAR 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:
filter:
- integration: zha
manufacturer: IKEA of Sweden
model: Remote Control N2
light:
name: Light
description: Select the light entity you wish to control.
selector:
entity:
filter:
- 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
preset_long:
name: Helper for long press
description: Select the helper entity with you pre defined settings.
selector:
entity:
filter:
- domain: input_select
preset:
name: Helper for short press
description: Select the helper entity with you pre defined settings.
selector:
entity:
filter:
- domain: input_select
mode: restart
max_exceeded: silent
variables:
var_preset: !input preset
var_preset_long: !input preset_long
var_speed: !input speed
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
# Select the last option of the preset if it is unknown.
- choose:
- conditions:
- condition: state
entity_id: !input preset
state: "unknown"
sequence:
- service: input_select.select_last
target:
entity_id: !input preset
- choose:
# Short-Press on the dim-up button during the day
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
- condition: state
entity_id: !input light
state: "off"
- condition: state
entity_id: sun.sun
state: above_horizon
sequence:
- service: light.turn_on
target:
entity_id: !input light
data:
color_temp_kelvin: 6500
brightness: 255
transition: "{{ (var_speed / 1000)|float }}"
- choose:
# Short-Press on the dim-up button at night
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
- condition: state
entity_id: !input light
state: "off"
- condition: state
entity_id: sun.sun
state: below_horizon
sequence:
- service: light.turn_on
target:
entity_id: !input light
data:
color_temp_kelvin: 2700
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 / 3000)|float }}"
- delay:
milliseconds: !input speed
# Short-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "off" }}'
sequence:
- service: light.turn_off
target:
entity_id: !input light
data:
transition: "{{ (var_speed / 1000)|float }}"
# Long-Press on the dim-down button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move" }}'
- condition: numeric_state
entity_id: !input light
attribute: brightness
above: 30
sequence:
- repeat:
while: []
sequence:
- service: light.turn_on
target:
entity_id: !input light
data:
brightness_step_pct: -10
transition: "{{ (var_speed / 3000)|float }}"
- delay:
milliseconds: !input speed
# Short-Press on the right button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "press" }}'
- condition: template
value_template: "{{ trigger.event.data.args == [256,13,0] }}"
sequence:
- service: input_select.select_next
target:
entity_id: !input preset
data:
cycle: true
- service: light.turn_on
target:
entity_id: !input light
data:
color_temp_kelvin: "{{ states(var_preset) }}"
brightness: "{{ (states(var_preset))| float / 26.0 }}"
# Long-Press on the right 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: input_select.select_next
target:
entity_id: !input preset_long
data:
cycle: true
- service: light.turn_on
target:
entity_id: !input light
data:
hs_color: "{{ states(var_preset_long) }}"
- delay:
milliseconds: !input speed
# Short-Press on the left button.
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "press" }}'
- condition: template
value_template: "{{ trigger.event.data.args == [257,13,0] }}"
sequence:
- service: input_select.select_previous
target:
entity_id: !input preset
data:
cycle: true
- service: light.turn_on
target:
entity_id: !input light
data:
color_temp_kelvin: "{{ states(var_preset) }}"
brightness: "{{ (states(var_preset))| float / 26.0 }}"
# Long-Press on the left 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: input_select.select_previous
target:
entity_id: !input preset_long
data:
cycle: true
- service: light.turn_on
target:
entity_id: !input light
data:
hs_color: "{{ states(var_preset_long) }}"
- 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