Sunset/sunrise or time automation trigger

Hello,

I was looking for advice about roller blind driver automation. I have it set up as close at sunset and open at sunrise. Living in Northern latitudes the nights become shorter this is not feasible. Is there a way to use sunrise/sunset as trigger or a set time whatever is latest or earliest? So sunset or 2000 whatever is earliest and sunrise or 0800 whatever is latest?

I’m sorry if this has been asked before but I was unable to find the answer with a search.

Thank you.

For the sunrise side, have two triggers: sunrise and fixed time: 0800.

Then add two conditions: sun above horizon and time later than 0759

In this way, the automation will trigger twice per day, but the conditions will only pass on the later one.

The sunset one is similar but you don’t need the conditions. Whichever happens first will cause the blinds to close, then the second will also have a cover.close_cover action, which will do nothing because they will already be closed.

2 Likes

[edited because of what @atlflyer points out below]

if someone comes in and opens/closes the shades manually in between 2000 and sunset then the second command will then re-close t. if you want that to happen, then don’t put the conditions. if you don’t want that to happen, then you need the conditions on both.

here’s the yaml for what @atlflyer described for morning.

description: ""
mode: single
trigger:
  - platform: sun
    event: sunrise
    offset: 0
  - platform: time
    at: "08:00:00"
condition:
  - condition: sun
    after: sunrise
  - condition: time
    after: "08:00:00"
action: []

2 Likes

OP indicated it should open on which ever happened latest for the sunrise case.

2 Likes

ah! you’re right. fixed. thanks!

2 Likes

thank you everyone. I’ll give these suggestions a go and mark it as solved. Thank you.

The following automation:

  • Opens the cover at sunrise or 08:00 whichever is latest.
  • Closes the cover at sunset or 20:00 whichever is earliest.
alias: Open/Close Cover at Sunrise/Sunset
description: ""
trigger:
  - platform: sun
    event: sunrise
    variables:
      is_true: "{{ now() > today_at('08:00') }}"
      mode: 'open'
  - platform: time
    at: "08:00:00"
    variables:
      is_true: "{{ is_state('sun.sun', 'above_horizon') }}"
      mode: 'open'
  - platform: sun
    event: sunset
    variables:
      is_true: "{{ now() < today_at('20:00') }}"
      mode: 'close'
  - platform: time
    at: "20:00:00"
    variables:
      is_true: "{{ is_state('sun.sun', 'below_horizon') }}"
      mode: 'close'
condition:
  - condition: template
    value_template: "{{ is_true }}"
action:
  - service: "cover.{{ mode }}_cover"
    target:
      entity_id: cover.your_cover

Each trigger has two associated variables.

  • is_true determines if an associated condition is true. For example, a Time Trigger at 08:00:00 checks if the sun has risen.
  • mode indicates which cover service call should be used, cover.open_cover or cover.close_cover.
2 Likes