Problem with automation and sensor.sun_next_dawn

Hi, I’m new to HA and I am trying my first automations.
For example I want a shelly switch to be switched off 20 minutes after dawn.
My problem is that all negative time offsets are working as expected, but the positive don’t work.
I tried several different annotations, but the triggers do not fire at all.
Am I having a faulty reasoning, a fallacy? This is an excerpt of my automations.yaml.
Any help appreciated.
regards, Frank

- id: '1738098859726'
  alias: mi disp off -1 -300
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: '-300'
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738519526054'
  alias: mi disp off -2 -00:10:00
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: -00:10:00
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738519578963'
  alias: mi disp off -3 -00:12
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: -00:12
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738519658530'
  alias: mi disp off +1 300
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: 330
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738098674583'
  alias: mi disp off +2 +420
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: '+420'
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738098722492'
  alias: mi disp off +3 00:09:00
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: '00:09:00'
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738098762300'
  alias: mi disp off +4 +00:11:00
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: +00:11:00
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738519956390'
  alias: mi disp off +5 00:13
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: '00:13'
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single
- id: '1738520007973'
  alias: mi disp off +6 +00:15
  description: ''
  triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: +00:15
  conditions: []
  actions:
  - type: turn_off
    device_id: d5f18457f51d4d2c0369b7c88b2c56ab
    entity_id: d3f127a137c8beb44d22cbc4fa327467
    domain: switch
  mode: single

I realize you’re using a Sun Trigger but there’s a note for the Time Trigger that also applies to your situation (using a positive offset).

Important

When using a positive offset the trigger might never fire. This is due to the sensor changing before the offset is reached. For example, when using a phone alarm as a trigger, the sensor value will change to the new alarm time when the alarm goes off, which means this trigger will change to the new time as well.

sensor.sun_next_dawn reports the next dawn time and date. After dawn has occurred today, the sensor’s value will change and be tomorrow’s dawn time.

One workaround is to create a Trigger-based Template Sensor that triggers just after midnight and records the value of sensor.sun_next_dawn. If you wish, you can even offset its value immediately.

template:
  - trigger:
      - trigger: time
        at: '00:00:10'
    sensor:
      - name: Offset Dawn
        unique_id: offset_dawn_abc123
        state: "{{ (states('sensor.sun_next_dawn') | as_datetime + timedelta(seconds=330)).isoformat() }}"
        device_class: timestamp

In your automation, use a Time Trigger set to monitor the Template Sensor.

triggers:
   - trigger: time
     at: sensor.offset_dawn

Why are you not using?

trigger: sun
event: sunrise
offset: "00:20:00"

as per the docs

Hi,
thank you very much for the explanations and the proposals and even examples :grinning:
I will give it a try asap (never worked witrh templates before).

Hi,
I wrote my 1st little template and it is working like a charme.
thank you one more time.

1 Like