Automatically open and close Curtains and Blinds at Sunrise, Sunset or any other time

I used to think that automating my curtains and blinds was a bit of a gimmick, but now that I've automated my curtains and blinds to close at sunset I've totally changed my mind.

Home Assistant includes a Sun integration that allows you to trigger automations in relation to the sunrise and sunset time, meaning that you don't need to update them as the season's change. There's just something magical about the blinds automatically closing and the lights fading in as the sun goes down outside.

In this example I will show you an automation that lowers a blind 10 minutes before sunset, but it can be easily adapted to open a curtain at sunrise or any other time of the day.

To create this automation you will need:

  1. A working Home Assistant installation

  2. Some automated curtain or blind controllers set up in Home Assistant as Cover entities

Trigger

This automation is triggered 10 minutes before sunset each day using the Sun trigger. I make use of the Offset parameter as well, which you can enter in the formation HH:MM:SS (HH = Two digit hour, MM = Two digit minutes, SS = two digit seconds)

I use an offset of "-00:10:00" which is minus ten minutes, or ten minutes BEFORE sunset. If you did "+00:10:00" then this automation would trigger 10 minutes after sunset, or "-01:00:00" would trigger 1 hour before sunset.

Screenshot of Home Assistant automation trigger showing the sun trigger with an offset of ten minutes.

Changing the event to Sunrise would trigger the automation 10 minutes before the sun rises.

If you wanted to trigger this automation at the same time each day, regardless of what the sun is doing, you can use the Time trigger type.

Screenshot of Home Assistant time trigger that will trigger the automation at 7 am

Here is the sunset automation trigger in YAML format:

platform: sun
event: sunset
offset: '-00:10:00'

Condition

I do not use a condition in this automation, but you could easily add a sun or Time condition that allows this to only run on weekdays or a state trigger that allows it to only run if people are at home.

Action

This automation uses a Service call action to call the cover.close service. A cover in Home Assistant is any curtain, blind, awning or garage door device. This will then close the blind, curtain or whatever you have chosen as the target entity.

Screenshot of Home Assistant showing the action that closes the blind using the cover.close service

I've added a few extra steps to my automation to make it also turn on the lights if we are home.

The next part of the action is a condition action. This condition will check if the residents are home or away, and if they are home continue on with the automation actions to turn on the light.

Screenshot of Home Assistant showing the condition that checks if people are home or not.

Then the Call Service action calls the Light Turn On service and fades in the bedroom light to 80% brightness over 10 seconds.

Screenshot showing the turn on light action in a home assistant automation.

And that's all there is to it! You can easily adapt this automation to open or close different curtains and blinds at different times of the day. You can also add more actions together so that lots of different things happen at sunrise or sunset.

Full automation in YAML

alias: 'Blind: Close bedroom blind at sunset and turn on bed head light'
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '-00:10:00'
condition: []
action:
  - service: cover.close_cover
    target:
      entity_id: cover.bedroom_blind_motor
  - condition: state
    entity_id: group.residents
    state: home
  - service: light.turn_on
    target:
      device_id: 0de04fa9b5cbac5626d4a8241d73ee22
    data:
      transition: 10
      color_temp: 375
      brightness_pct: 80
mode: single
Previous
Previous

Automatically close the Curtains when the TV turns on

Next
Next

Use a Hue Dimmer Switch to Open and Close Blinds and Curtains via a Home Assistant Automation