Close shutters if sun rises early

Hey community,

I want to automate shutters based on the expected sunrise time. I am still fairly new to home assistant. I think this should be easily possible but I am somewhat stuck with how to define the condition.

I would like to close shutters at 3:00 am if the sunrise will be before 6:30 am.

So I think the trigger would be “3:00 am” and for the condition I can maybe use the ‘next-rising’ attribute, but I don’t know how. Any support would be highly appreciated.

alias: close shutters
description: ''
mode: single
trigger:
  - platform: time
    at: '03:00:00'
condition:
  - condition: state
    entity_id: sun.sun
    attribute: next_rising
action:
  - device_id: xyz
    domain: cover
    entity_id: zyx
    type: set_position
    position: 0
trigger:
  - platform: sun
    event: sunrise
    offset: '-03:30:00'

works for me.

I suggest to use elevation and no offset. Because the “real darkness” level is more or less aligned with the elevation degree, whereas the darkness level is different with only using the offset, because the sun is rising and setting “faster” (curves) or “slower” depending on the seasons.

trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    above: '-10'

Thank you both. I want the shutters to go down at 3:00 am if (and only if) the sun will rise on the same day before 06:30 am though. How do I do this?

I would not mind using the elevation function, but I am more struggling with condition that is in the future. Is this possible?

The entity sun.sun has an attribute next_rising, so I guess you need to check against that time.

He mentioned this in is first point.

@holmalholz
You can try something like this as template condition:

as_local(as_datetime(state_attr("sun.sun", "next_rising"))) < today_at("06:30")

Great, thank you @arganto. Did not know about these template conditions, but think this should work very nicely.

I will know more in the following days, when I have collected some experience with the automation.

This is how my yaml looks like. Hope it will work:

alias: close shutters when sun rises early
description: ''
trigger:
  - platform: time
    at: '03:00:00'
condition:
  - condition: template
    value_template: >-
      as_local(as_datetime(state_attr("sun.sun", "next_rising"))) < today_at("06:30")
action:
  - device_id: xyz1
    domain: cover
    entity_id: cover.xyz1
    type: set_position
    position: 100
  - device_id: xyz2
    domain: cover
    entity_id: cover.xyz2
    type: set_position
    position: 100
  - device_id: xyz3
    domain: cover
    entity_id: cover.xyz3
    type: set_position
    position: 100
mode: single

Please compare again with the docs. {{}}

Sorry I’m a little closer confused here. What I wrote is what the visual editor gave me. If this is incorrect, would the following be the correct syntax?

alias: DFF schließen in der hellen Jahreszeit
description: ''
trigger:
  - platform: time
    at: '03:00:00'
condition:
  - condition: template
    value_template: "{{
      as_local(as_datetime(state_attr("sun.sun", "next_rising"))) <
      today_at("06:30") }}"
action:
  - device_id: e1f1245bdab2806e7ee50b9b6367b5a7
    domain: cover
    entity_id: cover.2_og_elzi_dff
    type: set_position
    position: 100
  - device_id: c22b48996ee8e222d3f8612f3ff66162
    domain: cover
    entity_id: cover.2_og_mazi_dff
    type: set_position
    position: 100
  - device_id: e63639535591c3c15d1e5f969c6245fc
    domain: cover
    entity_id: cover.2_og_schlazi_dff
    type: set_position
    position: 100
mode: single