automation:
alias: Turn on light when sun sets
trigger:
- platform: sun
event: sunset
action:
service: light.turn_on
Sun goes down and lights come on. All is well.
Then I go to frontend and manually turn the lights off. And they stays off to the next sunset. Makes perfect sense.
Now take this seemingly equivalent example:
automation:
alias: Turn on light when sun sets
trigger:
- platform: state
entity_id: sun.sun
state: below_horizon
action:
service: light.turn_on
And again, after triggering, I go to the frontend and turn lights off. But this time, after about 20-30 seconds, light turns on! Obviously, sunâs state trigger re-triggered itself.
I wonder if there are other triggers that show same behavior (retriggering)? Is it something that described somewhere?
To understand that behavior you need to understand a little bit about how the âsunâ component works in HA.
It actually updates periodically (every minute or so?) And sunset is a single discrete event that is fired only once on the first sun update after sunset.
By contrast, below_horizon is true while the sun is below the horizon, and if used as an event is fired every time sun updates.
Other components don;t really do this on the whole. A light on event fires only when the actual state changes for instance.
The difference here is that a number of the sun based state variables change consistently throughout the day, e.g. elevation, so it updates regularly for those state changes.
Thanks for pointing out from. I tried using to instead of state but still got lots of re-triggers.
I thought maybe to: on would be saying, âtrigger if the state has changed to onâ, so it would not re-trigger if it was still on (not changed to something new), but that doesnât seem to be the case (and docs say to is an alias for state: https://home-assistant.io/docs/automation/trigger/).
How would I get an automation to not trigger when it was triggered recently? (simply!)
E.g. motion sensor that reports immediately when it sees motion, but not again for 3 minutes.
I canât use the for because it wonât be âonâ for long. Iâd rather not have to set up two more automations/scripts/input_booleans to achieve this.
Is there a simple way to âdebounceâ automation triggers to avoid frequent repeats?
Thanks
I think you might be able to just write the automation using the From and the on. And then at the END of the automation put in a 3 minute delay. So the script will keep ârunningâ for 3 minutes or however long. At that point, it will be âresetâ to run again.