Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ variables:
button_down_release: [down_long_release]
zigbee2mqtt:
# source: https://www.zigbee2mqtt.io/devices/324131092621.html#philips-324131092621
button_on_short: [on_press]
button_on_short: [on_press_release]
button_on_long: [on_hold]
button_on_release: [on_hold_release]
button_off_short: [off_press]
button_off_short: [off_press_release]
button_off_long: [off_hold]
button_off_release: [off_hold_release]
button_up_short: [up_press]
Expand All @@ -349,6 +349,7 @@ variables:
button_down_short: [down_press]
button_down_long: [down_hold]
button_down_release: [down_hold_release]
button_event_ignored: [on_press, off_press]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_on_short: '{{ actions_mapping[integration_id]["button_on_short"] }}'
Expand All @@ -363,6 +364,7 @@ variables:
button_down_short: '{{ actions_mapping[integration_id]["button_down_short"] }}'
button_down_long: '{{ actions_mapping[integration_id]["button_down_long"] }}'
button_down_release: '{{ actions_mapping[integration_id]["button_down_release"] }}'
button_event_ignored: '{{ actions_mapping[integration_id]["button_event_ignored"] }}'
# build data to send within a controller event
controller_id: !input controller_device
mode: restart
Expand All @@ -374,6 +376,11 @@ triggers:
device_id: !input controller_device
type: action
subtype: on_press
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: on_press_release
- trigger: device
domain: mqtt
device_id: !input controller_device
Expand All @@ -389,6 +396,11 @@ triggers:
device_id: !input controller_device
type: action
subtype: off_press
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: off_press_release
- trigger: device
domain: mqtt
device_id: !input controller_device
Expand Down Expand Up @@ -469,12 +481,16 @@ actions:
{{ trigger.event.data.command }}
{%- endif -%}
deserialized_state: '{{ (states(helper_last_controller_event) | from_json) if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{\s*?((\"a\":\s*?\".*\"|\"t\":\s*?\d+\.\d+)(,\s*?)?){2}\s*?\}$")) else {} }}'
last_controller_event: "{{ deserialized_state.a | default('') }}"
trigger_delta: '{{ (as_timestamp(now()) - (deserialized_state.t | default(0))) * 1000 }}'
# update helper
- action: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
# update helper if event not ignored
- choose:
- conditions: '{{ trigger_action | string not in button_event_ignored }}'
sequence:
- action: 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_on_short }}'
Expand Down
Loading