Switch auto-off?

Hello there !

I have set up a fingerbot on a physical light switch on the mirror of the bathroom. Its responsability, thanks to an HA automation, is to turn the mirror’s light off when leaving the bathroom (when you turn the ceiling light off) in case you forgot it. So far so good.

My fingerbot cannot turn the mirror’s light on, it can only turn it off.

The problem is the state of the fingerbot: toggling it (turning it off or on) currently does the same action.
What I would like to do, in HA, is that when I turn it on, its state automatically gets back to off within a second, so that the only action I can do is to turn it on.

So, I wrote that automation:

alias: Switch auto-off
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.bot_7d8e
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.bot_7d8e
mode: single

It works, except… it actually triggers the button a second time. I didn’t find an action which only acts on the state, not the device itself.

Any ideas?

To be honest, I don’t understand the described behaviour / concept, anyway: What about a last triggered condition?


{{ now() - state_attr('automation.YOUR_AUTOMATION', 'last_triggered') > timedelta(seconds=3)  }}

or deploying the this variable:


{{ now() - this.attributes.last_triggered > timedelta(seconds=3)  }}

If the automation has been triggered in the last 3 seconds, the condition fails and the automation will not be executed.