Skip to content

Instantly share code, notes, and snippets.

@oscarb
Last active January 2, 2024 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarb/1e295b636d27559aa6c4d45c9ccd24ae to your computer and use it in GitHub Desktop.
Save oscarb/1e295b636d27559aa6c4d45c9ccd24ae to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: IKEA E1743 Trådfri on/off switch (ZHA)
blueprint:
name: IKEA E1743 Trådfri on/off switch (ZHA)
description: Dim or turn on/off a light using the IKEA Trådfri E1743 switch remote. Works with ZHA.
author: oscarb
domain: automation
input:
light:
name: Light
description: Entiy ID of light to control
selector:
entity:
filter:
domain: light
multiple: false
remote:
name: Trådfri on/off switch
description: The IKEA Trådfri on/off switch remote to use
selector:
device:
filter:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
multiple: false
fade_speed:
name: Fade speed
description: The speed used for dimming the light )brightness steps per second)
default: 80
selector:
number:
min: 1
max: 255
unit_of_measurement: brightness steps/second
default_brightness:
name: Default brightness
description: The brightness to set when turning on the light
default: 128
selector:
number:
min: 1
max: 255
mode: restart
max_exceeded: silent
variables:
input_light: !input light
fade_speed: !input fade_speed
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- choose:
- conditions: "{{ trigger.event.data.command == 'on' }}"
sequence:
- service: light.turn_on
entity_id: !input light
data:
brightness: !input default_brightness
- conditions: "{{ trigger.event.data.command == 'off' }}"
sequence:
- service: light.turn_off
entity_id: !input light
- conditions: "{{ trigger.event.data.command in ['move', 'move_with_on_off'] }}"
sequence:
- alias: Set up variables
variables:
brightness_from: "{{ state_attr(input_light, 'brightness') | int(0) }}"
brightness_target: "{{ 0 if trigger.event.data.command == 'move' else 255 }}"
brightness_delta: "{{ (brightness_target - brightness_from) | abs }}"
brightness_direction: "{{ -1 if trigger.event.data.command == 'move' else 1 }}"
transition_time: "{{ brightness_delta / fade_speed }}"
- service: light.turn_on
entity_id: !input light
data:
transition: "{{ transition_time }}"
brightness: "{{ brightness_target }}"
- wait_for_trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
command: stop_with_on_off
timeout: "{{ transition_time }}"
continue_on_timeout: false
- alias: Estimate current brightness
variables:
brightness_current: >
{{ brightness_from +
brightness_direction * fade_speed * (wait.trigger.event.time_fired - trigger.event.time_fired).total_seconds()
}}
- service: light.turn_on
entity_id: !input light
data:
brightness: "{{ brightness_current }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment