Thanks @JetSerge , I love this blueprint. If double press could be implemented it would be perfect. I have tried some other ones for RWL022 and Zigbee2MQTT but double pressing does not work. somebody could help me? I need the double press please.
@JetSerge love your blueprint!
Just figured that something in z2m or HA must have changed with the recent updates.
My actions for up_hold_once and down_hold_once didn’t work anymore.
Everything else kept working like a charm.
Figured out that the helper field becomes “unknown” in between the real states.
So the following code needed to be changed to don’t let the helper field take status “unknown”:
condition:
- condition: template
value_template: '{{ trigger.event.data.new_state.state not in ("", "None", "unknown") }}'
After adding “unknown” to the exclusion list the up_hold_once und down_hold_once actions are working again
Maybe you want to add that to your great blueprint to keep it working?
If you’re already at it, this
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ command }}'
should better become something like this
- action: input_text.set_value
metadata: {}
data:
value: '{{ command }}'
target:
entity_id: !input helper_last_controller_event
according to the new best practice I guess.
Thanks for the fix. I didn’t test it myself yet, but I updated the blueprint gist.
As for the new syntax keywords, I’ll wait for some time before updating it to maintain compatibility with the older HA versions.
Thanks for the template! It didn’t work until I replaced underscores with hypens in the dimmer actions.
e.g. {{ command == “on_press” }} becomes {{ command == “on-press” }}
I recently moved from ZHA to Zigbee2QTT so it may be a config issue on my side?
Edit: I realise that I’m using a V1 dimmer (324131137411), not V2 which might be the reason.
Hey @JetSerge,
with zigbee2mqtt 2.0 the support for Home Assistant legacy triggers will be removed.
Just tried to disable Home Assistant legacy triggers in z2m and all switches based on this blueprint stopped working.
Instead MQTT device trigger should be used.
Any chance, you will update your great blueprint to keep it working with z2m 2.0?
Regarding this post z2m 2.0 is expected to be released the 3rd January 2025.
I’ve updated the blueprint to listen on a MQTT topic. Now you have to insert the topic as a parameter:
blueprint:
name: Philips Hue Dimmer switch v2 (Zigbee2MQTT)
description:
"Tested with Philips Hue Smart Wireless Dimmer Switch V2 (929002398602).
\n\n To have different actions on short press and on hold (long press), use 'button
release' (`*_press_release`) and 'button hold once' (`*_hold_once`) commands,
as 'press' (`*_press`) will always trigger before 'button hold' (`*_hold`). \n\n
When you hold a button, 'button hold' (`*_hold`) command is repeated roughly once
per second. This may not work as desired with actions like toggling light/switch.
If you want an action to run only once when the button hold action is registered,
use 'button hold once' (`*_hold_once`). It's better than using 'button hold release'
as the result can be observed before releasing the button after holding. \n\n
As 'button hold' action is repeated by the device while you keep holding the button,
it's a good way to run actions which increment / decrement some value (such as
light dimming). To make it react as soon as the button is pressed, copy the same
action to 'button press' (press action occurs immediately, while hold action occurs
after a delay). \n\n Make sure to manually create a separate Text Helper per dimmer
device and define its entity in the automation. It's used to store the last controller
event to filter possible empty events and handle 'button hold once' actions. "
domain: automation
input:
mqtt_topic:
name: MQTT Topic
description: Topic of the Philips Hue Motion
default: zigbee2mqtt/<device name>
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description:
Input Text used to store the last event fired by the controller.
You will need to manually create a text input Helper entity for this.
default: ""
selector:
entity:
domain:
- input_text
multiple: false
on_press:
name: ON button press
description: Action to run
default: []
selector:
action: {}
on_press_release:
name: ON button release
description: Action to run
default: []
selector:
action: {}
on_hold:
name: ON button hold
description: Action to run (repeat while holding)
default: []
selector:
action: {}
on_hold_once:
name: ON button hold once
description: Action to run only once (no repeat)
default: []
selector:
action: {}
on_hold_release:
name: ON button hold release
description: Action to run
default: []
selector:
action: {}
up_press:
name: UP button press
description: Action to run
default: []
selector:
action: {}
up_press_release:
name: UP button release
description: Action to run
default: []
selector:
action: {}
up_hold:
name: UP button hold
description: Action to run (repeat while holding)
default: []
selector:
action: {}
up_hold_once:
name: UP button hold once
description: Action to run only once (no repeat)
default: []
selector:
action: {}
up_hold_release:
name: UP button hold release
description: Action to run
default: []
selector:
action: {}
down_press:
name: DOWN button press
description: Action to run
default: []
selector:
action: {}
down_press_release:
name: DOWN button release
description: Action to run
default: []
selector:
action: {}
down_hold:
name: DOWN button hold
description: Action to run (repeat while holding)
default: []
selector:
action: {}
down_hold_once:
name: DOWN button hold once
description: Action to run only once (no repeat)
default: []
selector:
action: {}
down_hold_release:
name: DOWN button hold release
description: Action to run
default: []
selector:
action: {}
off_press:
name: OFF/HUE button press
description: Action to run
default: []
selector:
action: {}
off_press_release:
name: OFF/HUE button release
description: Action to run
default: []
selector:
action: {}
off_hold:
name: OFF/HUE button hold
description: Action to run (repeat while holding)
default: []
selector:
action: {}
off_hold_once:
name: OFF/HUE button hold once
description: Action to run only once (no repeat)
default: []
selector:
action: {}
off_hold_release:
name: OFF/HUE button hold release
description: Action to run
default: []
selector:
action: {}
source_url: https://gist.github.com/CrazyCoder/28d660d9e2e8464458e591ad79b3698e
mode: restart
max_exceeded: silent
trigger:
- platform: mqtt
topic: !input mqtt_topic
condition:
- condition: template
value_template: "{{ trigger.payload_json.action != '' }}"
action:
- variables:
helper_last_controller_event: !input helper_last_controller_event
command: "{{ trigger.payload_json.action }}"
prev_command: "{{ states(helper_last_controller_event) }}"
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: "{{ command }}"
- choose:
- conditions:
- '{{ command == "on_press" }}'
sequence: !input on_press
- conditions:
- '{{ command == "on_press_release" }}'
sequence: !input on_press_release
- conditions:
- '{{ command == "on_hold" }}'
sequence: !input on_hold
- conditions:
- '{{ command == "on_hold_release" }}'
sequence: !input on_hold_release
- conditions:
- '{{ command == "up_press" }}'
sequence: !input up_press
- conditions:
- '{{ command == "up_press_release" }}'
sequence: !input up_press_release
- conditions:
- '{{ command == "up_hold" }}'
sequence: !input up_hold
- conditions:
- '{{ command == "up_hold_release" }}'
sequence: !input up_hold_release
- conditions:
- '{{ command == "down_press" }}'
sequence: !input down_press
- conditions:
- '{{ command == "down_press_release" }}'
sequence: !input down_press_release
- conditions:
- '{{ command == "down_hold" }}'
sequence: !input down_hold
- conditions:
- '{{ command == "down_hold_release" }}'
sequence: !input down_hold_release
- conditions:
- '{{ command == "off_press" }}'
sequence: !input off_press
- conditions:
- '{{ command == "off_press_release" }}'
sequence: !input off_press_release
- conditions:
- '{{ command == "off_hold" }}'
sequence: !input off_hold
- conditions:
- '{{ command == "off_hold_release" }}'
sequence: !input off_hold_release
- choose:
- conditions:
- '{{ command == "on_hold" and prev_command == "on_press" }}'
sequence: !input on_hold_once
- conditions:
- '{{ command == "up_hold" and prev_command == "up_press" }}'
sequence: !input up_hold_once
- conditions:
- '{{ command == "down_hold" and prev_command == "down_press" }}'
sequence: !input down_hold_once
- conditions:
- '{{ command == "off_hold" and prev_command == "off_press" }}'
sequence: !input off_hold_once
if you enable the Z2M experimental features before 2.0.0
gets rolled out, it will be very simple to modify the blueprint:
- Change the trigger to listen, to event of the dimmer. Z2M will expose
event.dimmer_name_action
entity that we can assign to. - Rework the
command
variable to allow keeping original blueprint figures. Use the<button_name>_<event_type>
from the attributes.
description: ""
triggers:
- trigger: state
entity_id:
- event.hue_dimmer_action
attribute: event_type
conditions: []
actions:
- variables:
command: >-
{{ trigger.to_state.attributes.button }}_{{
trigger.to_state.attributes.event_type }}
mode: single
thx, working like a charme here with 24x hue dimmer switches and set homeassistant_legacy_triggers: false
.
Will migrate over my 24x hue dimmer switches to your blueprint.
So Z2M 2.0.0 can come for me…
P.S.: Also my feelings are like yours, the reaction is slightly faster.
thx a lot.
Thank you for your contribution. I’ll make sure to update the blueprint before Z2M 2.0 release. I’m a bit hesitant to do so right now as I have several different third-party blueprints that will likely break, so it would take quite some time updating them all.
@JetSerge if you use my proposed approach (with MQTT topic), then it will work already with < 1.42 Z2M version. You should be able to test it immediately. The event type from within Z2M will come after 2.0.0
, but I think we shall wait for Z2M to become stable in the event aspect, since there is a warning that somethings may change.
MQTT topic approach is being used with the Hue Tap switch since a while. I use one Blueprint from the link below:
Hi @tilz0R
Like you, I use this blueprint or the automation Zigbee2MQTT - Philips Hue Tap Dial Switch by SmartHomeGeeks.io
and would also like to adapt its MQTT section for the Dimmer Switch, as you suggested.
However, already in tap dial automation I come across warning messages in the HA log after a restart when I deactivate (in preparation for zigbee2mqtt 2.0) the homeassistant legacy_triggers in z2m. For example:
Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ trigger.payload_json.action is match('^button_[1-4]_press$') }}'
Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ trigger.payload_json.action is match('button_[1-4]_press_release') and states(counter_var) > '1' }}'
Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ trigger.payload_json.action is match('button_[1-4]_press_release') }}'
Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ states(input_text_var) == '3' and trigger.payload_json.action is match('^dial_rotate_') }}'
It affects all template lines that contain trigger.payload_json.action
This is my configuration for z2m:
homeassistant:
experimental_event_entities: true
advanced:
homeassistant_legacy_entity_attributes: false
legacy_api: false
legacy_availability_payload: false
homeassistant_legacy_triggers: false
And when I press the hue tap switch, I get the payload data (as seen in the automation, payload part of the trigger
variable):
{
"action":"button_3_press_release",
"action_direction":null,
"action_step_size":null,
"action_time":null,
"action_type":null,
"battery":100,
"brightness":null,
"linkquality":142,
"update":{
"installed_version":33569561,
"latest_version":33569561,
"state":"idle"
},
"update_available":null
}
And when I try the same for dimmer, I get:
{
"action":"off_press_release",
"battery":100,
"linkquality":156,
"update": {
"installed_version":33565954,
"latest_version":33565954,
"state":"idle"
},
"update_available":null
}
In both cases I see the action
.
Z2M version 1.42.0
Thank you for your answer. I think I have to describe it a little more precisely, because the automations work. So when I press a button, action
is also published.
The warning messages in the HA Log only appear after a restart or full restart of HA. Probably because during the evaluation of the automations, the zigbee device (Tap Dial or dimmer) has not yet sent a topic, or zigbee2mqtt is not yet fully loaded at this time. Maybe something needs to be added to the templates to prevent this?
I have the same zigbee2mqtt configuration as you, except for the experimental event entities.
OK, now it makes more sense.
The blueprint condition would need to be changed, to something like below (not tested in reality):
condition:
- condition: template
value_template: "{{ 'action' in trigger.payload_json and trigger.payload_json.action != '' }}"
Check shall be done verifying that action
key exists, before its value is validated.
Thank you for your support. Unfortunately, I won’t be able to try it out for a few days. I’ll come back and report if it works.
Edit: @tilz0R
I was able to test it and it looks very good. I did several reboots and also a full reboot:
No more warnings appear in the log! Thank you very much for your support and have a nice weekend.
Thank you for your solution. Has anybody gotten a blueprint that works with the event entity instead though? I am hoping to not create additional event helper entities if it’s not necessary.
The event entity will be available in HA from the Z2M, but only in the version Z2M v2.0.0 or if you enable the preview features of Z2M.
Hey @tilz0R do you have a working blueprint you could share that works with the dimmer V2 and uses the experimental events?
You can take the original blueprint, use the take over feature and then modify it.
Thanks, I only use very basic functionality and I’ve just managed to port what I need over into an automation.
I just use the press/release for each of the 4 buttons but the code could be modified for other things.
It’s a trigger off the event and then a 4-way conditional action based on the button pressed.