EPMatt / awesome-ha-blueprints

A curated collection of automation blueprints for Home Assistant.
https://epmatt.github.io/awesome-ha-blueprints
GNU General Public License v3.0
867 stars 254 forks source link

Bug - Ikea Shortcut Button Double Click does not work #593

Open hackintoshlover opened 10 months ago

hackintoshlover commented 10 months ago

Blueprint name

Controller - IKEA E1812 TRÅDFRI Shortcut button

Home Assistant Core Version

2023.11.3

Home Assistant Installation Type

Home Assistant Operating System

Description

I imported the Ikea shortcut button blueprint and set it up everything works as expected, except double click. Attached screenshots of setup with error. I having configured the device using zigbee 2 mqtt setup.

Automation YAML config

Attachedalias: Controller - IKEA E1812 TRÅDFRI Shortcut button
description: ""
use_blueprint:
  path: EPMatt/ikea_e1812.yaml
  input:
    integration: Zigbee2MQTT
    controller_entity: sensor.0x94deb8fffee14abe_action
    action_button_double:
      - service: switch.toggle
        data: {}
        target:
          device_id: 9d9d853ecd3efa803f10702640113de1
    helper_double_press_delay: 1000
    button_double_press: true
    helper_last_controller_event: input_text.helper_last_controller_event

To Reproduce

Import blueprint. Setup as image below. Run.

Expected behavior

Double click should toggle switch.

Actual Behaviour

Nothing.

Additional Details

Screenshots

Screenshot (364) Screenshot (363) Screenshot (362) Screenshot (361) Screenshot (360) Screenshot (359) Screenshot (358) Screenshot (357) Screenshot (356)

Additional context

No response

t08 commented 10 months ago

same here. Also a note is that the (Optional) Helper - Double Press delay is working-isch, it takes the delay, after that it just fires the single press action

ZtormTheCat commented 9 months ago

I also have this problem and did a little digging in the traces. It seems like the time since the last command doesn't get set correctly. I'm currently working on finding out where the problem exactly lies and will try to fix it.

ZtormTheCat commented 9 months ago

I found the problem. It has to do with RegEx. The problem occurs both when trying to set trigger_delta and last_controller_event. It seems that for some time now the regex to determine if the Helper contains the correct string doesn't match, even though it is correct.

I am in no way a home assistant or scripting expert but to me it seems like some way down the line the way home assistant handles whitespaces in RegEx changed.

This is the current way the automation checks for the correctness:

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 }}

If you change this to:

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 }}

It gets matched correctly. All I did was remove all whitespaces in the RegEx.

hackintoshlover commented 9 months ago

I found the problem. It has to do with RegEx. The problem occurs both when trying to set trigger_delta and last_controller_event. It seems that for some time now the regex to determine if the Helper contains the correct string doesn't match, even though it is correct.

I am in no way a home assistant or scripting expert but to me it seems like some way down the line the way home assistant handles whitespaces in RegEx changed.

This is the current way the automation checks for the correctness:

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 }}

If you change this to:

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 }}

It gets matched correctly. All I did was remove all whitespaces in the RegEx.

Hi glad it worked for you. just two quick questions: 1) Where do i make these changes? 2) The only change i see is regex_match changed to a new line. That fixes it?

ZtormTheCat commented 9 months ago
  1. I will try to create a Pull request today so you can just import the blueprint again. But I'll also look into how to change it locally so you don't have to wait for the PR.

  2. I also removed the spaces before the first \d and before )?

hackintoshlover commented 9 months ago

Thanks Mate. I hope the update happens soon.

ZtormTheCat commented 9 months ago

Ok, so here's how you can change it locally: First you should install the file explorer add-on in the Add-On stored if you didn't already. Then follow this tutorial to edit your blueprint locally.

In the blueprint navigate to line 482 and 486 (Might vary for you) and change all the regex strings to not contain ANY whitespaces aka Spaces and newlines. Then save the .yaml file and restart Home Assistant(Honestly don't know if thats necessary).

If you still need help doing it, feel free to ask.

p4sI commented 9 months ago

Thanks for this fix in the regex @ZtormTheCat. Worked like a charm.