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 - Double-press triggers when any 2 buttons are pressed within the double-press delay #643

Open
1 task done
danleongjy opened this issue Jan 6, 2025 · 0 comments · May be fixed by #676
Open
1 task done

Bug - Double-press triggers when any 2 buttons are pressed within the double-press delay #643

danleongjy opened this issue Jan 6, 2025 · 0 comments · May be fixed by #676
Labels
blueprint An issue related to a blueprint bug Something isn't working

Comments

@danleongjy
Copy link

Blueprint name

Controller - IKEA E2001/E2002 STYRBAR Remote control

Home Assistant Core Version

2024.12.5

Home Assistant Installation Type

Home Assistant Operating System

Description

When any two buttons are pressed within the double-press delay, the double-press action will trigger. Which double-press action triggers depends on which double-pressed actions are exposed and which is the second button pressed. Tested with E2001/2002, E1743, E1766, E1524/E1810.

Automation YAML config

alias: Elena's Room Controller
description: Control Elena's Room Lights, Fan, AC and Curtain
use_blueprint:
  path: EPMatt/ikea_e2001_e2002.yaml
  input:
    integration: ZHA
    controller_device: bcfa3b3429c3ad745cc8299a3d74e3d3
    helper_last_controller_event: input_text.zz_elena_s_room_lights_controller_last_event
    action_button_up_short:
      - if:
          - condition: state
            entity_id: light.elenas_room_lights
            state: "off"
        then:
          - action: script.lights_controller
            metadata: {}
            data:
              lights:
                - light.elenas_room_lights
              command: lights_on
        else:
          - action: script.lights_controller
            metadata: {}
            data:
              lights:
                - light.elenas_room_lights
              command: lights_off
    action_button_up_long:
      - if:
          - condition: numeric_state
            entity_id: light.elenas_room_lights
            attribute: brightness
            above: 127
        then:
          - repeat:
              sequence:
                - action: script.lights_controller
                  metadata: {}
                  data:
                    lights:
                      - light.elenas_room_lights
                    command: lights_darken
                - delay: 1
              while:
                - condition: template
                  value_template: >-
                    {{ 'move' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
        else:
          - repeat:
              sequence:
                - action: script.lights_controller
                  metadata: {}
                  data:
                    lights:
                      - light.elenas_room_lights
                    command: lights_brighten
                - delay: 1
              while:
                - condition: template
                  value_template: >-
                    {{ 'move' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
    action_button_down_short:
      - choose:
          - conditions:
              - condition: state
                entity_id: cover.elenas_room_curtains
                state:
                  - closed
                  - closing
            sequence:
              - action: script.cover_controller
                metadata: {}
                data:
                  cover: cover.elenas_room_curtains
                  command: cover_open
          - conditions:
              - condition: state
                entity_id: cover.elenas_room_curtains
                state:
                  - opening
            sequence:
              - action: script.cover_controller
                metadata: {}
                data:
                  cover: cover.elenas_room_curtains
                  command: cover_close
        default:
          - if:
              - condition: numeric_state
                entity_id: cover.elenas_room_curtains
                attribute: current_position
                above: 50.5
            then:
              - action: script.cover_controller
                metadata: {}
                data:
                  cover: cover.elenas_room_curtains
                  command: cover_close
            else:
              - action: script.cover_controller
                metadata: {}
                data:
                  cover: cover.elenas_room_curtains
                  command: cover_open
    action_button_down_long:
      - if:
          - condition: state
            entity_id: automation.elenas_room_curtains_auto_control
            state: "off"
        then:
          - action: script.cover_controller
            metadata: {}
            data:
              command: cover_auto_control
              cover: cover.elenas_room_curtains
        else:
          - action: script.cover_controller
            metadata: {}
            data:
              command: cover_manual_control
              cover: cover.elenas_room_curtains
    button_up_long_loop: false
    button_up_long_max_loop_repeats: 50
    button_down_long_loop: false
    button_down_long_max_loop_repeats: 50
    action_button_left_short:
      - if:
          - condition: state
            entity_id: fan.elenas_room_fan
            state: "off"
        then:
          - action: script.fan_controller
            metadata: {}
            data:
              fan: fan.elenas_room_fan
              command: fan_on
        else:
          - action: script.fan_controller
            metadata: {}
            data:
              fan: fan.elenas_room_fan
              command: fan_off
    action_button_left_long:
      - if:
          - condition: numeric_state
            entity_id: fan.elenas_room_fan
            attribute: percentage
            above: 51
        then:
          - repeat:
              sequence:
                - action: script.fan_controller
                  metadata: {}
                  data:
                    fan: fan.elenas_room_fan
                    command: fan_slow_down
                - delay: 2
              while:
                - condition: template
                  value_template: >-
                    {{ 'hold' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
        else:
          - repeat:
              sequence:
                - action: script.fan_controller
                  metadata: {}
                  data:
                    fan: fan.elenas_room_fan
                    command: fan_speed_up
                - delay: 2
              while:
                - condition: template
                  value_template: >-
                    {{ 'hold' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
    action_button_right_short:
      - if:
          - condition: state
            entity_id: climate.elenas_room_ac
            state: "off"
        then:
          - action: script.ac_controller
            metadata: {}
            data:
              ac: climate.elenas_room_ac
              command: ac_on
        else:
          - action: script.ac_controller
            metadata: {}
            data:
              ac: climate.elenas_room_ac
              command: ac_off
    action_button_right_long:
      - if:
          - condition: numeric_state
            entity_id: climate.elenas_room_ac
            attribute: temperature
            above: 25.4
        then:
          - repeat:
              sequence:
                - action: script.ac_controller
                  metadata: {}
                  data:
                    ac: climate.elenas_room_ac
                    command: ac_colder
                - delay: 2
              while:
                - condition: template
                  value_template: >-
                    {{ 'hold' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
        else:
          - repeat:
              sequence:
                - action: script.ac_controller
                  metadata: {}
                  data:
                    ac: climate.elenas_room_ac
                    command: ac_warmer
                - delay: 2
              while:
                - condition: template
                  value_template: >-
                    {{ 'hold' in
                    states('input_text.zz_elena_s_room_lights_controller_last_event')
                    }}
    button_left_long_loop: false
    button_left_long_max_loop_repeats: 50
    button_right_long_loop: false
    button_right_long_max_loop_repeats: 50
    action_button_up_double:
      - action: script.lights_controller
        metadata: {}
        data:
          lights:
            - light.elenas_room_lights
          command: set_recommended_room_scene
    action_button_down_double:
      - action: script.lights_controller
        metadata: {}
        data:
          lights:
            - light.elenas_room_lights
          command: turn_off_room
    button_up_double_press: true
    button_down_double_press: true
    helper_double_press_delay: 700
    action_button_left_double:
      - if:
          - condition: state
            entity_id: fan.elenas_room_fan
            attribute: direction
            state: forward
        then:
          - action: script.fan_controller
            metadata: {}
            data:
              fan: fan.elenas_room_fan
              command: fan_reverse
        else:
          - action: script.fan_controller
            metadata: {}
            data:
              fan: fan.elenas_room_fan
              command: fan_forward
    action_button_right_double:
      - if:
          - condition: state
            entity_id: automation.elenas_room_fan_auto_control
            state: "on"
        then:
          - action: script.ac_controller
            metadata: {}
            data:
              ac: climate.elenas_room_ac
              command: cooling_manual_control
        else:
          - action: script.ac_controller
            metadata: {}
            data:
              ac: climate.elenas_room_ac
              command: cooling_auto_control
    button_left_double_press: true
    button_right_double_press: true
    helper_debounce_delay: 300

To Reproduce

  1. Define action_button_*_short and action_button_*_double for left, right, up, down buttons. Eg. to set an input_text helper to the value of the variable trigger_action.
  2. Set button_*_double_press to true for left, right, up, down buttons.

Expected behavior

  • When two different buttons are pressed within the helper_double_press_delay, ideally two different single press actions should be triggered. However, as the blueprint relies on restart mode to detect double-presses, only the second single press action should be triggered.
  • Double-press action should only be triggered if the same button is pressed within the helper_double_press_delay.

Actual Behaviour

Press any button then up button within the duration helper_double_press_delay. action_button_up_double will trigger. Same for any other combination of 2 buttons pressed - the double-press action associated with the second button will trigger.

Additional Details

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

Screenshots

No response

Additional context

The issue seems to be with the logic for checking for virtual double-presses. First, the old state of the input_text helper is saved to variable last_controller_event, then the input_text is updated to the new trigger_action. Finally, the check for double-press uses the condition trigger_action | string in states(helper_last_controller_event). This effectively checks that trigger_action is in itself. Changing the condition to trigger_action | string == last_controller_event seems to reflect the intended logic correctly and results in the expected behaviour.

@danleongjy danleongjy added blueprint An issue related to a blueprint bug Something isn't working labels Jan 6, 2025
@danleongjy danleongjy linked a pull request Jan 30, 2025 that will close this issue
3 tasks
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

Successfully merging a pull request may close this issue.

1 participant