Sunrise automation weekdays differentiation

Hi all,

I have built some automation for opening of coversin relation to sunrise with
an offset very simple.

Now I would like to improve this and differentiate if it is weekdays or weekend.

I tried the following, which give me errors.

- alias: "Sunrise - Open Cover"
    platform: sun
    event: sunrise
    offset: >
    {% if now().weekday() in (0,1,2,3,4) %}
    {% else %}
    {% endif %}

  action: ...

So I hope someone can help me and guide into the right direction to be able to open the covers later in the wekeend to not wake up by opening :slight_smile:

Thanks a lot!

I’m not sure if you can use a template with an event or state trigger, you might be only able to do so with a numeric state trigger. In which case you would probably have to have an if statement like the one you have, but for different solar elevations.

Of course it’s your automation, but are you sure you want to trigger this based on a fixed offset from sunrise? I don’t know where you live, but where I do the sunrise varies by 2 hours over the year, and I wouldn’t want to shades to stay down until 9am on a winter saturday versus 7am on a summer saturday. The best way to accomplish a similar effect to what you want might simply be two separate automations with days of the week conditions, even though I usually prefer to have less automations.

You cannot use a template in a trigger this way, but you could create two automations which have a condition based on the Workday Sensor.

OK thanks for feedback. I wanted to keep the automation at a minimum but if there is no other way
to realize this I will split the automation.

Or perhaps use a template sensor?

I agree with @Danymyte. Make a template sensor that indicates weather the cover should be open or close. Then trigger off the transition of that template sensor:

  platform: template
      value_template: >
        {% if now().weekday() in range(5) %}
        {% set offset = 30*60 %} #units are seconds
        {% else %}
        {% set offset = 2*60*60 %} # units are seconds
        {% endif %}
        {{ as_timestamp(now()) >= as_timestamp(states.sun.sun.attributes.next_dusk)-offset }}