Toggle Switch Trigger Automation

Hi,
I am trying for a small automation to make my garage door switch to toggle. Automation should turn the switch OFF after 200ms if someone turn it ON. So I did this but it is not working. What I am doing wrong?

trigger:
platform: state
entiry_id: switch.garage_door
from: “OFF”
to: “ON”
for:
milliseconds: 200

action:
service: switch.turn_off
entity_id: switch.garage_door

you need to format your code


trigger:
platform: state
entiry_id: switch.garage_door
from: “OFF”
to: “ON”
for:
milliseconds: 200

action:
service: switch.turn_off
entity_id: switch.garage_door

1st look
you missing the some indenting

trigger:
  - platform: state
    entiry_id: switch.garage_door
    from: "OFF"
    to: "ON"
    for:
      milliseconds: 200

action:
  -  service: switch.turn_off
     entity_id: switch.garage_door

2rd those Quotes are on a mac

3rd look like you missing the spaces after the for: as the milliseconds arepart of the for:

looking again
4th qualify - its what i call it

You want 'on' and 'off' in lower case, and entity_id is mis-spelled in your trigger code. Here’s how I’d format it, with alias, description and id. The id (just a random string: I use UUID4) allows the automation tracer / debugger to work.

- alias: Garage door momentary on
  description: Turns the garage door switch off as soon as it is turned on
  id: 7a66b9b0-0e44-4687-88b2-8b6e02c7edbd

  trigger:
    - platform: state
      entity_id: switch.garage_door
      from: 'off'
      to: 'on'
      for:
        milliseconds: 200

  action:
    - service: switch.turn_off
      entity_id: switch.garage_door

If the 200ms is critical, you may be disappointed: HA isn’t necessarily that “punctual”.

But do please format your code using the </> button. See point 11 here:

I would suggest rather using a script with a delay between turning on and off. Also, what you’re describing is called a momentary button.

That’s a good idea if it’s HA that is also turning the switch on. If it’s a physical switch, the automation will be needed.

You’re right but it seems risky to have a button that needs to be controlled from more than one place to which HA will have to reach so quickly.

I was kind of assuming based on this that the existing physical button is already a momentary button (like a remote) and that one wouldn’t use that and e.g. a button in HA at the same time.

Thanks for your help. Issue is fixed after i added the missing - before platform and service.

Thanks for your help! 200ms don’t need to be accurate for my case. I just need automation to turn it OFF after few seconds. It is working great with your script.

1 Like

I have a physical push button. But it doesn’t look like the button and HA are coming each others way.
Script is working great now after I modified it as suggested by myle & Troon above.

1 Like