Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nao-pon/5ed67440f45feb88db98e501e52ab691 to your computer and use it in GitHub Desktop.
Save nao-pon/5ed67440f45feb88db98e501e52ab691 to your computer and use it in GitHub Desktop.
ZHA Tradfri on/off button complex with input button helper
blueprint:
name: ZHA - IKEA Tradfri on/off switch complex with input button helper
description: '"Control your light(s) with IKEA Tradfri on/off switch
Select the Tradfri remote and your lights.
You can turn the lights On / Off, or hold the buttons to dim the lights.
The Delay and Speed are configurable.
And On / Off can be used for other automation in conjunction with each input button helper."
'
domain: automation
input:
remote:
name: Remote
description: The remote that will control the lights
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
multiple: false
light:
name: Light
description: The lights that will be controlled
selector:
target:
entity:
domain: light
step_size:
name: Step Size
description: The % step each dimming step takes
default: 10
selector:
number:
min: 5.0
max: 25.0
unit_of_measurement: '%'
mode: slider
step: 1.0
step_delay:
name: Step Delay
description: The time between dimming steps (ms)
default: 1000
selector:
number:
min: 100.0
max: 2000.0
unit_of_measurement: milliseconds
mode: slider
step: 1.0
forced_brightness:
name: Forced Brightness
default: false
selector:
boolean: {}
brightness_day_level:
name: Brightness level (Day)
description: Force the light to this brightness (when enabled)
default: 75
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: '%'
mode: slider
step: 1.0
use_night_brightness:
name: Different brightness at night
default: false
selector:
boolean: {}
brightness_night_level:
name: Brightness level (Night)
description: Force the light to this brightness at night (when enabled)
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: '%'
mode: slider
step: 1.0
night_time_start:
name: Night Start Time
selector:
time: {}
night_time_end:
name: Night End time
selector:
time: {}
button_on:
name: Input Button On
description: Input Button helper entity for On
selector:
target:
entity:
domain: input_button
button_off:
name: Input Button Off
description: Input Button helper entity for Off
selector:
target:
entity:
domain: input_button
source_url: https://gist.github.com/nao-pon/5ed67440f45feb88db98e501e52ab691
mode: restart
variables:
step_size: !input step_size
forced_brightness: !input forced_brightness
use_night_brightness: !input use_night_brightness
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- variables:
command: '{{ trigger.event.data.command }}'
cluster_id: '{{ trigger.event.data.cluster_id }}'
endpoint_id: '{{ trigger.event.data.endpoint_id }}'
- choose:
- conditions:
- '{{ command == ''on'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence:
- choose:
- conditions:
- '{{ use_night_brightness }}'
- condition: time
before: !input night_time_end
after: !input night_time_start
sequence:
- service: light.turn_on
target: !input light
data:
brightness_pct: !input brightness_night_level
transition: 1
- conditions: '{{ force_brightness_day }}'
sequence:
- service: light.turn_on
target: !input light
data:
brightness_pct: !input brightness_day_level
transition: 1
default:
- service: light.turn_on
target: !input light
data:
transition: 1
- service: input_button.press
target: !input button_on
- conditions:
- '{{ command == ''off'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence:
- service: light.turn_off
target: !input light
data:
transition: 1
- service: input_button.press
target: !input button_off
- conditions:
- '{{ command == ''move_with_on_off'' }}'
- '{{ cluster_id == 8 }}'
- '{{ endpoint_id == 1 }}'
sequence:
repeat:
while:
- condition: template
value_template: '{{ repeat.index < (100 / step_size)|int }}'
sequence:
- service: light.turn_on
target: !input light
data:
transition: 1
brightness_step_pct: !input step_size
- delay:
milliseconds: !input step_delay
- conditions:
- '{{ command == ''move'' }}'
- '{{ cluster_id == 8 }}'
- '{{ endpoint_id == 1 }}'
sequence:
repeat:
while:
- condition: template
value_template: '{{ repeat.index < (100 / step_size)|int }}'
sequence:
- service: light.turn_on
target: !input light
data:
transition: 1
brightness_step_pct: '{{ step_size * -1 }}'
- delay:
milliseconds: !input step_delay
- conditions:
- '{{ command == ''stop'' }}'
- '{{ cluster_id == 8 }}'
- '{{ endpoint_id == 1 }}'
sequence:
- service: light.turn_on
target: !input light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment