Skip to content

Instantly share code, notes, and snippets.

@jongdesteven
Last active March 22, 2024 20:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save jongdesteven/e267f19575cafbe5fc0d756612717a63 to your computer and use it in GitHub Desktop.
Save jongdesteven/e267f19575cafbe5fc0d756612717a63 to your computer and use it in GitHub Desktop.
ZHA Tradfri on/off button complex
blueprint:
name: ZHA - IKEA Tradfri on/off switch complex
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"
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'
- integration: zha
manufacturer: 'IKEA of Sweden'
model: 'RODRET Dimmer'
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
max: 25
unit_of_measurement: '%'
step_delay:
name: Step Delay
description: The time between dimming steps (ms)
default: 1000
selector:
number:
min: 100
max: 2000
unit_of_measurement: 'milliseconds'
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
max: 100
unit_of_measurement: '%'
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
max: 100
unit_of_measurement: "%"
night_time_start:
name: Night Start Time
selector:
time:
night_time_end:
name: Night End time
selector:
time:
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
- conditions:
- "{{ command == 'off' }}"
- "{{ cluster_id == 6 }}"
- "{{ endpoint_id == 1 }}"
sequence:
- service: light.turn_off
target: !input 'light'
data:
transition: 1
- 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