Double-click Automation "wait_for_trigger", not working properly

I am trying to make a double click binary sensor, on single click it is supposed to activate script.kontor_kveld on double click it is supposed to activate script.kontor_vanlig

What happens is single click: 2700ms after the click “script.kontor_kveld” is triggered. This is expected behavior.

What happens on a double click: Immediately after the first click, a script is activated (expected), but the script activated is “script.kontor_kveld”, that is not excepted.

Any tips on what I am doing wrong here?

- alias: "Test dobbel"
  trigger:
    - platform: state
      entity_id: binary_sensor.kontor_dor_rt
      to: 'on'
  mode: single
  action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.kontor_dor_rt
        to: 'on'
    timeout:
      milliseconds: 2700
    continue_on_timeout: true
  - choose:
    - conditions:
#single click action if wait is over 2700ms

      - condition: template
        value_template: "{{ not wait.completed }}"
      sequence:
        - service: script.turn_on
          entity_id: script.kontor_kveld
#double click action
    default:
        - service: script.turn_on
          entity_id: script.kontor_vanlig
1 Like

I got help on this, in case anybody else has the same problem. The problem was the value_template: “{{ not wait.completed }}” it has top be exchanged with “{{ wait.remaining == 0 }}”

1 Like

Thanks for posting this! I’m playing with something similar.

I tested using notifications and wait.completed definitely doesn’t return anything for wait_for_template. The equivalent for wait_for_template would be wait.trigger

From: https://www.home-assistant.io/docs/scripts/#wait-variable

wait.completed 	Exists only after wait_template. true if the condition was met, false otherwise
wait.trigger 	Exists only after wait_for_trigger. Contains information about which trigger fired. (See Available-Trigger-Data.) Will be none if no trigger happened before timeout expired
wait.remaining 	Timeout remaining, or none if a timeout was not specified

So another option is to check for "{{ wait.trigger == None }}" instead of "{{ not wait.completed }}" or "{{ wait.remaining == 0 }}"

EDIT: Removed the single quotes around None; If you include them the test will fail.

This is great. I made a automation to turn my single button switch (Philips Hue wall switch module) in to a multi function switch with single, double and triple click.

alias: Template single, double en triple click event
description: ''
trigger:
 - platform: event
   event_type: deconz_event
   event_data:
     id: rdm001_11
     event: 1002
action:
 - wait_for_trigger:
     - platform: event
       event_type: deconz_event
       event_data:
         id: rdm001_11
         event: 1002
   timeout: 
     milliseconds: 500
   continue_on_timeout: true
 - choose:
     - conditions:
         - condition: template
           value_template: '{{ wait.trigger == none }}'
       sequence:
         - choose:
             - conditions:
# single click
                 - condition: device
                   type: is_off
                   device_id: 9b4064088a454329b50a0f19a47435af
                   entity_id: light.philips_lamp_2
                   domain: light
               sequence:
                 - type: turn_on
                   device_id: 9b4064088a454329b50a0f19a47435af
                   entity_id: light.philips_lamp_2
                   domain: light
                   brightness_pct: 50
           default:
             - type: turn_off
               device_id: 9b4064088a454329b50a0f19a47435af
               entity_id: light.philips_lamp_2
               domain: light
   default:
     - wait_for_trigger:
         - platform: event
           event_type: deconz_event
           event_data:
             id: rdm001_11
             event: 1002
       timeout:
         milliseconds: 500
       continue_on_timeout: true
# double click
     - choose:
         - conditions:
             - condition: template
               value_template: '{{ wait.trigger == none }}'
           sequence:
             - type: turn_on
               device_id: 9b4064088a454329b50a0f19a47435af
               entity_id: light.philips_lamp_2
               domain: light
               brightness_pct: 100
       default:
# triple click
         - type: toggle
           device_id: 624004bdf8444cf3bae397a5070bd03f
           entity_id: light.philips_lamp_1
           domain: light
mode: single

I hope this can help some more people.

2 Likes

Do you why that is? The documentation doesn’t really make sense here as to why "{{ not wait.completed }}" won’t work. It should right?

OK so in my case re-reading the documentation I suppose it is right since they mention that wait.completed is only applicable for when you use the wait_template while wait.trigger is available for wait_for_trigger. So i used "{{ wait.trigger is none }}" instead of the == calculation you used. Works the same way. just FYI!

Never worked for me. :frowning:

HA 2022.3.7

alias: Temp
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_a4b0004daa
    to: 'on'
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.sonoff_a4b0004daa
        to: 'on'
    timeout: '0.5'
    continue_on_timeout: true
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger == none }}'
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.sonoff_1000e2e47b_1
    default:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.sonoff_1001474224
mode: single

I did a simple automation to add a double click to a zigbee switch. The switch is a tuya wall switch module WHD02.
I can’t dissociate the input rocket wall switch connected to the device from the lamp also connected to it. So when the user pulses the rocket the light will toggle.
With this automation, a second click in less than a second, will toggle a secondary light (z_esc_2), while the primary one (z_esc), will toggle twice and remain in the original status.
To do the automation I created a helper variable entity_id: input_datetime.esc_last_click to which I assign a value (now() ) then I check the last change so, the value is not used at all.
I put the condition in the actions, not an entering condition, because I need to get in to change the helper variable.

alias: doble_click_escala
description: ""
trigger:
  - platform: device
    type: changed_states
    device_id: 0a0269d89eb833edef7659e8f648f5f4
    entity_id: switch.z_esc
    domain: switch
condition: []
action:
  - if:
      - condition: template
        value_template: >-
          {{
          (now()-states.input_datetime.esc_last_click.last_updated).total_seconds()
          <1 }}
    then:
      - type: toggle
        device_id: 7eb6058bf8d22f149ca5df859ed0b061
        entity_id: switch.z_esc2
        domain: switch
  - service: input_datetime.set_datetime
    data:
      timestamp: "{{ now().timestamp() }}"
    target:
      entity_id: input_datetime.esc_last_click
mode: single