Using sunrise in the automation editor

I’m a total newbie and have started using the automation editor in the Hass.io web ui. An automation I made isn’t working; I’m trying to turn on a switch if my pi reboots between sunrise & sunset and the switch is off. It occurs to me that choosing ‘before sunrise’ is looking at this morning’s sunrise. is there a way to change it to something like ‘next_sunrise’? The automation works without the ‘before sunrise’ condition.
This is what it looks like now:

- action:
  - delay: 00:03:00
  - after: sunset
    after_offset: 00:30:00
    condition: sun
  - before: sunrise
    condition: sun
  - condition: state
    entity_id: switch.chickens
    state: 'off'
  - data:
      entity_id: automation.coop_close
    service: automation.trigger
  alias: Reboot Night
  condition: []
  id: '1523244718205'
  trigger:
  - event: start
    platform: homeassistant

Is a time of day not always before the next sunrise, so such a condition would always be true?

Example:

Let’s say that on the 1st of June the sunrise is 0500 hours exactly. At 0001 hours on 1st of June, the ‘next’ sunrise is 0500 so the condition is true, and so it remains until 0459 hours.

Then when the clock ticks to 0500 the ‘next’ sunrise is 0458 hours on the 2nd of June, which we are ‘before’ so the condition remains true.

1 Like

Yes I fell into that one. So I’ll try using sun elevation like so:

- action:
  - delay: 00:03:00
  - below: '-4'
    condition: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
  - condition: state
    entity_id: switch.chickens
    state: 'off'
  - data:
      entity_id: automation.coop_close
    service: automation.trigger
  alias: Reboot Night
  condition: []
  id: '1523244718205'
  trigger:
  - event: start
    platform: homeassistant