Has anyone managed to get the hold actions working correctly? I’m using @11harveyj’s Blueprint and have tried a few making a few tweaks for down_hold etc. but can’t seem to get working without breaking other functions. I am currently using Switch Manager - New refined switch integration to manage your switches instead which does handle hold presses OK if anyone else is struggling with this.
Here is my working blueprint incl. the holding function.
File “hue_929002398602_mqtt.yaml”:
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: "{{ 'action' in trigger.payload_json and 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
thank you for your great blueprint.
i am using on press and hold(once) for different features, and if i intend to use hold(once) on press is triggered too. is this intended? if so should i use on release?
Yes, it’s in the description of the blueprint:
To have different actions on short press and on hold (long press), use ‘button release’ (
*_press_release
) and ‘button hold once’ (*_hold_once
)
Here is how I solved my issue! Its working great! For some reason, changing the rate in the delay node isn’t working, but I can change the tick up in the payload. Lower than 80 completely bricks wled integration, so this is the lowest I was able to make it.
[{"id":"74bf69f207c10ffa","type":"switch","z":"102803786c01f817","name":"Which payload?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"up_press","vt":"str"},{"t":"eq","v":"up_hold","vt":"str"},{"t":"eq","v":"up_hold_release","vt":"str"},{"t":"eq","v":"down_press","vt":"str"},{"t":"eq","v":"down_hold","vt":"str"},{"t":"eq","v":"down_hold_release","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":660,"y":1600,"wires":[["1142de7afe27d649"],["228f24fef5e96892"],["f131fdf6645a8124"],["1ad8200a531d1ad9"],["7190a623fb36a9ae"],["28bd40501809b971"]]},{"id":"7fcaeb49f9c60b4b","type":"change","z":"102803786c01f817","name":"msg.payload = action","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1600,"wires":[["74bf69f207c10ffa","a6751a65462edf11"]]},{"id":"1142de7afe27d649","type":"api-call-service","z":"102803786c01f817","name":"↑ single step +10%","server":"e3d85e14.7c261","version":7,"debugenabled":false,"action":"light.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.led_canto"],"labelId":[],"data":"{\"brightness_step_pct\":5}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"blockInputOverrides":false,"domain":"light","service":"turn_on","output_location":"","output_location_type":"none","x":930,"y":1540,"wires":[[]]},{"id":"228f24fef5e96892","type":"function","z":"102803786c01f817","name":"Generate first tick (up)","func":"return { payload: \"tick_up\", rate: 80 };","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":1600,"wires":[["750330ab0034861b"]]},{"id":"f131fdf6645a8124","type":"change","z":"102803786c01f817","name":"Stop ↑ loop","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":1640,"wires":[["750330ab0034861b"]]},{"id":"1ad8200a531d1ad9","type":"api-call-service","z":"102803786c01f817","name":"↓ single step -10%","server":"e3d85e14.7c261","version":7,"debugenabled":false,"action":"light.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.led_canto"],"labelId":[],"data":"{\"brightness_step_pct\":-10}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"blockInputOverrides":false,"domain":"light","service":"turn_on","output_location":"","output_location_type":"none","x":930,"y":1760,"wires":[[]]},{"id":"7190a623fb36a9ae","type":"function","z":"102803786c01f817","name":"Generate first tick (down)","func":"return { payload: \"tick_down\", rate: 80 };","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":1820,"wires":[["f07d7f962f3931da"]]},{"id":"28bd40501809b971","type":"change","z":"102803786c01f817","name":"Stop ↓ loop","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":1860,"wires":[["f07d7f962f3931da"]]},{"id":"64a1951834d0371a","type":"mqtt in","z":"102803786c01f817","name":"MQTT – Interruptor Hue (action)","topic":"zigbee2mqtt/Interruptor Hue/action","qos":"0","datatype":"auto-detect","broker":"fbac6eb7e98975f5","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":1600,"wires":[["7fcaeb49f9c60b4b"]]},{"id":"a6751a65462edf11","type":"debug","z":"102803786c01f817","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":560,"y":1760,"wires":[]},{"id":"750330ab0034861b","type":"delay","z":"102803786c01f817","name":"Rate-limit ↑ at 50 ms","pauseType":"rate","timeout":"0","timeoutUnits":"ms","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"0","randomLast":"0","randomUnits":"ms","drop":false,"allowrate":true,"outputs":1,"x":1250,"y":1620,"wires":[["750330ab0034861b","314d37175a5554ab","437c43d1251376d8"]]},{"id":"f07d7f962f3931da","type":"delay","z":"102803786c01f817","name":"Rate-limit ↓ at 50 ms","pauseType":"rate","timeout":"0","timeoutUnits":"ms","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"0","randomLast":"0","randomUnits":"ms","drop":false,"allowrate":true,"outputs":1,"x":1250,"y":1840,"wires":[["5db70163f2eaaf33","f07d7f962f3931da"]]},{"id":"314d37175a5554ab","type":"debug","z":"102803786c01f817","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1380,"y":1560,"wires":[]},{"id":"437c43d1251376d8","type":"api-call-service","z":"102803786c01f817","name":"↑ step +4%","server":"e3d85e14.7c261","version":7,"debugenabled":false,"action":"light.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.led_canto"],"labelId":[],"data":"{\"brightness_step_pct\":4}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"blockInputOverrides":false,"domain":"light","service":"turn_on","output_location":"","output_location_type":"none","x":1530,"y":1620,"wires":[[]]},{"id":"5db70163f2eaaf33","type":"api-call-service","z":"102803786c01f817","name":"↓ step -4%","server":"e3d85e14.7c261","version":7,"debugenabled":false,"action":"light.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.led_canto"],"labelId":[],"data":"{\"brightness_step_pct\":-4}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"blockInputOverrides":false,"domain":"light","service":"turn_on","output_location":"","output_location_type":"none","x":1530,"y":1840,"wires":[[]]},{"id":"e3d85e14.7c261","type":"server","name":"Home Assistant","addon":true},{"id":"fbac6eb7e98975f5","type":"mqtt-broker","name":"","broker":"192.168.0.2","port":"1883","clientid":"HAMQTT","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]
Has anyone got a dummies guide?
Really struggling with this, to be honest
Go to Home Assistant > zigbee2mqtt’s web ui > Settings > Home Assistant integration
If you have “Home Assistant legacy action sensors” enabled, then you can use this blueprint by JetSerge:
If you have “Home Assistant experimental event entities” enabled, then you need to use 11harveyj’s fork of JetSerge’s blueprint:
If you use my blueprint (manually create the file file editor or SSH) from here: Philips Hue Dimmer Switch v2 (Zigbee2MQTT) - #83 by pOpY
You dont need the legacy setting.
This is yet another way, although not blueprint per se, but straight automation.
Background, I’m using the hue dimmer switch v2 with z2m and without any legacy flags in z2m, and a zigbee blub that does RGBW. And I build the whole thing using automation UI - those triggers are device triggers so your device id for the hue dimmer switch will be different for sure.
Again, not blueprint per se, but figured I could at least share.
alias: Bulb Kitchen Sink operations per hue dimmer switch
description: ""
triggers:
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: on_press_release
trigger: device
id: hue_on_press_release
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: up_press_release
trigger: device
id: hue_up_press_release
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: down_press_release
trigger: device
id: hue_down_press_release
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: off_press_release
trigger: device
id: hue_off_press_release
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: off_hold_release
trigger: device
id: hue_on_hold
- domain: mqtt
device_id: ababababababababababab
type: action
subtype: off_hold
trigger: device
id: hue_off_hold
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id: hue_on_press_release
sequence:
- data:
transition: 1
brightness_pct: 75
target:
entity_id:
- light.bulb_kitchen_sink_rgbw
action: light.toggle
- conditions:
- condition: trigger
id: hue_up_press_release
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "off"
sequence:
- data:
transition: 0
brightness_pct: 1
target:
entity_id:
- light.bulb_kitchen_sink_rgbw
action: light.turn_on
- conditions:
- condition: trigger
id: hue_up_press_release
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "on"
sequence:
- data:
transition: 1
brightness_step_pct: 24
target:
entity_id:
- light.bulb_kitchen_sink_rgbw
action: light.turn_on
- conditions:
- condition: trigger
id: hue_down_press_release
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "on"
sequence:
- data:
transition: 1
brightness_step_pct: -24
target:
entity_id:
- light.bulb_kitchen_sink_rgbw
action: light.turn_on
- conditions:
- condition: trigger
id: hue_off_press_release
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "on"
sequence:
- data:
hs_color:
- >-
{{ (state_attr("light.bulb_kitchen_sink_rgbw", "hs_color")[0]
+ 60) % 360 }}
- 100
transition: 1
target:
entity_id: light.bulb_kitchen_sink_rgbw
action: light.turn_on
- conditions:
- condition: trigger
id:
- hue_on_hold
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "off"
sequence:
- data:
transition: 2
brightness_pct: 100
target:
entity_id: light.bulb_kitchen_sink_rgbw
action: light.turn_on
- conditions:
- condition: trigger
id: hue_on_hold
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "on"
sequence:
- data:
transition: 2
target:
entity_id:
- light.bulb_kitchen_sink_rgbw
action: light.turn_off
- conditions:
- condition: trigger
id:
- hue_off_hold
- condition: state
entity_id: light.bulb_kitchen_sink_rgbw
state: "on"
sequence:
- data:
color_temp_kelvin: 3000
transition: 1
target:
entity_id: light.bulb_kitchen_sink_rgbw
action: light.turn_on
mode: restart