Automation trigger on sunrise but only past 8

Hi I need help to setup my automation for opening the blinds.
I want them to open on sunrise, but only if it happens past 8H.
If sunrise happens before 8H, I would want to open the blinds at 8H.

But I don’t want to open them at 8. In winter when sun rises at @9h I want the blinds to open then.

The problem seems to be delay the opening to 8 if sunrise happens before. But not always trigger at 8.
Any suggestions?

Trigger at 08:00 and then an if/then Action…
if sunrise then open blind
else wait for trigger (sunrise) and then open blinds

Something like this should work:

- alias: open blinds at sunrise but not before 8
  trigger:
    - platform: sun
      event: sunrise
    - platform: time
      at: '00:08:00'
  condition:
    - condition: state
      entity_id: yourblindsentity
      state: 'closed'
    - condition: time
      after: '00:08:00'
  action:
  ...

It triggers at sunrise or 08:00 (what happens first), if sunrise is before 08:00 it will do nothing because of the time condition.
If sunrise is past eight the state condition will prevent running the automation triggered by sunrise (replace it with your blinds entity and your state when blinds are closed)
The part to open at 09:00 is even more tricky, untested but i think it will work:

- alias: open blinds at sunrise but not before 8
  trigger:
    - platform: sun
      event: sunrise
    - platform: template
      value_template: "{{ now().hour == 8 if (3,21) <= (now().month, now().day) <= (12,21) else now().hour == 9 }}"
  condition:
    - condition: state
      entity_id: yourblindsentity
      state: 'down'
    - condition: template
      value_template: "{{ now().hour == 8 if (3,21) <= (now().month, now().day) <= (12,21) else now().hour == 9 }}"
  action:
  ...

The template renders true at eight from 21.3. to 21.12, the rest (in winter) it renders true at nine o clock.

1 Like

Instead of dates, you can also use ‘season’ sensor
There is also sun2 (hacs) which allows to control even more like dawn/dusk

I think that I didn’t explain myself so well.

What I want to do would be:
Trigger:
Sunrise → If it’s before 8:00 do nothing, else open blinds.
8:00 → If sunrise was happened before, open blinds, else do nothing.

So effectively I always want to trigger by sunrise, but delay the opening to 8h if before. But for doing the action at 8, it must have happened sunrise before.

alias: example
trigger:
  - platform: sun
    event: sunrise
    variables:
      open_cover: "{{ now().hour >= 8 }}"
  - platform: time
    at: '08:00:00'
    variables:
      open_cover: "{{ (state_attr('sun.sun', 'next_rising') | as_datetime | as_local).time() < now().time() }}"
condition:
  - "{{ open_cover }}"
  - "{{ is_state('cover.blinds', 'closed') }}"
action:
  - service: cover.open_cover
    target:
      entity_id: cover.blinds

EDIT

Correction. Change open to closed in Template Condition.

4 Likes

@SeRiusRod sorry, my fault, i didn’t read exactly and did it the other way round. Take Taras example, his templates and automations are always cutting the edge. Just to mention the date template i used is also by him.

@Taras just one question to this condition:

- "{{ is_state('cover.blinds', 'open') }}"

Doesn’t it have to check if the blinds are closed? Now the action only runs if the state of the covers is open, aren’t they closed in the moment the automation runs in the morning?
And is the condition really needed? As i understand the template condition it can only run once a day…

Nothing to be sorry! I’m always so grateful for all your help :grin:

About the open condition: yes, I implemented it the inverted way and it works, but perhaps would be better if one could check every blind one by one if it’s completely closed and try to open only the ones that are in that state. I know there’s some loop functionality into automations, but I never used it.

One checks if it’s completely closed because the sibling automation that closes them at night if temperature drops below 16 deg leaves them in that state.
If someone wants to leave one out that cycle just should leave the blind adjusted at some position.

@Taras, I’ve already implemented your solution and this morning it worked. Thank your sir.

One last thing, In my country we use to have the “textile” or venetian style of blinds on the inside but also aluminium outside blinds that are integrated in the windows.
Those later are what I’m trying to automate, and are meant to protect from sun, but also from cold and offer more security when out of home.

I’m clarifying because I recently realized that those are not common in other countries and in fact we are an exception in Europe. :+1:

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title signaling to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like

I wanted to be awake to see it in actin, but your right :+1:

Hi,

is there an easy way to have an offset (like 30 min. before sunrise)?
Im not sure with the second trigger. The first trigger should be:

  • platform: sun
    event: sunrise
    offset: “-00:30:00”
    variables:
    open_cover: “{{ now().hour >= 8 }}”
  - platform: time
    at: '08:00:00'
    variables:
      open_cover: >
        {{ (state_attr('sun.sun', 'next_rising') | as_datetime | as_local - timedelta(minutes=30)).time() < now().time() }}

Where would I put this yaml solution snippet?
I tried configuration.yaml, but I get

Integration error: trigger - Integration 'trigger' not found.
Integration error: alias - Integration 'alias' not found.
Integration error: condition - Integration 'condition' not found.
Integration error: action - Integration 'action' not found.