Automation won't fire

I trying to make a simple automation, where a switch should be turned on for 1 Minute, then turn off, then wait 20 MInutes, then repeat. Trigger is sunset. But for some reason the automation won’t start. Any hints? What am I overlooking here?

Code:

- id: '1685191263449'
  alias: Taubenabwehr
  description: Steckdose Terrasse nachs alle 20 Min für 1 Min einschalten
  trigger:
  - platform: sun
    event: sunset
    offset: 0
  condition: []
  action:
  - repeat:
      while:
      - condition: sun
        before: sunrise
      sequence:
      - type: turn_on
        device_id: 68bba5984f044753c145419080ed9adf
        entity_id: light.steckdose_terrasse
        domain: light
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
          milliseconds: 0
      - type: turn_off
        device_id: 68bba5984f044753c145419080ed9adf
        entity_id: light.steckdose_terrasse
        domain: light
      - delay:
          hours: 0
          minutes: 20
          seconds: 0
          milliseconds: 0
  mode: single

When you say it won’t start, have you checked the traces to confirm if it’s triggering and then not passing the while condition?

Unless something has changed with the sun entity my understanding is that before sunrise = midnight to sunrise.

I suspect that the automation triggers on sunset therefore before midnight and then checks the while condition and it does not pass.

If in doubt I normally use above or below horizon as this does not care about time.

I stand to be corrected here as something may have changed with sun.sun regarding the whole midnight thing.

Worth checking you traces to see what’s happening!

Here’s how I’d write that automation, assuming this is the only thing that operates that light.

With this setup, the automation is always run “instantly”, rather than having any timing or looping within it. This is better (IMO), avoiding complex logic in the action. Three triggers:

  • sunset, via below_horizon state
  • light has been on for a minute
  • light has been off for 20 minutes

The condition block prevents the light turning on before sunset, but allows the light to turn off if the sun rises whilst it is on.

- id: '1685191263449'
  alias: Taubenabwehr
  description: Steckdose Terrasse nachs alle 20 Min für 1 Min einschalten
  trigger:
    - platform: state
      entity_id: sun.sun
      to: "below_horizon"
      id: "turn_on"
    - platform: state
      entity_id: light.steckdose_terrasse
      to: "on"
      for:
        minutes: 1
      id: "turn_off"
    - platform: state
      entity_id: light.steckdose_terrasse
      to: "off"
      for:
        minutes: 20
      id: "turn_on"
  condition:
    - condition: or
      conditions:
      - condition: state
        entity_id: sun.sun
        state: "below_horizon"
      - condition: trigger
        id: "turn_off"
  action:
    - service: light.{{ trigger.id }}
      entity_id: light.steckdose_terrasse
1 Like

grafik

That’s all. It seem that it did start, but nothing happened.

Yes, it’s the only thing controlling this light. I’ll give it a try.

Thank you!