Skip to content

Instantly share code, notes, and snippets.

@BlueFyre
Last active June 11, 2023 15:25
Show Gist options
  • Save BlueFyre/0aee4b3c3978a3ab7f2de1f55394736c to your computer and use it in GitHub Desktop.
Save BlueFyre/0aee4b3c3978a3ab7f2de1f55394736c to your computer and use it in GitHub Desktop.
Ikea Symfonisk Gen2 (E2123) Blueprint
# Based on https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e2001_e2002/ikea_e2001_e2002.yaml
blueprint:
name: Controller - IKEA E2123 Symfonisk Gen 2 Remote control
description: |
# Controller - IKEA E2123 Symfonisk Gen 2 Remote control
source_url: https://gist.github.com/BlueFyre/0aee4b3c3978a3ab7f2de1f55394736c
domain: automation
input:
integration:
name: (Required) Integration
description: Integration used for connecting the remote with Home Assistant. Select one of the available values.
selector:
select:
options:
- deCONZ
- ZHA
- Zigbee2MQTT
controller_device:
name: (deCONZ, ZHA) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.
default: ""
selector:
device:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
default: ""
selector:
entity:
domain: sensor
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_middle_short:
name: (Optional) Middle button short press
description: Action to run on short middle button press.
default: []
selector:
action:
action_button_middle_double:
name: (Optional) Middle button double press
description: Action to run on double middle button press.
default: []
selector:
action:
action_button_top_left_short:
name: (Optional) Top left button short press
description: Action to run on short top left button press.
default: []
selector:
action:
action_button_top_left_double:
name: (Optional) Top left button double press
description: Action to run on double top left button press.
default: []
selector:
action:
action_button_top_right_short:
name: (Optional) Top right button short press
description: Action to run on short top right button press.
default: []
selector:
action:
action_button_top_right_double:
name: (Optional) Top right button double press
description: Action to run on double top right button press.
default: []
selector:
action:
action_button_bottom_left_short:
name: (Optional) Bottom left button short press
description: Action to run on short bottom left button press.
default: []
selector:
action:
action_button_bottom_left_long:
name: (Optional) Bottom left button long press
description: Action to run on long bottom left button press.
default: []
selector:
action:
action_button_bottom_left_release:
name: (Optional) Bottom left button release
description: Action to run on bottom left button release after long press.
default: []
selector:
action:
action_button_bottom_left_double:
name: (Optional) Bottom left button double press
description: Action to run on double bottom left button press.
default: []
selector:
action:
action_button_bottom_right_short:
name: (Optional) Bottom right button short press
description: Action to run on short bottom right button press.
default: []
selector:
action:
action_button_bottom_right_long:
name: (Optional) Bottom right button long press
description: Action to run on long bottom right button press.
default: []
selector:
action:
action_button_bottom_right_release:
name: (Optional) Bottom right button release
description: Action to run on bottom right button release after long press.
default: []
selector:
action:
action_button_bottom_right_double:
name: (Optional) Bottom right button double press
description: Action to run on double bottom right button press.
default: []
selector:
action:
action_button_up_short:
name: (Optional) Up button short press
description: Action to run on short up button press.
default: []
selector:
action:
action_button_up_double:
name: (Optional) Up button double press
description: Action to run on double up button press.
default: []
selector:
action:
action_button_down_short:
name: (Optional) Down button short press
description: Action to run on short down button press.
default: []
selector:
action:
action_button_down_double:
name: (Optional) Down button double press
description: Action to run on double down button press.
default: []
selector:
action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_bottom_left_long_loop:
name: (Optional) Bottom left button long press - loop until release
description: Loop the bottom left button action until the button is released.
default: false
selector:
boolean:
button_bottom_left_long_max_loop_repeats:
name: (Optional) Bottom left 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
button_bottom_right_long_loop:
name: (Optional) Bottom right button long press - loop until release
description: Loop the bottom right button action until the button is released.
default: false
selector:
boolean:
button_bottom_right_long_max_loop_repeats:
name: (Optional) Bottom right 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_middle_double_press:
name: (Optional) Expose middle button double press event
description: Choose whether or not to expose the virtual double press event for the middle button. Turn this on if you are providing an action for the middle button double press event.
default: false
selector:
boolean:
button_top_left_double_press:
name: (Optional) Expose top left button double press event
description: Choose whether or not to expose the virtual double press event for the top left button. Turn this on if you are providing an action for the top left button double press event.
default: false
selector:
boolean:
button_bottom_left_double_press:
name: (Optional) Expose bottom left button double press event
description: Choose whether or not to expose the virtual double press event for the bottom left button. Turn this on if you are providing an action for the bottom left button double press event.
default: false
selector:
boolean:
button_top_right_double_press:
name: (Optional) Expose top right button double press event
description: Choose whether or not to expose the virtual double press event for the top right button. Turn this on if you are providing an action for the top right button double press event.
default: false
selector:
boolean:
button_bottom_right_double_press:
name: (Optional) Expose bottom right button double press event
description: Choose whether or not to expose the virtual double press event for the bottom right button. Turn this on if you are providing an action for the bottom right button double press event.
default: false
selector:
boolean:
button_up_double_press:
name: (Optional) Expose up button double press event
description: Choose whether or not to expose the virtual double press event for the up button. Turn this on if you are providing an action for the up button double press event.
default: false
selector:
boolean:
button_down_double_press:
name: (Optional) Expose down button double press event
description: Choose whether or not to expose the virtual double press event for the down button. Turn this on if you are providing an action for the down button double press event.
default: false
selector:
boolean:
# helpers used to properly recognize the remote button events
helper_double_press_delay:
name: (Optional) Helper - Double Press delay
description: Max delay between the first and the second button press for the double press event. Provide a value only if you are using a double press action. Increase this value if you notice that the double press action is not triggered properly.
default: 500
selector:
number:
min: 100
max: 5000
unit_of_measurement: milliseconds
mode: box
step: 10
helper_debounce_delay:
name: (Optional) Helper - Debounce delay
description:
Delay used for debouncing RAW controller events, by default set to 0. A value of 0 disables the debouncing feature. Increase this value if you notice custom actions or linked Hooks running multiple times when interacting with the device. When the controller needs to be debounced,
usually a value of 100 is enough to remove all duplicate events.
default: 0
selector:
number:
min: 0
max: 1000
unit_of_measurement: milliseconds
mode: box
step: 10
# Automation schema
variables:
# convert input tags to variables, to be used in templates
integration: !input integration
button_middle_double_press: !input button_middle_double_press
button_top_left_double_press: !input button_top_left_double_press
button_top_right_double_press: !input button_top_right_double_press
button_bottom_left_long_loop: !input button_bottom_left_long_loop
button_bottom_left_long_max_loop_repeats: !input button_bottom_left_long_max_loop_repeats
button_bottom_left_double_press: !input button_bottom_left_double_press
button_bottom_right_long_loop: !input button_bottom_right_long_loop
button_bottom_right_long_max_loop_repeats: !input button_bottom_right_long_max_loop_repeats
button_bottom_right_double_press: !input button_bottom_right_double_press
button_up_double_press: !input button_up_double_press
button_down_double_press: !input button_down_double_press
helper_last_controller_event: !input helper_last_controller_event
helper_double_press_delay: !input helper_double_press_delay
helper_debounce_delay: !input helper_debounce_delay
# integration id used to select items in the action mapping
integration_id: "{{ integration | lower }}"
# adjusted debounce delay so that the resulting double 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 double press delay
adjusted_double_press_delay: "{{ [helper_double_press_delay - helper_debounce_delay, 100] | max }}"
# mapping between actions and integrations
actions_mapping:
deconz:
button_middle_short: ["3002"] # TODO
button_top_left_short: ["3002"] # TODO
button_top_right_short: ["4002"] # TODO
button_bottom_left_short: ["3002"] # TODO
button_bottom_left_long: ["3001"] # TODO
button_bottom_left_release: ["3003"] # TODO
button_bottom_right_short: ["4002"] # TODO
button_bottom_right_long: ["4001"] # TODO
button_bottom_right_release: ["4003"] # TODO
button_up_short: ["1002"] # TODO
button_down_short: ["2002"] # TODO
zha:
button_middle_short: [press_257_13_0] # TODO
button_top_left_short: [press_257_13_0] # TODO
button_top_right_short: [press_256_13_0] # TODO
button_bottom_left_short: [press_257_13_0] # TODO
button_bottom_left_long: [hold_3329_0] # TODO
button_bottom_left_release: [release_1365] # TODO
button_bottom_right_short: [press_256_13_0] # TODO
button_bottom_right_long: [hold_3328_0] # TODO
button_bottom_right_release: [release_-27903] # TODO
button_up_short: ["on"] # TODO
button_down_short: ["off"] # TODO
zigbee2mqtt:
button_middle_short: [toggle]
button_top_left_short: [track_previous]
button_top_right_short: [track_next]
button_bottom_left_short: [dots_1_short_release]
button_bottom_left_long: [dots_1_long_press]
button_bottom_left_release: [dots_1_long_release]
button_bottom_right_short: [dots_2_short_release]
button_bottom_right_long: [dots_2_long_press]
button_bottom_right_release: [dots_2_long_release]
button_up_short: [volume_up]
button_down_short: [volume_down]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_middle_short: '{{ actions_mapping[integration_id]["button_middle_short"] }}'
button_top_left_short: '{{ actions_mapping[integration_id]["button_top_left_short"] }}'
button_top_right_short: '{{ actions_mapping[integration_id]["button_top_right_short"] }}'
button_bottom_left_short: '{{ actions_mapping[integration_id]["button_bottom_left_short"] }}'
button_bottom_left_long: '{{ actions_mapping[integration_id]["button_bottom_left_long"] }}'
button_bottom_left_release: '{{ actions_mapping[integration_id]["button_bottom_left_release"] }}'
button_bottom_right_short: '{{ actions_mapping[integration_id]["button_bottom_right_short"] }}'
button_bottom_right_long: '{{ actions_mapping[integration_id]["button_bottom_right_long"] }}'
button_bottom_right_release: '{{ actions_mapping[integration_id]["button_bottom_right_release"] }}'
button_up_short: '{{ actions_mapping[integration_id]["button_up_short"] }}'
button_down_short: '{{ actions_mapping[integration_id]["button_down_short"] }}'
# integrations which need to store the previous press event to determine which button was released
integrations_with_prev_event_storage: [zha, zigbee2mqtt]
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# trigger for other integrations
- platform: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
# this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
- '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
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: !input helper_debounce_delay
# extract button event from the trigger
# provide a single string value to check against
- variables:
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
trigger_delta: '{{ (as_timestamp(now()) - ((states(helper_last_controller_event) | from_json).t if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\": \".*\"|\"t\": \d+\.\d+)(, )?){2}\}$")) else as_timestamp("1970-01-01 00:00:00"))) * 1000 }}'
last_controller_event: '{{ (states(helper_last_controller_event) | from_json).a if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\": \".*\"|\"t\": \d+\.\d+)(, )?){2}\}$")) else "" }}'
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: "{{ trigger_action | string in button_middle_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_middle_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_middle_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_middle_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_middle_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_middle_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_middle_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_middle_short
- conditions: "{{ trigger_action | string in button_top_left_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_top_left_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_top_left_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_left_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_top_left_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_left_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_top_left_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_left_short
- conditions: "{{ trigger_action | string in button_top_right_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_top_right_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_top_right_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_right_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_top_right_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_right_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_top_right_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_top_right_short
- conditions: "{{ trigger_action | string in button_bottom_left_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_bottom_left_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_left_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_left_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_bottom_left_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_left_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_left_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_left_short
- conditions: "{{ trigger_action | string in button_bottom_left_long }}"
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_left_long
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: "{{ button_bottom_left_long_loop }}"
sequence:
- repeat:
while: "{{ repeat.index < button_bottom_left_long_max_loop_repeats | int }}"
sequence: !input action_button_bottom_left_long
# if looping is not enabled run the custom action only once
default: !input action_button_bottom_left_long
- conditions:
- "{{ trigger_action | string in button_bottom_left_release }}"
# for integrations which need to store the last controller event, need to check the previous button event, stored in the provided input_text
- "{{ not integration_id in integrations_with_prev_event_storage or last_controller_event | string in button_bottom_left_long }}"
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_left_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_left_release
- conditions: "{{ trigger_action | string in button_bottom_right_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_bottom_right_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_right_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_right_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_bottom_right_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_right_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_right_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_right_short
- conditions: "{{ trigger_action | string in button_bottom_right_long }}"
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_right_long
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: "{{ button_bottom_right_long_loop }}"
sequence:
- repeat:
while: "{{ repeat.index < button_bottom_right_long_max_loop_repeats | int }}"
sequence: !input action_button_bottom_right_long
# if looping is not enabled run the custom action only once
default: !input action_button_bottom_right_long
- conditions:
- "{{ trigger_action | string in button_bottom_right_release }}"
# for integrations which need to store the last controller event, need to check the previous button event, stored in the provided input_text
- "{{ not integration_id in integrations_with_prev_event_storage or last_controller_event | string in button_bottom_right_long }}"
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_bottom_right_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_bottom_right_release
- conditions: "{{ trigger_action | string in button_up_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_up_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_up_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_up_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_up_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_up_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_up_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_up_short
- conditions: "{{ trigger_action | string in button_down_short }}"
sequence:
- choose:
# if double press event is enabled
- conditions: "{{ button_down_double_press }}"
sequence:
- choose:
# if previous event was a short press
- conditions: "{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_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: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_down_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_down_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: "{{ adjusted_double_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_down_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_down_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: "{{ controller_id }}"
action: button_down_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_down_short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment