Skip to content

Instantly share code, notes, and snippets.

@niro1987
Last active February 7, 2023 08:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save niro1987/4e49117075cd4b66975e0ecfe3ad72b5 to your computer and use it in GitHub Desktop.
Save niro1987/4e49117075cd4b66975e0ecfe3ad72b5 to your computer and use it in GitHub Desktop.
Home Assistant - Blueprint - ZHA - IKEA TRADFRI - 2 Button Remote - OnOff and Brightness
---
# This automation simulates the use of the IKEA TRADFRI Dimmer control
# connected through ZHA.
# | Button | Action |
# | ----------- | ------------------- |
# | on (short) | Turn the light on |
# | off (short) | Turn the light off |
# | on (long) | Increase brightness |
# | off (long) | Decrease brightness |
blueprint:
source_url: https://github.com/niro1987/homeassistant-config/blob/main/blueprints/automation/niro1987/zha_ikea_tradfri_2button_remote_brightness.yaml
name: ZHA - IKEA TRADFRI - 2 Button Remote - OnOff and Brightness
description: >-
This automation simulates the use of the IKEA TRADFRI on/off switch
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 on/off switch
light:
name: Light
description: Select the light entity you wish to control.
selector:
entity:
domain: light
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- choose:
# Short-Press the on button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
sequence:
- service: light.turn_on
target:
entity_id: !input light
data:
brightness: 254
hs_color:
- 38.222
- 52.941
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
target:
entity_id: !input light
data:
brightness_step_pct: 10
transition: 0.5
- delay:
milliseconds: 500
# Short-Press the off button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "off" }}'
sequence:
- service: light.turn_off
target:
entity_id: !input light
data:
transition: 1
# Long-Press the off 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: 0.5
- delay:
milliseconds: 500
# Any other event will cancel the repeat loops (i.e. releasing the [on|off] button)
default: []
@al13nus
Copy link

al13nus commented Nov 12, 2022

I combined your 2 button script and motion sensor and getting funny behaviour: so if he tells every time automation is triggered without buttons, that Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'event'. BUT if you click on a button, then he finds event data and everything is fine. At the end everything works anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment