Last active
May 24, 2022 13:14
-
-
Save WarriorRocker/f6a44fe4d69dcc2edec605fe67d03378 to your computer and use it in GitHub Desktop.
ZHA - Philips Hue Dimmer Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: ZHA - Philips Hue Dimmer Switch | |
description: | | |
Control lights with a Philips Hue Dimmer Switch. | |
The top "on" button behaviour is adjustable. By default it behaves like this: | |
- Press it while the light is off, and the light will turn on to the last set brightness. | |
- Press it again while the light is on, the light will turn to the fixed brightness setting. | |
Dim up/down buttons will change the brightness smoothly and can be pressed | |
and hold until the brightness is satisfactory. | |
The bottom "off" button will turn the light off. | |
The "on" and "off" buttons can be assigned to an action when double | |
or triple pressed. This allows you to assign e.g. a scene or something else. | |
The minimum brightness setting will limit how low you can set the brightness. This will | |
prevent dimming down until the light turns off. Set this to zero to disable this feature. | |
domain: automation | |
source_url: https://gist.github.com/WarriorRocker/f6a44fe4d69dcc2edec605fe67d03378 | |
# Define the inputs for the blueprint | |
input: | |
remote: | |
name: Philips Hue Dimmer Switch | |
description: Pick either RWL020 (US) or RWL021 (EU) | |
selector: | |
device: | |
integration: zha | |
manufacturer: Philips | |
entity: | |
domain: sensor | |
device_class: battery | |
light: | |
name: Light(s) | |
description: > | |
The light entity to control | |
(only a single entity is supported; use light groups when needed) | |
selector: | |
entity: | |
domain: light | |
force_brightness: | |
name: Force turn on brightness | |
description: 'Force the brightness to the set level below, when the "on" button | |
on the remote is pushed and lights turn on.' | |
default: false | |
selector: | |
boolean: {} | |
brightness: | |
name: Brightness | |
description: Brightness of the light(s) when turning on | |
default: 255 | |
selector: | |
number: | |
min: 0 | |
max: 255 | |
mode: slider | |
step: 1 | |
min_brightness: | |
name: Min Brightness | |
description: Minimum brightness of the light(s) when dimming | |
default: 0 | |
selector: | |
number: | |
min: 0 | |
max: 255 | |
mode: slider | |
step: 1 | |
mode: restart | |
max_exceeded: silent | |
# Trigger the automation when the selected dimmer remote sends an event | |
# Also only trigger on cluster_id 64512. This ignores the 'old' events with cluster_id 8. | |
trigger: | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input 'remote' | |
cluster_id: 64512 | |
variables: | |
light: !input 'light' | |
force_brightness: !input 'force_brightness' | |
brightness: !input 'brightness' | |
min_brightness: !input 'min_brightness' | |
action: | |
- variables: | |
command: '{{ trigger.event.data.command }}' | |
cur_brightness: '{{ state_attr(light, ''brightness'') | int }}' | |
- choose: | |
- conditions: '{{ command == ''on_press'' }}' | |
sequence: | |
- choose: | |
- conditions: '{{ force_brightness }}' | |
sequence: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
brightness: !input 'brightness' | |
default: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
- conditions: '{{ command == ''off_press'' }}' | |
sequence: | |
- service: light.turn_off | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
- conditions: '{{ command == ''up_press'' }}' | |
sequence: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
brightness_step: 25 | |
transition: 1 | |
- conditions: '{{ command == ''up_hold'' }}' | |
sequence: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
brightness_step: 50 | |
transition: 1 | |
- conditions: '{{ command == ''down_press'' }}' | |
sequence: | |
- choose: | |
- conditions: '{{ (cur_brightness - 25) >= min_brightness }}' | |
sequence: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
brightness_step: -25 | |
default: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
brightness: !input 'min_brightness' | |
- conditions: '{{ command == ''down_hold'' }}' | |
sequence: | |
- choose: | |
- conditions: '{{ (cur_brightness - 50) >= min_brightness }}' | |
sequence: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
brightness_step: -50 | |
default: | |
- service: light.turn_on | |
data: | |
entity_id: !input 'light' | |
transition: 1 | |
brightness: !input 'min_brightness' |
This is true, for the sake of lights controlled by a remote I generally create a light group and reference the light group entity with the remote blueprint. In this way HA holds the current brightness value even if one of the lights is unreachable.
Updated for V2 ZHA commands per @ https://gist.github.com/stefanroelofs/775e2e0a3cdb3d72a9451fb247492d59
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Great blueprint, thanks.
It fails however when you try to target more than 1 light entity.
I think on line 89 where you get the current brightness of the light?