Skip to content

Instantly share code, notes, and snippets.

@SciLor
Created December 20, 2022 19:23
Show Gist options
  • Save SciLor/c49cc168a379b78dda59db22c4fa97c3 to your computer and use it in GitHub Desktop.
Save SciLor/c49cc168a379b78dda59db22c4fa97c3 to your computer and use it in GitHub Desktop.
Home Assistant: Different Actions on short, long, double and triple clicks for binary sensors - Works for ShellyForHass
blueprint:
name: Multi and long click
description: Different Actions on short, long, double and triple clicks
domain: automation
input:
switch_id:
name: Binary sensor entity
description: The binary_sensor used to trigger the automation
selector:
entity:
domain: binary_sensor
multiple: false
short_click_action:
name: Short click action
description: The action(s) to launch for a single short click
default: []
selector:
action: {}
double_click_action:
name: Double click action
description: The action(s) to launch for a double click
default: []
selector:
action: {}
triple_click_action:
name: Triple click action
description: The action(s) to launch for a triple click
default: []
selector:
action: {}
long_click_action:
name: Long click action
description: The action(s) to launch for a long click
default: []
selector:
action: {}
delay_long:
name: Long click delay in seconds
description: The time in seconds (can contain decimals) used as a delay for
the long click detection
default: 1.0
selector:
number:
min: 0.1
max: 10.0
unit_of_measurement: seconds
mode: slider
step: 0.1
delay_multi:
name: Multi click delay in seconds
description: The time in seconds (can contain decimals) used as a delay for
the multi click detection
default: 0.8
selector:
number:
min: 0.1
max: 10.0
unit_of_measurement: seconds
mode: slider
step: 0.1
source_url: https://community.home-assistant.io/t/trigger-different-actions-on-a-single-double-or-double-click-on-a-binary-sensor/255902
trigger:
- platform: state
entity_id: !input switch_id
to: 'on'
action:
- variables:
switch_id: !input switch_id
double_click: !input double_click_action
triple_click: !input triple_click_action
- wait_template: '{{ is_state(switch_id, ''off'') }}'
timeout: !input delay_long
- choose:
- conditions: '{{ not wait.completed }}'
sequence: !input long_click_action
default:
- choose:
- conditions: '{{ double_click | length > 0 }}'
sequence:
- wait_template: '{{ is_state(switch_id, ''on'') }}'
timeout: !input delay_multi
- choose:
- conditions: '{{ not wait.completed }}'
sequence: !input short_click_action
default:
- choose:
- conditions: '{{ triple_click | length > 0 }}'
sequence:
- wait_template: '{{ is_state(switch_id, ''off'') }}'
timeout: !input delay_multi
- wait_template: '{{ is_state(switch_id, ''on'') }}'
timeout: !input delay_multi
- choose:
- conditions: '{{ not wait.completed }}'
sequence: !input double_click_action
default: !input triple_click_action
default: !input double_click_action
default: !input short_click_action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment