To link two conditions in an automation

I’m having trouble with YAML. I want to link two conditions in an automation:

The roller shutter should open when it’s 7:00 AM AND sunrise. So, in summer, it should open at 7:00 AM, and in winter, only at sunrise.

The reverse: closing the roller shutter when it’s 7:00 PM OR sunset is trivial, as it can be achieved with two separate automations, but it’s not elegant:

  1. Close roller shutter at 7:00 PM
  2. Close roller shutter at sunset

Can anyone help me with a solution?

triggers:
  - trigger: time
    at: "07:00"
  - trigger: sun
    event: sunrise
conditions:
  - condition: or
    conditions: 
      - condition: and
          - condition: state
            entity_id: sensor.season
            state: summer
          - condition: time
            after: "07:00"
      - condition: and
          - condition: state
            entity_id: sensor.season
            state: winter
          - condition: sun
            after: sunrise

You will need to add this:

You will also need to determine what you want to do in spring and autumn.

7 PM is 19:00 :slight_smile:

Wait never mind, this was only for opening :slight_smile:

Just set both events as triggers then mirror those in the conditions…

triggers:
  - trigger: sun
    event: sunrise
  - trigger: time
    at: "07:00:00"
conditions:
  - condition: time
    after: "07:00"
  - condition: sun
    after: sunrise
actions:
....

This construction will make it so the actions are only executed on the later of the two triggers.

When sunrise is before 7:00, the action will be executed at 7:00.
When sunrise is after 7:00, the action will be executed at sunrise.

Hi tom_I,
Thanks for your help. The season isn’t THE deciding factor. I only mentioned it for clarification.

The crucial point is whether sunrise occurs before or after 7:00 a.m.:
If sunrise is before 7:00 a.m., the blind should open at 7:00 a.m.
If sunrise is after 7:00 a.m., the blind should open at sunrise.

Hi Didgeridrew,
That looks very good (and simple), I will test it - thank you.