Skip to content

Instantly share code, notes, and snippets.

@reven
Last active November 29, 2020 07:05
Show Gist options
  • Save reven/873652a0b1e47c2ae09f1177e8f522ea to your computer and use it in GitHub Desktop.
Save reven/873652a0b1e47c2ae09f1177e8f522ea to your computer and use it in GitHub Desktop.
Home Assistant - Dimming a light while holding down a button
---
#
# This automation simulates the use of the IKEA TRADFRI Wireless dimmer
# connected through zha but should also work for other type of events.
# Requires Home Assistant 0.113 or higher.
#
id: 'living_room-ikea_dimmer'
alias: IKEA Dimmer - Living Room
description: ''
mode: restart
trigger:
- platform: event
event_type: zha_event
event_data:
# Change this to your own device_ieee (lookup on the device page)
device_ieee: 00:0d:6f:ff:fe:a0:54:37
condition: []
action:
- choose:
# Short-Press the on button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room
brightness: 254
hs_color:
- 38.222
- 52.941
transition: 1
# Short-Press the off button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "off" }}'
sequence:
- service: light.turn_off
data_template:
entity_id: light.living_room
transition: 1
# Long-Press the on 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 the off 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 (i.e. releasing the [on|off] button)
default: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment