#"Wait for trigger" but for the same device_id that triggered the automation

1 messages · Page 1 of 1 (latest)

manic furnace
#

Hello! I'm building one big lights automation that does an additional action on double click.
My triggers are device "toggle" action (cannot use the switch entity because the switches are in detached relay mode).

I have multiple triggers and I'd like to detect whether the same trigger was pressed again within 300ms.

My triggers look like this:

triggers:
  - domain: mqtt
    device_id: 7d261e9fcde1fa4dfc4926fb2a6dde67
    type: action
    subtype: toggle
    metadata: {}
    trigger: device
    id: toilette_light
    variables:
      trigger_device_id: 7d261e9fcde1fa4dfc4926fb2a6dde67
      actions_entity_id: light.toilette_light
  - domain: mqtt
    device_id: 4f0bf0afa2ab19ce76c5aee10f73ac6f
    type: action
    subtype: toggle
    trigger: device
    id: hallway_lights
    enabled: true
    variables:
      trigger_device_id: 4f0bf0afa2ab19ce76c5aee10f73ac6f
      actions_entity_id: light.hallway_lights

In the actions I'm using

 - wait_for_trigger:
      - domain: mqtt
        device_id: 4f0bf0afa2ab19ce76c5aee10f73ac6f <--- this shouldn't be hard coded
        type: action
        subtype: toggle
        trigger: device
    timeout:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 300
    continue_on_timeout: false

I tried using templates for dynamically setting the device_id in the wait_for_trigger but it's not supported. I'm out of ideas on how to handle this without adding a massive Choose block. What's a good way to handle this? Thanks!

abstract rivet
#

That device trigger corresponds to some entity and you can just use that

#

Not to clear what detached relay mode has to do with it

#

I suggest not using any device triggers at all

manic furnace
#

I cannot find any entity that "toggles" only a switch that is either on or off. It needs to be always on tho

abstract rivet
#

Toggle is turning a switch on and off

manic furnace
#

Basically the switch is powering a smart bulb, and it needs to be always on. This is why the switches are in detached relay mode

abstract rivet
#

You just want a trigger on any state change

manic furnace
#

Yeah it doesn't work because of the detached relay

abstract rivet
#

You're triggering on something and that thing is an entity

#

When a switch is in detached mode, it just stops controlling the load. The switch still operates

manic furnace
#

Let me try again

abstract rivet
#

Your trigger is just referring to the switch entity

manic furnace
#
  - trigger: state
    entity_id:
      - switch.studio_light_switch
    from: null
    to: null

I also tried from on to off and viceversa, it never triggers

#

If I toggle the switch from HA the power (relay) turns off

abstract rivet
#

you don't need the from: and to: there

manic furnace
#

It also doesn't show in the logbook when I press the button

manic furnace
abstract rivet
#

if you can't identify which entity is changing state when you manually toggle the switch, I suggest going to devtools -> Events and listening for state_changed to see if you can find the event

manic furnace
#

Nothing logs there

#

I pressed a bunch of times

abstract rivet
#

That's curious, as if you're actually using HA for things, you should have many state changes all the time

manic furnace
#

I got some logs for Adaptive lightings

#

But overall 90% of the devices are lights and switches

abstract rivet
#

then listen for * instead

manic furnace
#

nope, still nothing

abstract rivet
#

then there are no events in the system

#

which is like the twilight zone

manic furnace
#

I can see the events in Zigbee2MQTT but not in HA. The only triggers that works that I know of is the device trigger

#

It doesn't make this easy haha

manic furnace
#

Ok, I was able to enable experimental events in Zigbee2MQTT and now I can use an entity to trigger the automation

manic furnace
#

@abstract rivet

  - trigger: state
    entity_id:
      - event.studio_light_switch_action

works as a trigger but

  - trigger: template
    value_template: "{{ state_translated('event.studio_light_switch_action') }}"

doesn't. Any idea why?

#

{{ states('event.studio_light_switch_action') }} outputs 2025-08-22T21:27:41.777+00:00

abstract rivet
#

Because it's just a string that always evaluates to true

manic furnace
#

So even now that I have an entity I cannot use it to detect a double tap? 🥲

#

I think I found a solution, it seems to work:
First I save the current trigger state
original_trigger_state: "{{ states('event.studio_light_switch_action') }}"
Then I use the wait for template like this:
wait_template: '{{ states(trigger.to_state.entity_id) != original_trigger_state }}'

#

Seems to be working consisently. Marking as resolved. Thanks for the pointer to use entities

abstract rivet
#

Yes, that's not a bad solution. I was going to suggest something similar

#

Event entities are going to be overhauled a bit to address exactly these issues

#

There are a bunch of things that make them hard to use

#

You can use a timeout for your wait_template and then check if it completed if you want to differentiate between single and double

#

Often the events will include an event_type that already tells you if it was a single, double, triple tap and you can just use that

#

So then you use a state trigger and conditions to check the event_type

manic furnace
#

I'm running the single-click actions regardless to keep the delay as low as possible and it's working great

#

Thank you very much for your help!

abstract rivet
#

Np, glad you got it working