Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug - zha don't work with IKEA E1812 TRÅDFRI Shortcut button [dru] #23

Open
1 task
KentGitIvar opened this issue Oct 7, 2024 · 9 comments
Open
1 task
Labels
bug Something isn't working E1812 Shortcut Button

Comments

@KentGitIvar
Copy link

Blueprint name

ikea_e1812/ikea_e1812_dru.yaml

Home Assistant Core Version

2024.9.3

Home Assistant Installation Type

Home Assistant Operating System

Description

The shortcut does not get all actions when used with zha. Change actions mapping for zha to:
zha:
button_short:
- "on"
button_long:
- "move_with_on_off_MoveMode.Up_83"
button_release:
- "stop_with_on_off"
button_double:
- "off"
Solved it for me.

Automation YAML config

blueprint:
  homeassistant:
    min_version: 2023.6.0
  name: Controller - IKEA E1812 TRÅDFRI Shortcut button [dru]
  description:
    "# Controller - IKEA E1812 TRÅDFRI Shortcut button\n\nController automation
    for executing any kind of action triggered by the provided IKEA E1812 TRÅDFRI
    Shortcut button. 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_e1812#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_e1812).\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 - modified by removing obsolete helpers relating to calculated double press. See https://github.com/lsismeiro/awesome-ha-blueprints/issues/12#issuecomment-2018106528 \n"
  source_url: https://github.com/lsismeiro/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1812/ikea_e1812_dru.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
          sort: 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_short:
      name: (Optional) Button short press
      description: Action to run on short button press.
      default: []
      selector:
        action: {}
    action_button_long:
      name: (Optional) Button long press
      description: Action to run on long button press.
      default: []
      selector:
        action: {}
    action_button_release:
      name: (Optional) Button release
      description: Action to run on button release after long press.
      default: []
      selector:
        action: {}
    action_button_double:
      name: (Optional) Button double press
      description: Action to run on double button press.
      default: []
      selector:
        action: {}
    button_long_loop:
      name: (Optional) Button long press - loop until release
      description: Loop the button action until the button is released.
      default: false
      selector:
        boolean: {}
    button_long_max_loop_repeats:
      name: (Optional) 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_double_press:
    #   name: (Optional) Expose button double press event
    #   description:
    #     Choose whether or not to expose the virtual double press event
    #     for the button. Turn this on if you are providing an action for the 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_long_loop: !input button_long_loop
  button_long_max_loop_repeats: !input button_long_max_loop_repeats
  # button_double_press: !input button_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_short:
        - "1002"
      button_long:
        - "1001"
      button_release:
        - "1003"
    zha:
      button_short:
        - "on"
      button_long:
        - move_with_on_off_0_83
      button_release:
        - stop
    zigbee2mqtt:
      button_short:
        - "on"
      button_long:
        - brightness_move_up
      button_release:
        - brightness_stop

      #added by dru
      button_double:
        - "off"

  button_short: '{{ actions_mapping[integration_id]["button_short"] }}'
  button_long: '{{ actions_mapping[integration_id]["button_long"] }}'
  button_release: '{{ actions_mapping[integration_id]["button_release"] }}'

  #added by Dru
  button_double: '{{ actions_mapping[integration_id]["button_double"] }}'

  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" -%} {{ 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 }}'
  # - 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_short }}'
      #   sequence:
      #   - choose:
      #     - conditions: '{{ button_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_double
      #           - choose:
      #             - conditions: []
      #               sequence: !input action_button_double
      #         default:
      #         - delay:
      #             milliseconds: '{{ adjusted_double_press_delay }}'
      #         - event: ahb_controller_event
      #           event_data:
      #             controller: '{{ controller_id }}'
      #             action: button_short
      #         - choose:
      #           - conditions: []
      #             sequence: !input action_button_short
      #     default:
      #     - event: ahb_controller_event
      #       event_data:
      #         controller: '{{ controller_id }}'
      #         action: button_short
      #     - choose:
      #       - conditions: []
      #         sequence: !input action_button_short

      - conditions: "{{ trigger_action | string in button_long }}"
        sequence:
          - event: ahb_controller_event
            event_data:
              controller: "{{ controller_id }}"
              action: button_long
          - choose:
              - conditions: "{{ button_long_loop }}"
                sequence:
                  - repeat:
                      while: "{{ repeat.index < button_long_max_loop_repeats | int }}"
                      sequence: !input action_button_long
            default: !input action_button_long

      - conditions: "{{ trigger_action | string in button_release }}"
        sequence:
          - event: ahb_controller_event
            event_data:
              controller: "{{ controller_id }}"
              action: button_release
          - choose:
              - conditions: []
                sequence: !input action_button_release

     # all below are added by dru
      - conditions: "{{ trigger_action | string in button_short }}"
        sequence:
          - event: ahb_controller_event
            event_data:
              controller: "{{ controller_id }}"
              action: button_short
          - choose:
              - conditions: []
                sequence: !input action_button_short
      
      - conditions: "{{ trigger_action | string in button_double }}"
        sequence:
          - event: ahb_controller_event
            event_data:
              controller: "{{ controller_id }}"
              action: button_double
          - choose:
              - conditions: []
                sequence: !input action_button_double

To Reproduce

  1. Go to blueprint create an automation using ikea_e1812_dru with zha and do some action with button_long
  2. Click on
  3. Trigger the automation with the shortcut button_long and see nothing happens
  4. See error

Expected behavior

Action long_press and button_dubble should do the action programmed.

Actual Behaviour

Since mapping from shortcut is not correct the action for button_long, button_release don't work.
Also button_double is missing for zha.

Additional Details

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

Screenshots

No response

Additional context

No response

@KentGitIvar KentGitIvar added the bug Something isn't working label Oct 7, 2024
@LewisSpring
Copy link
Collaborator

LewisSpring commented Oct 13, 2024

Hi, thanks for reporting.
Can you test this with the original ikea_e1812 blueprint as well?
I don't have this button to test with. If both is affected I will update both. (edit:... i assume both will be(!))

@drublin - may be of interest to you

@LewisSpring LewisSpring added the E1812 Shortcut Button label Oct 13, 2024
@drublin
Copy link

drublin commented Oct 14, 2024

I can test it only next week. (after 21st oct)

Upd: i, indeed, didn't update the blueprint for zha, only for z2m, because i don't have zha to test.

@drublin
Copy link

drublin commented Oct 14, 2024

I think the reason could be the same: original blueprint (also _dru with Zha) still "calculates" the double pressaction. Later the button started sending a separate payload for the double_press.
We need somehow to test in Zha and confirm all the current payloads sent by the button. I don't have zha, sadly.

@KentGitIvar
Copy link
Author

Hi.
I have for more than a year uset a patched EPMatt ikea_e1812 version 2021.10.26.
The changes are, first original and then my changes:
zha:
button_short: ['on']
button_long: [move_with_on_off_0_83]
button_release: [stop]

zha:
button_short: ['on']
button_long: [move_with_on_off_0_83, 'move_with_on_off_MoveMode.Up_83']
button_release: [stop, stop_with_on_off]

Added the changes to the ikea_e1812 here and tested it, works as it should.
No double press works as expected.

For some reason I could not use exactly this in patch for ikea_e1812_dru but does not matter since the extra is for the old version.

Mvh Kent

@LewisSpring
Copy link
Collaborator

The @drublin blueprint (_dru) is modified from the core blueprint used elsewhere.

@KentGitIvar If you've tested these changed for a while and they're still working I'm happy to pull those in.

@KentGitIvar
Copy link
Author

I have been using those changes for several month now and for me they work well.

@LewisSpring
Copy link
Collaborator

I intend to update the Blueprint with this change, as soon as I find a spare moment.
Feel free to Pull Request it.

@LewisSpring LewisSpring added the Pending-Dev Pending some development work (or a pull request) label Nov 10, 2024
@LewisSpring
Copy link
Collaborator

#27 Has been created ready for testing, if you can please.

@LewisSpring LewisSpring added Pending-Needs testing Pending testing and removed Pending-Dev Pending some development work (or a pull request) labels Nov 30, 2024
@LewisSpring
Copy link
Collaborator

Merged the mapping changes.

We need to look into the double press issue still, I understand.

@LewisSpring LewisSpring removed the Pending-Needs testing Pending testing label Dec 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working E1812 Shortcut Button
Projects
None yet
Development

No branches or pull requests

3 participants