One-shot triggers vs triggers that re-triggers themself

Say we have this automation:

    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.

Oh, thank you very much! Now it makes much more sense!

You can use a ‘from’ limiter though to make the retrigger onlybhappen once. See below.

https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/automation/sunrise_turnon_and_off.yaml

1 Like

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 :slight_smile:

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.