Simulate multi-click button with single-click button: Add wait time on each click to count final clicks after stopping

Hi!

I have multiple buttons/remotes but there’s one place I want to do more than 3 actions with the middle button of an IKEA E1810 (I’m getting a Mi Wireless Switch soon, which allows many clicks, but I’d love to make it with the E1810).

In words:

  1. I want to click the button, and allow 350ms for the next click to happen and be added to the final count. Up to 5 clicks.
  2. If no further click happens in those 350ms, the final action is executed, based on the amount of clicks that happened (1-5).

So the total automation “duration” (wait time) can vary between ~350ms and ~1750ms

Examples/options:

  1. Click - [350ms nothing happens]: Action1
  2. Click [245ms] Click [350ms nothing happens]: Action2
  3. Click [245ms] Click [335ms] Click [350ms nothing happens]: Action3
  4. Click [245ms] Click [335ms] Click [175ms] Click [350ms nothing happens]: Action4
  5. Click [245ms] Click [335ms] Click [175ms] Click [275ms] Click [350ms nothing happens]: Action5

I’ve achieved the concept of this with:

  1. Counter helper

  2. Automation to Increment Counter:

alias: E1810 Clicks
description: ''
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/E1810 LG TV/action
    payload: toggle
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.e1810_clicks
mode: single
  1. Automation to wait 1.5 seconds + count the amount of clicks within that time + reset counter
alias: E1810 Wait and count
description: ''
trigger:
  - platform: numeric_state
    entity_id: counter.e1810_clicks
    above: '0'
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 500
  - choose:
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '1'
        sequence:
          - type: toggle
            device_id: 9330500dc9cdbe9460cd4c9c2549ca47
            entity_id: light.comedor
            domain: light
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '2'
        sequence:
          - type: toggle
            device_id: cddaad70c0a8eb148b8cd3413087623f
            entity_id: light.tv_led
            domain: light
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '3'
        sequence:
          - type: toggle
            device_id: 2fc7662a6441bfcdd1ea6e5f083cb02d
            entity_id: switch.ventilador_comedor_local
            domain: switch
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '4'
        sequence:
          - service: script.music_in_office
            data: {}
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '5'
        sequence:
          - service: scene.turn_on
            data: {}
            target:
              entity_id: scene.apagar_cocina
    default: []
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.e1810_clicks
mode: single

This works pretty much okay (not foolproof), but it forces me to wait 1.5 seconds even if I click only once, or clicking 5 times very fast if I want to reach 5 clicks in 1.5 seconds

That is why I want to change the approach to “add 350ms to wait time with each click” as explained above. I’m very open to ideas on the overall concept - I’m not the first attempting this but the threads I found were old or abandoned.

PS: I’d like to avoid things like ControllerX as this is only for one remote.

Thanks a lot

I changed to one helper and just one automation to count the end result and execute the right action, using Delay and Restart mode:

  1. Counter helper
  2. Automation to Increment Counter, wait 700ms after each click (Restart mode), then Choose action based on Counter status [1-5], finally reset counter:
alias: E1810 Clicks
description: ''
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/E1810 LG TV/action
    payload: toggle
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.e1810_clicks
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 700
  - choose:
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '1'
        sequence:
          - type: toggle
            device_id: 9330500dc9cdbe9460cd4c9c2549ca47
            entity_id: light.comedor
            domain: light
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '2'
        sequence:
          - type: toggle
            device_id: cddaad70c0a8eb148b8cd3413087623f
            entity_id: light.tv_led
            domain: light
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '3'
        sequence:
          - type: toggle
            device_id: 2fc7662a6441bfcdd1ea6e5f083cb02d
            entity_id: switch.ventilador_comedor_local
            domain: switch
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '4'
        sequence:
          - service: script.music_in_office
            data: {}
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '5'
        sequence:
          - service: scene.turn_on
            data: {}
            target:
              entity_id: scene.apagar_cocina
    default: []
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.e1810_clicks
mode: restart

However, for some reason if the time between clicks matches the delay, the automation actions run twice (first and last, usually). It seems some delay in execution and counter reset might be playing with me. It shouldn’t happen though. I welcome any idea to mitigate this (as well as a completely different approach).

Cheers

The traces could be able to tell you more about which invocations are double and what caused it. I suspect the restart may not always abort the previous run quickly enough. Maybe a condition that the state must have been as expected for at least 700 msecs above the switch would detect the delay in aborting the script?

1 Like

Yeah that’s what I thought. Traces did show the actions being run but not enough time to reset the counter (restart triggered before it could). Thanks.

I guess you’re referring to the “For” section, but since it can’t be less than 1 second, it becomes too high

But you gave me an idea that seems to work! I placed the Reset Counter running In Parallel to each of the 5 actions. A bit more repetitive but hey, aparently it works (will test more).

alias: E1810 Comedor multi-click
description: |-
  1: Comedor
  2: Tele
  3: Ventilador
  4: Script music in Office
  5: Apagar cocina
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/E1810 LG TV/action
    payload: toggle
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.e1810_clicks
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 700
  - choose:
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '1'
        sequence:
          - parallel:
              - event: command
                event_data:
                  command: comedor
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.e1810_clicks
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '2'
        sequence:
          - parallel:
              - event: command
                event_data:
                  command: tele
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.e1810_clicks
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '3'
        sequence:
          - parallel:
              - type: toggle
                device_id: 2fc7662a6441bfcdd1ea6e5f083cb02d
                entity_id: switch.ventilador_comedor_local
                domain: switch
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.e1810_clicks
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '4'
        sequence:
          - parallel:
              - service: script.music_in_office
                data: {}
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.e1810_clicks
      - conditions:
          - condition: state
            entity_id: counter.e1810_clicks
            state: '5'
        sequence:
          - parallel:
              - service: scene.turn_on
                data: {}
                target:
                  entity_id: scene.apagar_cocina
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.e1810_clicks
    default: []
mode: restart

Now I just need to figure out a cooldown period after it runs completely once (eg if clicks are over the waiting time - currently 700ms - the automation rightly fires twice).
Setting a delay at the end doesn’t work since it’s in Restard mode to allow its main purpose :thinking:

Thanks for the input!

It’s quite easy to create a software multi click sequence in Node red if that is interesting.

1 Like

Thank you, good to know! I also read this could be done with ControllerX.

For now I want to avoid overhead / new addons just for this very niche use-case for 1 remote, as I’m more than happy with HA Automations but I know I’m forcing it with this (and took it as a challenge), plus most likely getting a dedicated remote that can do this natively for 10€ (WXKG01LM)

Just a learning exercise that might help someone in my situation in the future :slight_smile:

1 Like