Instantly share code, notes, and snippets.
Created
October 29, 2023 23:31
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save manix84/b367e6acc9a7d916366ce1793890ee7b to your computer and use it in GitHub Desktop.
A Home Assistant Automation Blueprint for detecting Single, Double, and Long presses of ZHA attached Smart Buttons (EG: Hue Smart Button). Allowing you to attach your own custom actions to the events.
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: Smart Button | |
description: | | |
Short, Long, and Double press actions for Smart Buttons. | |
Variables: | |
* <strong>last_triggered</strong> - the time the script was triggered. | |
* <strong>last_triggered_seconds</strong> - number of seconds since the last trigger. | |
* <strong>action</strong> - parsed actions list (<em>short_press</em>, <em>double_press</em>, <em>long_press</em>). | |
domain: automation | |
source_url: https://gist.github.com/manix84/b367e6acc9a7d916366ce1793890ee7b | |
author: Manix84 | |
input: | |
button_device_id: | |
name: Smart Button | |
description: "Your Smart Button; check integration and/or App if you don't know the name" | |
selector: | |
device: | |
integration: zha | |
delay_time: | |
name: Delay Time | |
description: How long to wait for a double press. | |
default: 0.5 | |
selector: | |
number: | |
mode: slider | |
min: 0 | |
max: 5 | |
step: 0.1 | |
unit_of_measurement: "seconds" | |
short_press_action: | |
name: Short Press Actions | |
description: "Actions to run, when button is pressed quickly." | |
default: [] | |
selector: | |
action: {} | |
double_press_action: | |
name: Double Press Actions | |
description: "Actions to run, when button is pressed quickly twice." | |
default: [] | |
selector: | |
action: {} | |
long_press_action: | |
name: Long Press Actions | |
description: "Actions to run, when button is pressed and released after over a second." | |
default: [] | |
selector: | |
action: {} | |
mode: restart | |
alias: Smart Button | |
description: Reacting to the press of a smart button, and running actions you specify. | |
variables: | |
action: > | |
{{ trigger.id }} | |
last_triggered: > | |
{{ this.attributes.last_triggered }} | |
last_triggered_seconds: > | |
{{ now().timestamp() - as_timestamp(this.attributes.last_triggered) }} | |
delay_time: !input delay_time | |
trigger: | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input button_device_id | |
command: on_short_release | |
id: short_press | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input button_device_id | |
command: on_long_release | |
id: long_press | |
condition: [] | |
action: | |
- service: persistent_notification.create | |
enabled: false | |
data: | |
message: >- | |
<strong>Last Triggered:</strong> {{ now().timestamp() - as_timestamp(this.attributes.last_triggered) }} seconds ago ({{ this.attributes.last_triggered }}). | |
<strong>Action:</strong> {{ trigger.event.data.command }} | |
<strong>Delay Time:</strong> {{ delay_time }} | |
<strong>Data:</strong> | |
{{ trigger.event.data }} | |
notification_id: zha-smart-button-debug-init | |
title: Trigger ID "{{ trigger.id }}_something" | |
- choose: | |
- alias: Short Press | |
conditions: | |
- condition: trigger | |
id: short_press | |
enabled: true | |
- condition: template | |
value_template: "{{ last_triggered_seconds > delay_time }}" | |
sequence: | |
- delay: | |
seconds: !input delay_time | |
- choose: | |
- conditions: [] | |
sequence: !input short_press_action | |
- alias: Double Press | |
conditions: | |
- condition: trigger | |
id: short_press | |
enabled: true | |
- condition: template | |
value_template: "{{ last_triggered_seconds <= delay_time }}" | |
sequence: | |
- variables: | |
action: double_press | |
- choose: | |
- conditions: [] | |
sequence: !input double_press_action | |
- alias: Long Press | |
conditions: | |
- condition: trigger | |
id: long_press | |
enabled: true | |
sequence: !input long_press_action | |
default: | |
- service: persistent_notification.create | |
data: | |
message: >- | |
<strong>Last Triggered:</strong> {{ now().timestamp() - as_timestamp(this.attributes.last_triggered) }} seconds ago ({{ this.attributes.last_triggered }}). | |
<strong>Action:</strong> {{ trigger.event.data.command }} | |
<strong>Delay Time:</strong> {{ delay_time }} | |
<strong>Data:</strong> | |
{{ trigger.event.data }} | |
notification_id: zha-smart-button-debug | |
title: Trigger ID "{{ trigger.id }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment