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
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:
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! 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.
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.
alias: 當螢幕開啟-開啟書房燈
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.cuco_wp5_4551_switch
from: 'off'
to: 'on'
for:
milliseconds: 200
action:
- service: switch.turn_on
entity_id: switch.3f_shu_fang_deng
Modify to theese.It can work.
But I turn on Mijia Switch.
The Switch Status From Off Change to on,
Trigged about 10s~30s,It;s too slow.
I think this maybe hass-xiaomi-miot Package Issue.
But Thanks Anyway!
alias: 當螢幕開啟-開啟書房燈
description: Turns the garage door switch off as soon as it is turned on
triggers:
- entity_id:
- switch.cuco_wp5_4551_switch
from: "off"
to: "on"
trigger: state
for:
hours: 0
minutes: 0
seconds: 1
actions:
- entity_id: switch.3f_shu_fang_deng
action: switch.turn_on