Service_template after 9:00 and before sunset

Hello,
If I restart home assistant I have to set the state off covers according to the rel state.
If the time is after the 9:00 and befor sunset, the cover is oppen and I have to switches accordingly…
I have the event when the home assistant start, and I have to design a service_template for covers.
I have the first part of the equation:

- service_template: >
       {% if states.sensor.time.state > '09:00' | timestamp_custom('%H:%M')%} and the missing part....
          homeassistant.turn_on
       {% else %}
          homeassistant.turn_off
       {% endif %}
      entity_id: group.livingroom_covers

Many thanks for your help, it will be very appreciated!
Best regards
Thierry

If I have understood your requirements correctly, this should do it:

- service_template: "homeassistant.turn_{{ 'on' if states('sensor.time') > '09:00' and states('sun.sun') == 'above_horizon' else 'off' }}"
  entity_id: group.livingroom_covers
1 Like

Many thanks for your help !
Regards

1 Like

You’re welcome!

Please mark my post (above) with the Solution tag. Only you the author of this topic can do that. It will automatically place a check-mark next to the topic’s title which signals to others that this topic has an accepted solution. It can also help people find answers to similar questions.

1 Like