I updated the blueprint with an optional setting to always fire the first button press when you cycle through - with this enabled I think it’s very close to mimicking the original HUE behaviour now
I am new to HA and I installed your blueprint. When I am starting it. I am able to select a device. But I cannot select an entry here: (Required) Helper - Last Controller Event.
As far as I understand, I have to create a manual entry here. Can you please explain me what exactly I have to do here?
Thank you.
Hello !
Yes, you need to create a text input in Settings => Devices & services => Helpers
Name it whatever you want and then select it in the blueprint.
Thank you.
After rereading, I just realized that the Blueprint does not work with Zigbee2MQTT. I use Z2M in combination with a Conbee II stick. Does anyone have a solution for Z2M?
Hi all,
Anyone have a working Zigbee2MQTT script?
@Shivy011 @tobias1337 @JoeP97 @karlc28 @Robson31
do you want to try the below blueprint and let me know how it goes? if it works I’ll update the main blueprint
i think this import button works, make sure it has the new mqtt topic option when you use it:
# Blueprint metadata
blueprint:
name: Controller - Philips Hue Smart Button
description: |
# Controller - Philips Hue Smart button with multiple presses
domain: automation
input:
controller_device:
name: HUE Smart Button Device
description: The button device to use for the automation.
default: ""
selector:
device:
entity:
domain: sensor
device_class: battery
controller_topic:
name: HUE Smart Button Device (Zigbee2MQTT)
description: The MQTT topic to use for the automation (only fill if using Zigbee2MQTT)
default: ""
selector:
text:
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 entity for this, please read the blueprint Additional Notes for more info.
default: ""
selector:
entity:
domain: input_text
# inputs for custom actions
action_button_short_release:
name: (Optional) Short button press release.
description: Action to run on short button press release.
default: []
selector:
action:
action_button_double_press:
name: (Optional) Button double press
description: Action to run on the release of a double button press.
default: []
selector:
action:
action_button_triple_press:
name: (Optional) Button triple press
description: Action to run on the release of a triple button press.
default: []
selector:
action:
action_button_quadruple_press:
name: (Optional) Button quadruple press
description: Action to run on the release of a quadruple button press.
default: []
selector:
action:
action_button_quintuple_press:
name: (Optional) Button quintuple press
description: Action to run on the release of a quintuple button press.
default: []
selector:
action:
action_button_long_repeat:
name: (Optional) Button long hold
description: Action to run on long button hold - this is fired every second the button is held down.
default: []
selector:
action:
action_button_long_release:
name: (Optional) Long button press release
description: Action to run on button release after long press.
default: []
selector:
action:
action_button_initial_press:
name: (Optional) Button initial press
description: Action to run on initial short button press. This is run on every single button press.
default: []
selector:
action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_long_repeat_loop:
name: (Optional) Button long press - loop actions
description: Loop the button action until the button is released (it will be called every second without this).
default: false
selector:
boolean:
button_long_repeat_max_loop_repeats:
name: (Optional) Button long press - Maximum loop repeats
description: >-
Maximum number of repeats for the custom action, when looping is enabled.
Use it as a safety limit to prevent an endless loop in case the corresponding stop event is not received.
default: 500
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
# inputs for enabling double press events
button_multi_press_enabled:
name: (Optional) Enable button multi press events
description: Choose whether or not to enable the virtual multi press events for the button. Turn this on if you are providing actions for the button double/triple/quadruple/quintuple press events.
default: false
selector:
boolean:
# inputs for enabling double press events
button_multi_press_always_fire_first_release:
name: (Optional) Always fire first short button release
description: Choose whether or not to always fire the first short button release action.
default: false
selector:
boolean:
# helpers used to properly recognize the remote button events
helper_multi_press_delay:
name: (Optional) Helper - Multi Press delay
description: Max delay between button presses for multi-press events. Provide a value only if you are using a multi-press action. Increase this value if you notice that the multi-press action is not triggered properly.
default: 1200
selector:
number:
min: 1000
max: 5000
unit_of_measurement: milliseconds
mode: box
step: 10
# Automation schema
variables:
# convert input tags to variables, to be used in templates
button_multi_press_enabled: !input button_multi_press_enabled
button_multi_press_always_fire_first_release: !input button_multi_press_always_fire_first_release
button_long_repeat_loop: !input button_long_repeat_loop
button_long_repeat_max_loop_repeats: !input button_long_repeat_max_loop_repeats
helper_last_controller_event: !input helper_last_controller_event
helper_multi_press_delay: !input helper_multi_press_delay
helper_debounce_delay: 10
# adjusted debounce delay so that the resulting multi press delay is exactly as specified by the user when running the action, taking also account of debouncing
# make sure it never goes below the minimum multi press delay
adjusted_multi_press_delay: "{{ [helper_multi_press_delay - helper_debounce_delay, 100] | max }}"
# mapping between actions and integrations
button_initial_press: [initial_press, on_press, press]
button_short_release: [short_release, on_short_release, release]
button_long_repeat: [repeat, on_hold, hold]
button_long_release: [long_release, on_long_release]
# build data to send within a controller event
controller_topic: !input controller_topic
controller_device: !input controller_device
controller_id: >-
{% if controller_topic|length > 1 %}
{{ controller_topic }}
{% else %}
{{controller_device}}
{% endif %}
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type:
- hue_event
- zha_event
event_data:
device_id: !input controller_device
- platform: mqtt
topic: !input controller_topic
payload: press
- platform: mqtt
topic: !input controller_topic
payload: release
- platform: mqtt
topic: !input controller_topic
payload: hold
condition:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{% if "payload" in trigger %}
{{ trigger.payload }}
{% elif "type" in trigger.event.data %}
{{ trigger.event.data.type }}
{% else %}
{{ trigger.event.data.command }}
{% endif %}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
action:
# debouncing - when automation is triggered multiple times, the last automation run is the one which completes execution, due to mode restart
# therefore previous runs must wait for the debounce delay before executing any other action
# if the delay expires and the automation is still running it means it's the last run and execution can continue
- delay:
milliseconds: "{{ helper_debounce_delay }}"
# extract button event from the trigger
# provide a single string value to check against
- variables:
trigger_action: >-
{% if "payload" in trigger %}
{{ trigger.payload }}
{% elif "type" in trigger.event.data %}
{{ trigger.event.data.type }}
{% else %}
{{ trigger.event.data.command }}
{% endif %}
trigger_delta: '{{ (as_timestamp(now()) - as_timestamp((states(helper_last_controller_event) | from_json).last_triggered if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{(\".*\": \".*\"(, )?)*\}$")) else "1970-01-01 00:00:00")) * 1000 }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: "{{ trigger_action | string in button_initial_press }}"
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_initial_press
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_initial_press
- conditions: "{{ trigger_action | string in button_short_release }}"
sequence:
- choose:
# if multi press events are enabled
- conditions: "{{ button_multi_press_enabled }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_multi_press_delay | int }}"
sequence:
# store the double press event in the last controller event helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":"double_press","last_triggered":now() | string} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_double_press
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_double_press
- conditions: '{{ "double_press" in states(helper_last_controller_event) and trigger_delta | int <= helper_multi_press_delay | int }}'
sequence:
# store the triple press event in the last controller event helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":"triple_press","last_triggered":now() | string} | to_json }}'
# run the triple press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_triple_press
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_triple_press
- conditions: '{{ "triple_press" in states(helper_last_controller_event) and trigger_delta | int <= helper_multi_press_delay | int }}'
sequence:
# store the quadruple press event in the last controller event helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":"quadruple_press","last_triggered":now() | string} | to_json }}'
# run the quadruple press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_quadruple_press
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_quadruple_press
- conditions: '{{ "quadruple_press" in states(helper_last_controller_event) and trigger_delta | int <= helper_multi_press_delay | int }}'
sequence:
# store the quintuple press event in the last controller event helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":"quintuple_press","last_triggered":now() | string} | to_json }}'
# run the quintuple press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_quintuple_press
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_quintuple_press
# previous event was not a short press
default:
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# Optionally skip delay to always fire the first release
- choose:
- conditions: "{{ button_multi_press_always_fire_first_release }}"
sequence: []
default:
# wait for the multi press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_multi_press_delay }}"
# if delay expires, no second press was received, therefore run the short press action
# run the short press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_short_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_short_release
# if multi press event is disabled run the action for the single short press
default:
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_short_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_short_release
- conditions: "{{ trigger_action | string in button_long_repeat }}"
sequence:
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_long_repeat
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: "{{ button_long_repeat_loop }}"
sequence:
- repeat:
while: "{{ repeat.index < button_long_repeat_max_loop_repeats | int }}"
sequence: !input action_button_long_repeat
# if looping is not enabled run the custom action only once
default: !input action_button_long_repeat
- conditions: "{{ trigger_action | string in button_long_release }}"
sequence:
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_long_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_long_release
using the new zigbee2mqtt version above make sure you use the /action
topic
if you look in topias’s post here there are two topics, use the topic that ends in /action
Hi there,
I’m quite new to home assistant so apologies for the hastle, however I’m having trouble setting up your blueprint:
I have a hue smart button (the single button that comes with the starter kit) and want to not onyl trigger my livingroom lights (hue bulbs) but also toggle some smart plugs at the same time.
First of all, I dont understand the required “helper - last controller event” part. What do I do here?
Additionally, I cant seem to figure out how to dim the light via long-press events.
Finally, do I have to do anything else once I have filled out this form? Do I need to set up anything elsewhere in my home-assistant, or does this blueprint cover it all?.
Do you have any tips on this?
I created a text helper, but not sure if I need to configure it differently as I still cant get things to work. Any tips?
can you show the rest of your config and what you wanna do?
Works like a charm for me.
Thank you very much !!
I got the simple press event worked using the button over zigbee2mqtt. But the multiple press event does not get triggert even with the related toggle enabled. Any idea which configuration may be wrong?
Can you share some more info? Unfortunately I don’t have Z2M so I did it by eye
Can you show the MQTT events you see while pressing the button, and if there are any automation traces for the secondary presses or if it didn’t trigger at all
Also just to confirm you’re using my new mqtt version above and not the one at the top of the thread
Hey Roger,
sure…
I’m using your latest version.
Furthermore, I have to correct me… the double press is recognized, but a single press not anymore if multi-press is enabled.
This one are the events from a single press:
Here you can see the trace from the single press (left one) and the double press (right one)
If you need something else, I will upload it asap.
Thank you for your help
Do you see any other traces for a single press? Maybe some cancelled ones?
If you know how to edit the blueprint code try changing the helper_debounce_delay: 10
line to maybe 0 and see what happens?
If not I’ll upload a version where you can change it as a setting
For me, you don’t have to upload a new version
I tried the 0 delay setting but with no effect.
You are right. There were some more traces. For one single press, I got three traces in the given sequence:
I played with the setting (UI) and my current workaround is to enable the “Always fire first short button release” action.
I think I can see the problem, the mqtt action topic sends additional payloads of “off” and “on” which seems to be some sort of toggler…
Is that a setting in z2m that maybe you can disable?
If not I’ll poke around in the blueprint and see if I can filter the trigger while keeping it working for all integrations
I updated the blueprint with different triggers Philips HUE Smart Button - 5 presses - #61 by TheHolyRoger
Do you want to see if that works better without the workaround?