Manage cover with sun position (elevation and azimuth)

Explanation

I have created a blueprint that allow to manage the cover with sun position. In sommer (for me) the sun over heat my house. So I will close / open my cover regarding sun elevation, azimuth and outside temperature.

Prerequisites

You will need to instal the “variable” HACS intergartion

https://github.com/snarky-snark/home-assistant-variables

You will also have to create an Input Boolean : input_boolean.cover_manage_cover_with_sun in ordre to enable / disable the automation.

Blueprint:

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or import this Blueprint by using the forum topic / Gist URL:

https://gist.github.com/mougeat/bec9f93c723c8e7d1a9c64c2592fa471
# #Contrôle automatique des volets en fonction de la position du soleil et de la température extérieur
# #Auteur : Cyril Barthel
# #Version : 2.1
blueprint:
  # #Contrôle automatique des volets en fonction de la position du soleil et de la température extérieur
# #Auteur : Cyril Barthel
# #Version : 2.1
blueprint:
  name: sun protection
  description: close cover when sun is shining and open when stops
  domain: automation
  source_url: https://gist.github.com/mougeat/bec9f93c723c8e7d1a9c64c2592fa471
  input:
    cover_entity:
      name: cover
      selector:
        # target:
        entity:
          domain: cover
    sun_position_start:
      name: sun azimuth position start
      description: Sun azimuth. when sun is below this value, shutter could be triggered
      default: 89
      selector:
        number:
          min: 0
          max: 360
          unit_of_measurement: angle
    sun_position_end:
      name: sun azimuth position end
      description: Sun azimuth. when sun is over this value, shutter could be triggered
      default: 200
      selector:
        number:
          min: 0
          max: 360
          unit_of_measurement: angle
    sun_elevation_start:
      name: sun elevation to start
      description: Sun elevation. when sun is over this value, shutter could be triggered
      default: 32
      selector:
        number:
          min: -100
          max: 360
          unit_of_measurement: angle
    weather:
      name: Weather service
      selector:
        entity:
          domain: weather
    outdoor_temp:
      name: Outdoor temperature
      default: 16
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: °C
    close_time:
      name: Closing time
      default: 10
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: s

variables:
  cover_e: !input cover_entity
  var_e: "{{ 'var.' + cover_e[6:-2] }}"
  protection_begin: !input sun_position_start
  protection_end: !input sun_position_end
  elevation_begin: !input sun_elevation_start
  outdoor_temp: !input outdoor_temp
  actual_temp: !input weather

mode: parallel

trigger:
  - platform: template
    value_template: "{{ state_attr('sun.sun', 'azimuth') > protection_begin and state_attr('sun.sun', 'azimuth') < protection_end and state_attr('sun.sun', 'elevation') > elevation_begin }}"
    id: aktywuj
    for: "00:01:00"

  - platform: template
    value_template: "{{ (state_attr('sun.sun', 'azimuth') < protection_begin or state_attr('sun.sun', 'azimuth') > protection_end or  state_attr('sun.sun', 'elevation') < elevation_begin) }}"
    id: dezaktywuj
    for: "00:01:00"

  - platform: time_pattern
    minutes: "/5"

action:
  - choose:
      ##########################################################
      # close cover
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: template
            value_template: "{{ states(var_e) != '1' }}"
          - condition: template
            value_template: "{{ state_attr('sun.sun', 'azimuth') > protection_begin and state_attr('sun.sun', 'azimuth') < protection_end and state_attr('sun.sun', 'elevation') > elevation_begin }}"
          - condition: template
            value_template: "{{ state_attr(actual_temp, 'temperature') > outdoor_temp }}"
        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
            service: cover.close_cover
          - delay:
              seconds: !input "close_time"
          - data_template:
              entity_id: "{{ cover_e }}"
            service: cover.stop_cover
          - condition: template
            value_template: "{{ states(cover_e) == 'closed' }}"
          - data:
              entity_id: "{{ var_e }}"
              value: 1
            service: var.set

      ##########################################################
      # open cover
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: template
            value_template: "{{ states(var_e) == '1' }}"
          - condition: template
            value_template: "{{ (state_attr('sun.sun', 'azimuth') < protection_begin or state_attr('sun.sun', 'azimuth') > protection_end or  state_attr('sun.sun', 'elevation') < elevation_begin) }}"

        sequence:
          - data_template:
              entity_id: "{{ cover_e }}"
            service: cover.open_cover
          - condition: template
            value_template: "{{ states(cover_e) == 'open' }}"
          - data:
              entity_id: "{{ var_e }}"
              value: 0
            service: var.set


Changelog

  • 27.03.2022 : Initial version
  • 28.03.2022 : add Time to close, add condition to check if the cover close or open, because my cover loose often connection.
1 Like

Hello,

Thx for works :slightly_smiling_face:

The blueprint is link to Sky Shark but we can"t create new account on it. Which alternate to it ?

Hi The link is for the HACS Integration you will need to install. You will have to click on the “Import Blueprint” button

thanks for that job
how do you find the value sun position start, sun position end, sun elevation to start

Hello omolko

I have used two options :

  1. You wait until the sun is at the right position and you check the value in HA sun.sun

  2. you use this application https://app.photoephemeris.com/join

I think you can find other services on the web to find the sun elevation and azimuth

thanks for reply so quickly.
I don’t understand the 3 value I have to put
sun position start
sun position end
sun elevation to start
On the photos this value will be fine with the south cover I had but it daesn’t trigger

sorry that was not clear enough

I have updated the blue print

sun position start : is the azimuth above which you want to close the shutter
sun position end : is the azimuth below which you want the shutter to be closed
sun elevation to start : is the elevationabove which you want to close the shutter

In you picture, if you want to close the shutter at sun position 1:03PM today
sun position start : 161.41
sun position end : 180 (supposition)
sun elevation to start : 62.07

Hey there, thanks for the Job.

I am curious if anyone else is getting an error when trying this template?

Did I maybe forget anything?

Template was imported via GitHub link, the Button on this page did not work for me. HACS is installed and so is the home-assistant-variables integration.

Thanks for your Help :slight_smile:

Same Here :slight_smile:

Hello

Did you install the sun integration?
Could you share a printscreen of you blueprint config?

Yes
image

I have the same problem.

Home Assistant Core 2022.5.3

Home Assistant Supervisor 2022.05.1

Home Assistant OS 7.6

Kernel version 5.10.103-v8

Agent version 1.2.1

HACS Installed Version 1.24.5

I’m new in HA, so I did not find a solution.

Thanks for your Help,

Harry