Need help - shutters opening dependant on sun-rise but not before 06:30:00

Hi guys, I need help please. I want my shutters to open not earlier than 6:30 in the morning, but not when it is still dark.
I have two programs. The first is opening at 6:30 when the sun is already above horizon. This works perfect for summer.

  trigger:
  - at: 06:30:00
    platform: time
  condition:
  - after: sunrise
    condition: sun

With the second program I want to open 25 minutes prior sun rise, but not before 6:30.

  trigger:
  - event: sunrise
    offset: -00:25:00
    platform: sun
  condition:
  - after: 06:30:00
    condition: time

Currently sun rises 06:35, less 25 minutes which is 06:10. This is before 06:30 and both of the programs not firing an action.

I don´t get it sorted to work.

You haven’t posted full code so it’s difficult to comment.
Why do you want two automations doing the same things but for different times ?
This may be central to your solution
Usually when you have two triggers (ie open at 06:30 (if sun has risen) or open at sunrise (if after 06:30) you need both triggers and both conditions.

1 Like

As @Mutt said, try with two triggers and two conditions in the same automation like this:

trigger:
  - event: sunrise
    offset: -00:25:00
    platform: sun
  - at: "06:30:00"
    platform: time
condition:
  - after: "06:29:59"
    condition: time
  - after: sunrise
    condition: sun

It’s an automation, you need a condition header and condition list keys

I’m an idiot, you gave them, but using gui style, it threw me :flushed:

thank you @Mutt and @Burningstone for your fast response. I believe Burningstone´s example works. I have other automation’s with multiple triggers and conditions, but this did not come present in my mind for this occasion. Will try and report back.

Yeah, just copied his code xD

this still fails. Looking at the example that sun will rise at 06:35. The offset triggers already at 06:10 and will not meet the conditions. Nothing will happen. Still don´t get a clue how to make it smarter.

Of course nothing happens at 6:10, you said you don’t want to open them before 6:30.

Let’s say sun rises at 6:35, so the first trigger is 25 min earlier at 6:10, nothing happens because you don’t want to open before 6:30. Then at 6:30 the second trigger happens, this will fire because its after 6:29 and after sunrise.

Hi @Burningstone. This is the problem, sun rises 06:35

sunrise is rarely at a whole minute value
what are you testing and HOW are you testing ?

06:35 is just an example to simulate the problem. I have a dead time from 06:30 to 06:55 because of the offset. If sun rises at 07:00 it would work again, because it meets the 06:29 condition.

I want to open shutters in general 25 minutes prior sun rise but not earlier than 06:30.

after 06:29:59 is pointless

You should just say : -

  - after: "06:30:00

As this actually means “at or after”

The only way to incorporate the before offset into a condition is to either break this into two automations or to use templates to calculate when 25 mins before sunrise is. Are you okay with templates ?

Hi @Mutt. Never digged into templates my own. I used what I found so far :wink: From what I see it only will work with template calculations.

You still haven’t posted your full automation.
Do you think we ask because we want to steal your code ???
Believe me, we aren’t.

So give your half-information, here’s your half-answer : -

  - alias: au_sunrise_cover_way_over_complicated
    trigger: template
      value_template: >
        {% set crnttime = states('sensor.time') %}
        {% set sunrise = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
        {% set offset = -25 * 60 %}
        {% set modtime = (sunrise + offset) | timestamp_custom('%H:%M') %}
        {{ (['06:30', modtime] | max) == crnttime }}

Under the current system (pre 0.115) this will reduce your evaluations from 86,400 per day to 1,440
AND is WAAAAAY less code

what a great surprise to see some code! I was out for a couple of hours hence the delay in my response. My automation is not a secret at all, I just didn´t want to provide non essential information. I will look at your code now, not sure if I understand everything, but will try. Thank you!

I have a workday binary sensor, which means there is another program for the weekend. First the shutters will be lifted to 40% and 15 minutes later they are fully open.

- id: 4f7ae7f8e6da4376b004404e041e0916
  alias: Jalousien Lux opening workday
  description: triggered from sun but not before 06:30:00
  trigger:
  - event: sunrise
    offset: -00:25:00
    platform: sun
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'on'
  - after: 06:30:00
    condition: time
  action:
  - data:
      entity_id: group.all_covers_homematic
      position: 40
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.stop_cover
  - delay: 00:15:00
  - data:
      entity_id: group.all_covers_homematic
      position: 100
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.open_cover
  initial_state: 'true'

@outlander4000 with your automations, the “6:35” case can’t work.
Let’s follow what the automation will do with sun rising at 6:35am:

  • 6:10am : second automation will trigger
    • Check time condition : after 06:30:00 is FALSE ==> STOP
  • 6:30am : first automation will trigger
    • Check sunrise state condition : sun is below horizon ==> STOP

You will need a third automation to complete the cases when sunrise occurs after 6:30am doing this :

  • trigger:
    • event: sunrise
      platform: sun
  • condition:
    • after: 06:30:00
      condition: time

I will probably follow another approach as our lovely planet sun´s elevation / brightness is not linear and the 20 minutes offset would work currently, but not on the darkest day. On the 21st of December the sun rise is 8:00 and opening shutters 7:40 is too late for me anyway. https://www.suncalc.org/

I possibly will do two or more automations for seasons, like I have for my fountain with condition templates. This would enable me to trigger the shutters per season.

- id: '1550348476838'
  alias: Vorgarten Brunnen aus
  description: February 1st to November 15th
  trigger:
  - entity_id: sun.sun
    for: '1:00:00'
    from: above_horizon
    platform: state
    to: below_horizon
  - above: '10'
    entity_id: sensor.wind_speed
    platform: numeric_state
  condition:
  - condition: template
    value_template: '{% set n = now() %} {{ not (n.month == 11 and n.day >=16 or n.month
      == 12 and n.day <= 31 or n.month == 1 and n.day <= 31) }}

      '
  action:
  - data:
      entity_id: switch.neq0950565_2
    service: homeassistant.turn_off
  initial_state: 'true'

I want to share with you my final solution. I had to figure out that it is not a good approach using time parameters for dependencies related to the sun. Almost all required background can be found in our manuals for Sunset / Sunrise Triggers Sunset / Sunrise trigger.

I used a sun calculator of my choice to lookup some extreme scenarious to proof conditions and triggers make sense SunCalc.org

I am now using elevation angle of “-5°”, which I can combine with conditions. I have two programs for easy managing work days and weekends. This now works flawless and is exactly what I wanted to achieve

- id: 11e5a6a3749d483ca1b5d139b29f540b
  alias: Jalousien opening weekend
  description: getriggert von Sonnenstand aber nicht vor 07:00:00
  trigger:
  - at: 07:00:00
    platform: time
  - platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'
    above: '-5'
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'off'
  - condition: template
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') >= -5 }}'
  - after: 07:00:00
    condition: time
    before: 08:00:00
  action:
  - data:
      entity_id: group.all_covers_homematic
      position: 40
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.stop_cover
  - delay: 00:15:00
  - data:
      entity_id: group.all_covers_homematic
      position: 100
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.open_cover
  initial_state: true
  mode: single
- id: 4f7ae7f8e6da4376b004404e041e0916
  alias: Jalousien opening workday
  description: getriggert von Sonnenstand aber nicht vor 06:30:00
  trigger:
  - at: 06:30:00
    platform: time
  - platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'
    above: '-5'
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'on'
  - condition: template
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') >= -5 }}'
  - after: 06:30:00
    condition: time
    before: 08:00:00
  action:
  - data:
      entity_id: group.all_covers_homematic
      position: 40
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.stop_cover
  - delay: 00:15:00
  - data:
      entity_id: group.all_covers_homematic
      position: 100
    service: cover.set_cover_position
  - entity_id:
    - cover.rfy_0b0101_1
    - cover.rfy_0b0102_1
    service: cover.open_cover
  initial_state: true
  mode: single


Thanks to share your final solution! Was looking for the same integration.
Will copy/paste :wink: