Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - IKEA E1524/E1810 TRÅDFRI - new custom quirks in recent f/w update broke blueprint #535

Open
1 task
Venj-ADL opened this issue Apr 5, 2023 · 15 comments
Labels
blueprint An issue related to a blueprint bug Something isn't working

Comments

@Venj-ADL
Copy link

Venj-ADL commented Apr 5, 2023

Blueprint name

Controller - IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote

Home Assistant Core Version

2023.02.01 >

Home Assistant Installation Type

Home Assistant Operating System

Description

In late February IKEA issued a firmware update to the E1524/E1810 TRÅDFRI remotes (Firmware: 0x24040005). This changed the data they were sending and required custom_quirks as a workaround to get them sending data to HA again. Home Assistant 2023.03 update added these quirks into the ZHA environment so custom_quirks were no longer required, however, this has broken your Blueprint. This is hands down the BEST blueprint for this remote and I desperately want to get it working again. Can we please update it to work with the Firmware: 0x24040005 and the new quirks?

Automation YAML config

n/a

To Reproduce

  1. Update IKEA remote to Firmware: 0x24040005

Expected behavior

Blueprint to function as normal

Actual Behaviour

Several buttons now send different output with new f/w and both ZHA and the Blueprint weren't playing ball. The ZHA quirks have been updated as of 2023.03 HA update, just need Blueprint to match.

Additional Details

  • I'd like to help developing a fix for this issue.

Screenshots

No response

Additional context

No response

@Venj-ADL Venj-ADL added blueprint An issue related to a blueprint bug Something isn't working labels Apr 5, 2023
@bernd63571
Copy link

I have a similar problem. After an update, the controller sends different commands, so the blueprint does not recognise them.
My workaround is quite simple:
I press the key, that I want to use. The command sent is then stored in the helper. I copy the contend of the command (behind the "a:" and "t:" and include it the in the blueprint.
An example for the "UP" key:
button_up_short:
- step_with_on_off_StepMode.Up_43_5 #// this is the new command

- step_with_on_off_0_43_5 #// this is the current line in the blueprint

This is not a perfect solution, sorry. I can not compete with all the coding wizzards here, so I can only leave a suggestion, where the blueprint may be improved.

@bernd63571
Copy link

Sorry for the bold text, was not intended.

@lhassell
Copy link

Just stopping in to +1 this. Does anyone have any idea if this could be edited manually on our side? I'm more than willing to tinker, but I'm not a programmer.

@bernd63571
Copy link

Edit the blueprint? No problem. You need either the add-on "File editor" or "Samba share" and you can modify it.

milothomas added a commit to milothomas/awesome-ha-blueprints that referenced this issue Jun 8, 2023
@milothomas
Copy link

I have updated the Up and Down short press button mappings for ZHA in this PR. If someone has the relevant mappings for the other integrations feel free to update.
#551

@jacobwod
Copy link

jacobwod commented Jun 9, 2023

I have updated the Up and Down short press button mappings for ZHA in this PR. If someone has the relevant mappings for the other integrations feel free to update.
#551

I can confirm that it works like a charm for E1524, thank you!

@kineticscreen
Copy link

So the double presses are still not solved? They're still ignored for me.

@SoccerCore11
Copy link

Here are the additional changes to make the 'long press up' and 'long press down' work again:

      button_up_short:
        - step_with_on_off_StepMode.Up_43_5
      button_up_long:
        - move_with_on_off_MoveMode.Up_84

@2manyvcos
Copy link

I had to change the following fields to get short and long presses to work:

      button_up_short:
      - step_with_on_off_StepMode.Up_43_5
      button_up_long:
      - move_with_on_off_MoveMode.Up_84
      button_up_release:
      - stop_with_on_off
      button_down_short:
      - step_StepMode.Down_43_5_0_0
      button_down_long:
      - move_MoveMode.Down_84_0_0
      button_down_release:
      - stop_0_0

I also had to remove the whitespaces from the following two Regexes in order to get long presses to stop when releasing the buttons (see #545):

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
+     | 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 "" }}'
+     | regex_match("^\{((\"a\":\".*\"|\"t\":\d+\.\d+)(,)?){2}\}$")) else "" }}'

@bryantlee
Copy link

bryantlee commented Aug 13, 2023

I had to change the following fields to get short and long presses to work:

      button_up_short:
      - step_with_on_off_StepMode.Up_43_5
      button_up_long:
      - move_with_on_off_MoveMode.Up_84
      button_up_release:
      - stop_with_on_off
      button_down_short:
      - step_StepMode.Down_43_5_0_0
      button_down_long:
      - move_MoveMode.Down_84_0_0
      button_down_release:
      - stop_0_0

I also had to remove the whitespaces from the following two Regexes in order to get long presses to stop when releasing the buttons (see #545):

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
+     | 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 "" }}'
+     | regex_match("^\{((\"a\":\".*\"|\"t\":\d+\.\d+)(,)?){2}\}$")) else "" }}'
`

Would you mind posting your actual file or a diff for the earlier section as well?

@bryantlee
Copy link

bryantlee commented Aug 13, 2023

ikea_e1524_e1810.txt

Here's my modified file that is working - for others to use. Change the file ext when you use - github didnt allow .yaml.

@bryantlee
Copy link

bryantlee commented Aug 13, 2023

Have folks noticed long press left/right do not work? Curious if anyone has figured out a fix before I poke around. Heres the issue I think:

The ZHA action mapping for the release is:

button_left_release: [release] button_right_release: [release]

The input text indeed gets this action, but its always appended with a random number, here's some examples of mine:

{"a":"release_1349","t":1691949262.919644} {"a":"release_921","t":1691949256.610047} {"a":"release_2029","t":1691949260.01094}

So when. the button action gets compared to the mapping it always fails the conditional

- '{{ trigger_action | string in button_left_release }}' or roughly

- '{{ 'release_1349' in release }}'

I am not seeing an obvious way to fix this, wondering if anyone else does?

@2manyvcos
Copy link

2manyvcos commented Aug 13, 2023

@bryantlee I noticed the same with my STYRBAR remotes (E2001/E2002).

A dirty workaround to fix this would be to explicitely check for the release event in the line where the trigger_action variable is defined.
You should be able to use the exact same code for the E1810 button, it should be the same.

-    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_action: >
+      {%- if integration_id == "zigbee2mqtt" -%}
+        {{ trigger.event.data.new_state.state }}
+      {%- elif integration_id == "deconz" -%}
+        {{ trigger.event.data.event }}
+      {%- elif integration_id == "zha" -%}
+        {%- if trigger.event.data.command == "release" -%}
+          release
+        {%- else -%}
+          {{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
+        {%- endif -%}
+      {%- endif -%}
Full file
blueprint:
  name: Controller - IKEA E1524/E1810 TRÃ…DFRI Wireless 5-Button Remote
  description: "# Controller - IKEA E1524/E1810 TRÃ…DFRI Wireless 5-Button Remote\n\nController
    automation for executing any kind of action triggered by the provided IKEA E1524/E1810
    TRÃ…DFRI Wireless 5-Button Remote. Allows to optionally loop an action on a button
    long press.\nSupports deCONZ, ZHA, Zigbee2MQTT.\n\nAutomations created with this
    blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks)
    supported by this controller.\nHooks allow to easily create controller-based automations
    for interacting with media players, lights, covers and more.\nSee the list of
    [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1524_e1810#available-hooks)
    for additional details.\n\n\U0001F4D5 Full documentation regarding this blueprint
    is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1524_e1810).\n\n\U0001F680
    This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints)
    project**.\n\nℹ� Version 2022.08.08\n"
  source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1524_e1810/ikea_e1524_e1810.yaml
  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
          custom_value: false
          multiple: false
    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
          multiple: false
    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
          multiple: false
    action_button_left_short:
      name: (Optional) Left button short press
      description: Action to run on short left button press.
      default: []
      selector:
        action: {}
    action_button_left_long:
      name: (Optional) Left button long press
      description: Action to run on long left button press.
      default: []
      selector:
        action: {}
    action_button_left_release:
      name: (Optional) Left button release
      description: Action to run on left button release after long press.
      default: []
      selector:
        action: {}
    action_button_left_double:
      name: (Optional) Left button double press
      description: Action to run on double left button press.
      default: []
      selector:
        action: {}
    action_button_right_short:
      name: (Optional) Right button short press
      description: Action to run on short right button press.
      default: []
      selector:
        action: {}
    action_button_right_long:
      name: (Optional) Right button long press
      description: Action to run on long right button press.
      default: []
      selector:
        action: {}
    action_button_right_release:
      name: (Optional) Right button release
      description: Action to run on right button release after long press.
      default: []
      selector:
        action: {}
    action_button_right_double:
      name: (Optional) Right button double press
      description: Action to run on double 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_long:
      name: (Optional) Up button long press
      description: Action to run on long up button press.
      default: []
      selector:
        action: {}
    action_button_up_release:
      name: (Optional) Up button release
      description: Action to run on up button release after long 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_long:
      name: (Optional) Down button long press
      description: Action to run on long down button press.
      default: []
      selector:
        action: {}
    action_button_down_release:
      name: (Optional) Down button release
      description: Action to run on down button release after long 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: {}
    action_button_center_short:
      name: (Optional) Center button short press
      description: Action to run on short center button press.
      default: []
      selector:
        action: {}
    action_button_center_long:
      name: (Optional) Center button long press
      description: Action to run on long center button press.
      default: []
      selector:
        action: {}
    action_button_center_double:
      name: (Optional) Center button double press
      description: Action to run on double center button press.
      default: []
      selector:
        action: {}
    button_left_long_loop:
      name: (Optional) Left button long press - loop until release
      description: Loop the left button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_left_long_max_loop_repeats:
      name: (Optional) 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_right_long_loop:
      name: (Optional) Right button long press - loop until release
      description: Loop the right button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_right_long_max_loop_repeats:
      name: (Optional) 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_up_long_loop:
      name: (Optional) Up button long press - loop until release
      description: Loop the up button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_up_long_max_loop_repeats:
      name: (Optional) Up 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_down_long_loop:
      name: (Optional) Down button long press - loop until release
      description: Loop the down button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_down_long_max_loop_repeats:
      name: (Optional) Down 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_left_double_press:
      name: (Optional) Expose left button double press event
      description: Choose whether or not to expose the virtual double press event
        for the left button. Turn this on if you are providing an action for the left
        button double press event.
      default: false
      selector:
        boolean: {}
    button_right_double_press:
      name: (Optional) Expose right button double press event
      description: Choose whether or not to expose the virtual double press event
        for the right button. Turn this on if you are providing an action for the
        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: {}
    button_center_double_press:
      name: (Optional) Expose center button double press event
      description: Choose whether or not to expose the virtual double press event
        for the center button. Turn this on if you are providing an action for the
        center button double press event.
      default: false
      selector:
        boolean: {}
    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.0
          max: 5000.0
          unit_of_measurement: milliseconds
          mode: box
          step: 10.0
    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.0
          max: 1000.0
          unit_of_measurement: milliseconds
          mode: box
          step: 10.0
variables:
  integration: !input integration
  button_left_long_loop: !input button_left_long_loop
  button_left_long_max_loop_repeats: !input button_left_long_max_loop_repeats
  button_left_double_press: !input button_left_double_press
  button_right_long_loop: !input button_right_long_loop
  button_right_long_max_loop_repeats: !input button_right_long_max_loop_repeats
  button_right_double_press: !input button_right_double_press
  button_up_long_loop: !input button_up_long_loop
  button_up_long_max_loop_repeats: !input button_up_long_max_loop_repeats
  button_up_double_press: !input button_up_double_press
  button_down_long_loop: !input button_down_long_loop
  button_down_long_max_loop_repeats: !input button_down_long_max_loop_repeats
  button_down_double_press: !input button_down_double_press
  button_center_double_press: !input button_center_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: '{{ integration | lower }}'
  adjusted_double_press_delay: '{{ [helper_double_press_delay - helper_debounce_delay,
    100] | max }}'
  actions_mapping:
    deconz:
      button_left_short:
      - '4002'
      button_left_long:
      - '4001'
      button_left_release:
      - '4003'
      button_right_short:
      - '5002'
      button_right_long:
      - '5001'
      button_right_release:
      - '5003'
      button_up_short:
      - '2002'
      button_up_long:
      - '2001'
      button_up_release:
      - '2003'
      button_down_short:
      - '3002'
      button_down_long:
      - '3001'
      button_down_release:
      - '3003'
      button_center_short:
      - '1002'
      button_center_long:
      - '1001'
    zha:
      button_left_short:
      - press_257_13_0
      button_left_long:
      - hold_3329_0
      button_left_release:
      - release
      button_right_short:
      - press_256_13_0
      button_right_long:
      - hold_3328_0
      button_right_release:
      - release
      button_up_short:
      - Up_43_5
      - step_with_on_off_StepMode.Up_43_5
      button_up_long:
      - move_with_on_off_0_83
      - move_with_on_off_0_84
      - move_with_on_off_MoveMode.Up_84
      button_up_release:
      - stop
      - stop_with_on_off
      button_down_short:
      - step_StepMode.Down_43_5_bitmap8.0_bitmap8.0
      - Down_43_5_bitmap8.0_bitmap8.0
      - step_StepMode.Down_43_5_0_0
      button_down_long:
      - move_MoveMode.Down_84_bitmap8.0_bitmap8.0
      - move_1_84
      - move_MoveMode.Down_84_0_0
      button_down_release:
      - stop
      - stop_bitmap8.0_bitmap8.0
      - stop_0_0
      button_center_short:
      - toggle
      button_center_long:
      - press_2_0_0
    zigbee2mqtt:
      button_left_short:
      - arrow_left_click
      button_left_long:
      - arrow_left_hold
      button_left_release:
      - arrow_left_release
      button_right_short:
      - arrow_right_click
      button_right_long:
      - arrow_right_hold
      button_right_release:
      - arrow_right_release
      button_up_short:
      - brightness_up_click
      button_up_long:
      - brightness_up_hold
      button_up_release:
      - brightness_up_release
      button_down_short:
      - brightness_down_click
      button_down_long:
      - brightness_down_hold
      button_down_release:
      - brightness_down_release
      button_center_short:
      - toggle
      button_center_long:
      - toggle_hold
  button_left_short: '{{ actions_mapping[integration_id]["button_left_short"] }}'
  button_left_long: '{{ actions_mapping[integration_id]["button_left_long"] }}'
  button_left_release: '{{ actions_mapping[integration_id]["button_left_release"]
    }}'
  button_right_short: '{{ actions_mapping[integration_id]["button_right_short"] }}'
  button_right_long: '{{ actions_mapping[integration_id]["button_right_long"] }}'
  button_right_release: '{{ actions_mapping[integration_id]["button_right_release"]
    }}'
  button_up_short: '{{ actions_mapping[integration_id]["button_up_short"] }}'
  button_up_long: '{{ actions_mapping[integration_id]["button_up_long"] }}'
  button_up_release: '{{ actions_mapping[integration_id]["button_up_release"] }}'
  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_center_short: '{{ actions_mapping[integration_id]["button_center_short"]
    }}'
  button_center_long: '{{ actions_mapping[integration_id]["button_center_long"] }}'
  integrations_with_prev_event_storage:
  - zha
  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:
- platform: event
  event_type: state_changed
  event_data:
    entity_id: !input controller_entity
- platform: event
  event_type:
  - deconz_event
  - zha_event
  event_data:
    device_id: !input controller_device
condition:
- condition: and
  conditions:
  - '{%- 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"] }}'
  - '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state
    }}'
action:
- delay:
    milliseconds: !input helper_debounce_delay
- 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" -%}
        {%- if trigger.event.data.command == "release" -%}
          release
        {%- else -%}
          {{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
        {%- endif -%}
      {%- 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 "" }}'
- service: input_text.set_value
  data:
    entity_id: !input helper_last_controller_event
    value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
- choose:
  - conditions: '{{ trigger_action | string in button_left_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_left_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_left_double
            - choose:
              - conditions: []
                sequence: !input action_button_left_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_left_short
          - choose:
            - conditions: []
              sequence: !input action_button_left_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_left_short
      - choose:
        - conditions: []
          sequence: !input action_button_left_short
  - conditions: '{{ trigger_action | string in button_left_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_left_long
    - choose:
      - conditions: '{{ button_left_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_left_long_max_loop_repeats | int }}'
            sequence: !input action_button_left_long
      default: !input action_button_left_long
  - conditions:
    - '{{ trigger_action | string in button_left_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_left_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_left_release
    - choose:
      - conditions: []
        sequence: !input action_button_left_release
  - conditions: '{{ trigger_action | string in button_right_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_right_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_right_double
            - choose:
              - conditions: []
                sequence: !input action_button_right_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_right_short
          - choose:
            - conditions: []
              sequence: !input action_button_right_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_right_short
      - choose:
        - conditions: []
          sequence: !input action_button_right_short
  - conditions: '{{ trigger_action | string in button_right_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_right_long
    - choose:
      - conditions: '{{ button_right_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_right_long_max_loop_repeats | int }}'
            sequence: !input action_button_right_long
      default: !input action_button_right_long
  - conditions:
    - '{{ trigger_action | string in button_right_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_right_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_right_release
    - choose:
      - conditions: []
        sequence: !input action_button_right_release
  - conditions: '{{ trigger_action | string in button_up_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_up_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_up_double
            - choose:
              - conditions: []
                sequence: !input action_button_up_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_up_short
          - choose:
            - conditions: []
              sequence: !input action_button_up_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_up_short
      - choose:
        - conditions: []
          sequence: !input action_button_up_short
  - conditions: '{{ trigger_action | string in button_up_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_up_long
    - choose:
      - conditions: '{{ button_up_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_up_long_max_loop_repeats | int }}'
            sequence: !input action_button_up_long
      default: !input action_button_up_long
  - conditions:
    - '{{ trigger_action | string in button_up_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_up_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_up_release
    - choose:
      - conditions: []
        sequence: !input action_button_up_release
  - conditions: '{{ trigger_action | string in button_down_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_down_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_down_double
            - choose:
              - conditions: []
                sequence: !input action_button_down_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_down_short
          - choose:
            - conditions: []
              sequence: !input action_button_down_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_down_short
      - choose:
        - conditions: []
          sequence: !input action_button_down_short
  - conditions: '{{ trigger_action | string in button_down_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_down_long
    - choose:
      - conditions: '{{ button_down_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_down_long_max_loop_repeats | int }}'
            sequence: !input action_button_down_long
      default: !input action_button_down_long
  - conditions:
    - '{{ trigger_action | string in button_down_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_down_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_down_release
    - choose:
      - conditions: []
        sequence: !input action_button_down_release
  - conditions: '{{ trigger_action | string in button_center_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_center_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_center_double
            - choose:
              - conditions: []
                sequence: !input action_button_center_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_center_short
          - choose:
            - conditions: []
              sequence: !input action_button_center_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_center_short
      - choose:
        - conditions: []
          sequence: !input action_button_center_short
  - conditions: '{{ trigger_action | string in button_center_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_center_long
    - choose:
      - conditions: []
        sequence: !input action_button_center_long
ikea_e2001_e2002.yaml
blueprint:
  name: Controller - IKEA E2001/E2002 STYRBAR Remote control
  description: "# Controller - IKEA E2001/E2002 STYRBAR Remote control\n\nController
    automation for executing any kind of action triggered by the provided IKEA E2001/E2002
    STYRBAR Remote control. Allows to optionally loop an action on a button long press.\nSupports
    deCONZ, ZHA, Zigbee2MQTT.\n\nAutomations created with this blueprint can be connected
    with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks)
    supported by this controller.\nHooks allow to easily create controller-based automations
    for interacting with media players, lights, covers and more.\nSee the list of
    [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e2001_e2002#available-hooks)
    for additional details.\n\n\U0001F4D5 Full documentation regarding this blueprint
    is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e2001_e2002).\n\n\U0001F680
    This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints)
    project**.\n\nℹ️ Version 2022.08.08\n"
  source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e2001_e2002/ikea_e2001_e2002.yaml
  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
          multiple: false
          custom_value: false
    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
          multiple: false
    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
          multiple: false
    action_button_left_short:
      name: (Optional) Left button short press
      description: Action to run on short left button press.
      default: []
      selector:
        action: {}
    action_button_left_long:
      name: (Optional) Left button long press
      description: Action to run on long left button press.
      default: []
      selector:
        action: {}
    action_button_left_release:
      name: (Optional) Left button release
      description: Action to run on left button release after long press.
      default: []
      selector:
        action: {}
    action_button_left_double:
      name: (Optional) Left button double press
      description: Action to run on double left button press.
      default: []
      selector:
        action: {}
    action_button_right_short:
      name: (Optional) Right button short press
      description: Action to run on short right button press.
      default: []
      selector:
        action: {}
    action_button_right_long:
      name: (Optional) Right button long press
      description: Action to run on long right button press.
      default: []
      selector:
        action: {}
    action_button_right_release:
      name: (Optional) Right button release
      description: Action to run on right button release after long press.
      default: []
      selector:
        action: {}
    action_button_right_double:
      name: (Optional) Right button double press
      description: Action to run on double 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_long:
      name: (Optional) Up button long press
      description: Action to run on long up button press.
      default: []
      selector:
        action: {}
    action_button_up_release:
      name: (Optional) Up button release
      description: Action to run on up button release after long 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_long:
      name: (Optional) Down button long press
      description: Action to run on long down button press.
      default: []
      selector:
        action: {}
    action_button_down_release:
      name: (Optional) Down button release
      description: Action to run on down button release after long 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: {}
    button_left_long_loop:
      name: (Optional) Left button long press - loop until release
      description: Loop the left button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_left_long_max_loop_repeats:
      name: (Optional) 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_right_long_loop:
      name: (Optional) Right button long press - loop until release
      description: Loop the right button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_right_long_max_loop_repeats:
      name: (Optional) 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_up_long_loop:
      name: (Optional) Up button long press - loop until release
      description: Loop the up button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_up_long_max_loop_repeats:
      name: (Optional) Up 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_down_long_loop:
      name: (Optional) Down button long press - loop until release
      description: Loop the down button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_down_long_max_loop_repeats:
      name: (Optional) Down 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.0
          max: 5000.0
          mode: slider
          step: 1.0
    button_left_double_press:
      name: (Optional) Expose left button double press event
      description: Choose whether or not to expose the virtual double press event
        for the left button. Turn this on if you are providing an action for the left
        button double press event.
      default: false
      selector:
        boolean: {}
    button_right_double_press:
      name: (Optional) Expose right button double press event
      description: Choose whether or not to expose the virtual double press event
        for the right button. Turn this on if you are providing an action for the
        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: {}
    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.0
          max: 5000.0
          unit_of_measurement: milliseconds
          mode: box
          step: 10.0
    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.0
          max: 1000.0
          unit_of_measurement: milliseconds
          mode: box
          step: 10.0
variables:
  integration: !input integration
  button_left_long_loop: !input button_left_long_loop
  button_left_long_max_loop_repeats: !input button_left_long_max_loop_repeats
  button_left_double_press: !input button_left_double_press
  button_right_long_loop: !input button_right_long_loop
  button_right_long_max_loop_repeats: !input button_right_long_max_loop_repeats
  button_right_double_press: !input button_right_double_press
  button_up_long_loop: !input button_up_long_loop
  button_up_long_max_loop_repeats: !input button_up_long_max_loop_repeats
  button_up_double_press: !input button_up_double_press
  button_down_long_loop: !input button_down_long_loop
  button_down_long_max_loop_repeats: !input button_down_long_max_loop_repeats
  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: '{{ integration | lower }}'
  adjusted_double_press_delay: '{{ [helper_double_press_delay - helper_debounce_delay,
    100] | max }}'
  actions_mapping:
    deconz:
      button_left_short:
      - '3002'
      button_left_long:
      - '3001'
      button_left_release:
      - '3003'
      button_right_short:
      - '4002'
      button_right_long:
      - '4001'
      button_right_release:
      - '4003'
      button_up_short:
      - '1002'
      button_up_long:
      - '1001'
      button_up_release:
      - '1003'
      button_down_short:
      - '2002'
      button_down_long:
      - '2001'
      button_down_release:
      - '2003'
    zha:
      button_left_short:
      - press_257_13_0
      button_left_long:
      - hold_3329_0
      button_left_release:
      - release
      button_right_short:
      - press_256_13_0
      button_right_long:
      - hold_3328_0
      button_right_release:
      - release
      button_up_short:
      - 'on'
      button_up_long:
      - move_with_on_off_MoveMode.Up_83
      button_up_release:
      - stop_with_on_off
      button_down_short:
      - 'off'
      button_down_long:
      - move_MoveMode.Down_83_0_0
      button_down_release:
      - stop_with_on_off
    zigbee2mqtt:
      button_left_short:
      - arrow_left_click
      button_left_long:
      - arrow_left_hold
      button_left_release:
      - arrow_left_release
      button_right_short:
      - arrow_right_click
      button_right_long:
      - arrow_right_hold
      button_right_release:
      - arrow_right_release
      button_up_short:
      - 'on'
      button_up_long:
      - brightness_move_up
      button_up_release:
      - brightness_stop
      button_down_short:
      - 'off'
      button_down_long:
      - brightness_move_down
      button_down_release:
      - brightness_stop
  button_left_short: '{{ actions_mapping[integration_id]["button_left_short"] }}'
  button_left_long: '{{ actions_mapping[integration_id]["button_left_long"] }}'
  button_left_release: '{{ actions_mapping[integration_id]["button_left_release"]
    }}'
  button_right_short: '{{ actions_mapping[integration_id]["button_right_short"] }}'
  button_right_long: '{{ actions_mapping[integration_id]["button_right_long"] }}'
  button_right_release: '{{ actions_mapping[integration_id]["button_right_release"]
    }}'
  button_up_short: '{{ actions_mapping[integration_id]["button_up_short"] }}'
  button_up_long: '{{ actions_mapping[integration_id]["button_up_long"] }}'
  button_up_release: '{{ actions_mapping[integration_id]["button_up_release"] }}'
  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"]
    }}'
  integrations_with_prev_event_storage:
  - zha
  - zigbee2mqtt
  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:
- platform: event
  event_type: state_changed
  event_data:
    entity_id: !input controller_entity
- platform: event
  event_type:
  - deconz_event
  - zha_event
  event_data:
    device_id: !input controller_device
condition:
- condition: and
  conditions:
  - '{%- 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"] }}'
  - '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state
    }}'
action:
- delay:
    milliseconds: !input helper_debounce_delay
- 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" -%}
        {%- if trigger.event.data.command == "release" -%}
          release
        {%- else -%}
          {{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
        {%- endif -%}
      {%- 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 "" }}'
- service: input_text.set_value
  data:
    entity_id: !input helper_last_controller_event
    value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
- choose:
  - conditions: '{{ trigger_action | string in button_left_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_left_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_left_double
            - choose:
              - conditions: []
                sequence: !input action_button_left_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_left_short
          - choose:
            - conditions: []
              sequence: !input action_button_left_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_left_short
      - choose:
        - conditions: []
          sequence: !input action_button_left_short
  - conditions: '{{ trigger_action | string in button_left_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_left_long
    - choose:
      - conditions: '{{ button_left_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_left_long_max_loop_repeats | int }}'
            sequence: !input action_button_left_long
      default: !input action_button_left_long
  - conditions:
    - '{{ trigger_action | string in button_left_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_left_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_left_release
    - choose:
      - conditions: []
        sequence: !input action_button_left_release
  - conditions: '{{ trigger_action | string in button_right_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_right_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_right_double
            - choose:
              - conditions: []
                sequence: !input action_button_right_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_right_short
          - choose:
            - conditions: []
              sequence: !input action_button_right_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_right_short
      - choose:
        - conditions: []
          sequence: !input action_button_right_short
  - conditions: '{{ trigger_action | string in button_right_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_right_long
    - choose:
      - conditions: '{{ button_right_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_right_long_max_loop_repeats | int }}'
            sequence: !input action_button_right_long
      default: !input action_button_right_long
  - conditions:
    - '{{ trigger_action | string in button_right_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_right_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_right_release
    - choose:
      - conditions: []
        sequence: !input action_button_right_release
  - conditions: '{{ trigger_action | string in button_up_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_up_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_up_double
            - choose:
              - conditions: []
                sequence: !input action_button_up_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_up_short
          - choose:
            - conditions: []
              sequence: !input action_button_up_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_up_short
      - choose:
        - conditions: []
          sequence: !input action_button_up_short
  - conditions: '{{ trigger_action | string in button_up_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_up_long
    - choose:
      - conditions: '{{ button_up_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_up_long_max_loop_repeats | int }}'
            sequence: !input action_button_up_long
      default: !input action_button_up_long
  - conditions:
    - '{{ trigger_action | string in button_up_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_up_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_up_release
    - choose:
      - conditions: []
        sequence: !input action_button_up_release
  - conditions: '{{ trigger_action | string in button_down_short }}'
    sequence:
    - choose:
      - conditions: '{{ button_down_double_press }}'
        sequence:
        - choose:
          - conditions: '{{ trigger_action | string in states(helper_last_controller_event)
              and trigger_delta | int <= helper_double_press_delay | int }}'
            sequence:
            - service: input_text.set_value
              data:
                entity_id: !input helper_last_controller_event
                value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json
                  }}'
            - event: ahb_controller_event
              event_data:
                controller: '{{ controller_id }}'
                action: button_down_double
            - choose:
              - conditions: []
                sequence: !input action_button_down_double
          default:
          - delay:
              milliseconds: '{{ adjusted_double_press_delay }}'
          - event: ahb_controller_event
            event_data:
              controller: '{{ controller_id }}'
              action: button_down_short
          - choose:
            - conditions: []
              sequence: !input action_button_down_short
      default:
      - event: ahb_controller_event
        event_data:
          controller: '{{ controller_id }}'
          action: button_down_short
      - choose:
        - conditions: []
          sequence: !input action_button_down_short
  - conditions: '{{ trigger_action | string in button_down_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_down_long
    - choose:
      - conditions: '{{ button_down_long_loop }}'
        sequence:
        - repeat:
            while: '{{ repeat.index < button_down_long_max_loop_repeats | int }}'
            sequence: !input action_button_down_long
      default: !input action_button_down_long
  - conditions:
    - '{{ trigger_action | string in button_down_release }}'
    - '{{ not integration_id in integrations_with_prev_event_storage or last_controller_event
      | string in button_down_long }}'
    sequence:
    - event: ahb_controller_event
      event_data:
        controller: '{{ controller_id }}'
        action: button_down_release
    - choose:
      - conditions: []
        sequence: !input action_button_down_release

@bryantlee
Copy link

Ah, nice work around! I wonder if its even worth doing a PR, i dont see many changes going into this repo in recent days.

@2manyvcos
Copy link

Yes, I don‘t think so either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blueprint An issue related to a blueprint bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants