Skip to content

Instantly share code, notes, and snippets.

@nickknissen
Forked from KeviinCosmos/script.yaml
Created November 23, 2023 06:11
Show Gist options
  • Save nickknissen/a9ff6af78e3ab708e2a317b82c50e30a to your computer and use it in GitHub Desktop.
Save nickknissen/a9ff6af78e3ab708e2a317b82c50e30a to your computer and use it in GitHub Desktop.
Controller - EnOcean PTM 215Z (Friends of Hue) switch double press
blueprint:
name: Controller - EnOcean PTM 215Z (Friends of Hue) switch double press
description: 'Controller automation for executing press/double-press/hold/release actions triggered by
EnOcean PTM 215Z (Friends of Hue) switch.'
domain: automation
input:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation.
default: ''
selector:
entity:
domain: sensor
hold_delay:
name: Hold delay
description: If the button has been held more than the configured Hold delay, the corresponding held action is triggered.
default: 500
selector:
number:
min: 100.0
max: 1000.0
unit_of_measurement: milliseconds
mode: box
step: 10.0
double_click_delay:
name: Double Click Delay
description: The time interval between two consecutive clicks to be considered as a double click.
default: 500
selector:
number:
min: 1.0
max: 400.0
unit_of_measurement: milliseconds
mode: box
step: 10.0
button_1_pressed:
name: Button 1 Pressed
description: Action to run, when button 1 is pressed.
default: []
selector:
action: {}
double_click_delay:
name: Double Click Delay
description: Delay (in milliseconds) to determine double click.
default: 500
selector:
number:
min: 100.0
max: 1000.0
unit_of_measurement: milliseconds
mode: box
step: 10.0
button_1_double_clicked:
name: Button 1 Double Clicked
description: Action to run, when button 1 is double clicked.
default: []
selector:
action:
- variables:
trigger_action: '{{ trigger.event.data.new_state.state }}'
button_1_last_clicked: '{{ (states("input_text.button_1_last_clicked_timestamp") | float) if "input_text.button_1_last_clicked_timestamp" in states else 0 }}'
- choose:
- conditions: '{{ trigger_action == "press_1" and wait.trigger != None }}'
sequence:
- choose:
- conditions: '{{ (as_timestamp(now()) - button_1_last_clicked) < (double_click_delay | int / 1000) }}'
sequence:
- service: input_text.set_value
data:
entity_id: input_text.button_1_last_clicked_timestamp
value: '{{ as_timestamp(now()) }}'
- !input 'button_1_double_clicked'
- conditions: '{{ (as_timestamp(now()) - button_1_last_clicked) >= (double_click_delay | int / 1000) }}'
sequence:
- service: input_text.set_value
data:
entity_id: input_text.button_1_last_clicked_timestamp
value: '{{ as_timestamp(now()) }}'
- !input 'button_1_pressed'
button_1_held:
name: Button 1 Held
description: Action to run, when the button 1 is held.
default: []
selector:
action: {}
button_1_released:
name: Button 1 released
description: Action to run, when the button 1 is released.
default: []
selector:
action: {}
button_2_pressed:
name: Button 2 Pressed
description: Action to run, when the button 2 pressed.
default: []
selector:
action: {}
button_2_held:
name: Button 2 Held
description: Action to run, when the button 2 is held.
default: []
selector:
action: {}
button_2_released:
name: Button 2 released
description: Action to run, when the button 2 is released.
default: []
selector:
action: {}
button_3_pressed:
name: Button 3 Pressed
description: Action to run, when the button 3 is pressed.
default: []
selector:
action: {}
button_3_held:
name: Button 3 Held
description: Action to run, when the button 3 is held.
default: []
selector:
action: {}
button_3_released:
name: Button 3 released
description: Action to run, when the button 3 is released.
default: []
selector:
action: {}
button_4_pressed:
name: Button 4 Pressed
description: Action to run, when the button 4 is pressed.
default: []
selector:
action: {}
button_4_held:
name: Button 4 Held
description: Action to run, when the button 4 is held.
default: []
selector:
action: {}
button_4_released:
name: Button 4 released
description: Action to run, when the button 4 is released.
default: []
selector:
action: {}
mode: single
max_exceeded: silent
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'controller_entity'
condition: '{{ trigger.event.data.new_state.state not in ["","None"] }}'
action:
- variables:
trigger_action: '{{ trigger.event.data.new_state.state }}'
- choose:
- conditions: '{{ "press_" | string in trigger_action }}'
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input 'controller_entity'
to: "release_1"
- platform: state
entity_id: !input 'controller_entity'
to: "release_2"
- platform: state
entity_id: !input 'controller_entity'
to: "release_3"
- platform: state
entity_id: !input 'controller_entity'
to: "release_4"
timeout:
milliseconds: !input 'hold_delay'
# - choose:
# - conditions: '{{ wait.trigger != None }}'
# sequence:
# - service: logbook.log
# data:
# name: Button Id
# message: '{{ trigger_action }} - press action'
# - conditions: '{{ wait.trigger == None }}'
# sequence:
# - service: logbook.log
# data:
# name: Button Id
# message: '{{ trigger_action }} - hold action'
- choose:
- conditions: '{{ trigger_action == "press_1" and wait.trigger != None }}'
sequence: !input 'button_1_pressed'
- conditions: '{{ trigger_action == "press_2" and wait.trigger != None }}'
sequence: !input 'button_2_pressed'
- conditions: '{{ trigger_action == "press_3" and wait.trigger != None }}'
sequence: !input 'button_3_pressed'
- conditions: '{{ trigger_action == "press_4" and wait.trigger != None }}'
sequence: !input 'button_4_pressed'
- conditions: '{{ trigger_action == "press_1" and wait.trigger == None }}'
sequence: !input 'button_1_held'
- conditions: '{{ trigger_action == "press_2" and wait.trigger == None }}'
sequence: !input 'button_2_held'
- conditions: '{{ trigger_action == "press_3" and wait.trigger == None }}'
sequence: !input 'button_3_held'
- conditions: '{{ trigger_action == "press_4" and wait.trigger == None }}'
sequence: !input 'button_4_held'
- conditions: '{{ "release_" | string in trigger_action }}'
sequence:
# - service: logbook.log
# data:
# name: Button Id
# message: '{{ trigger_action }} - release action'
- choose:
- conditions: '{{ trigger_action == "release_1" }}'
sequence: !input 'button_1_released'
- conditions: '{{ trigger_action == "release_2" }}'
sequence: !input 'button_2_released'
- conditions: '{{ trigger_action == "release_3" }}'
sequence: !input 'button_3_released'
- conditions: '{{ trigger_action == "release_4" }}'
sequence: !input 'button_4_released'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment