From 75e6d69d38f8a641011249405c5b37fc82c2024e Mon Sep 17 00:00:00 2001 From: nomike Date: Sat, 3 Feb 2024 03:25:36 +0100 Subject: [PATCH 1/4] Fix mapping for zigbee2mqtt - event names are with underscores (e.g. "on_hold" instead of "on-hold") - short presses should happen on the "_press_release" event and not on "_press" --- .../philips_324131092621.yaml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml index 4957f40b..27639737 100644 --- a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml +++ b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml @@ -321,18 +321,18 @@ variables: button_down_long: [down_hold] button_down_release: [down_long_release] zigbee2mqtt: - button_on_short: [on-press] - button_on_long: [on-hold] - button_on_release: [on-hold-release] - button_off_short: [off-press] - button_off_long: [off-hold] - button_off_release: [off-hold-release] - button_up_short: [up-press] - button_up_long: [up-hold] - button_up_release: [up-hold-release] - button_down_short: [down-press] - button_down_long: [down-hold] - button_down_release: [down-hold-release] + button_on_short: [on_press_release] + button_on_long: [on_hold] + button_on_release: [on_hold_release] + button_off_short: [off_press_release] + button_off_long: [off_hold] + button_off_release: [off_hold_release] + button_up_short: [up_press_release] + button_up_long: [up_hold] + button_up_release: [up_hold_release] + button_down_short: [down_press_release] + button_down_long: [down_hold] + button_down_release: [down_hold_release] # 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"] }}' @@ -489,7 +489,7 @@ action: - choose: - conditions: [] sequence: !input action_button_on_release - - conditions: '{{ trigger_action | string in button_off_short }}' + - conditions: "{{ trigger_action | string in button_off_short }}" sequence: - choose: # if double press event is enabled From adb20fa375b77b38fb7c164ed9382fb45cabb4d4 Mon Sep 17 00:00:00 2001 From: nomike Date: Sat, 3 Feb 2024 03:35:00 +0100 Subject: [PATCH 2/4] Fix calculation of tirigger_delta - Accept no whitspace behind json keys. - Add sample value as comment --- .../controllers/philips_324131092621/philips_324131092621.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml index 27639737..39a8dd9e 100644 --- a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml +++ b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml @@ -401,7 +401,8 @@ action: {%- elif integration_id == "zha" -%} {{ trigger.event.data.command }} {%- 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 }}' + # helper_last_controller_event example: {"a":"on_press_release","t":1706926380.358825} + 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 }}' # update helper - service: input_text.set_value data: From b0b729debfbf7d53c2a7c20db2e11db613aaede2 Mon Sep 17 00:00:00 2001 From: nomike Date: Sat, 3 Feb 2024 03:48:31 +0100 Subject: [PATCH 3/4] Don't run on "_press" events. --- .../controllers/philips_324131092621/philips_324131092621.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml index 39a8dd9e..4e2a2d3e 100644 --- a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml +++ b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml @@ -380,7 +380,7 @@ condition: {{ trigger.event.data.command }} {%- endif -%} {%- endset -%} - {{ trigger_action not in ["","None"] }} + {{ trigger_action not in ["","None", "on_press", "up_press", "down_press", "off_press"] }} # 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 }}' From 63ddfcfe4d7ef4359db5013b40e299f3753c7125 Mon Sep 17 00:00:00 2001 From: nomike Date: Sat, 3 Feb 2024 04:05:14 +0100 Subject: [PATCH 4/4] Allow any whitspace character when calculating trigger_delta. --- .../controllers/philips_324131092621/philips_324131092621.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml index 4e2a2d3e..d76afa69 100644 --- a/blueprints/controllers/philips_324131092621/philips_324131092621.yaml +++ b/blueprints/controllers/philips_324131092621/philips_324131092621.yaml @@ -402,7 +402,7 @@ action: {{ trigger.event.data.command }} {%- endif -%} # helper_last_controller_event example: {"a":"on_press_release","t":1706926380.358825} - 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 }}' + 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\":\s*\".*\"|\"t\":\s*\d+\.\d+)(,\s*)?){2}\}$")) else as_timestamp("1970-01-01 00:00:00"))) * 1000 }}' # update helper - service: input_text.set_value data: