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

var:
  cover_NAME_OF_YOUR_COVER: #Replace NAME_OF_YOUR_COVER with the entity_id without cover. for exemple my entity_id is cover.bureau, the variable will be cover_bureau
    friendly_name: "NAME YOU WOULD LIKE TO USE"
    initial_value: 0
    icon: mdi:bug
  • Add Input Boolean
    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.4
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: °
    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: °
    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: °
    weather:
      name: Weather service
      selector:
        entity:
          domain: weather
    outdoor_temp:
      name: Outdoor temperature
      description: Temperature above which the shutters will close
      default: 16
      selector:
        number:
          min: 0
          max: 30
          unit_of_measurement: °C
    close_time:
      name: Closing time
      description: Duration the shutter closes (max 60s)
      default: 10
      selector:
        number:
          min: 0
          max: 60
          unit_of_measurement: s


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

mode: parallel

trigger:
  - platform: time_pattern
    minutes: "/5"
  
condition:
  condition: sun
  before: sunset
  after: sunrise

action:
  - choose:
      ##########################################################
      # close cover
      ##########################################################
      - conditions:
          - condition: template
            value_template: "{{- is_state('input_boolean.cover_manage_cover_with_sun', 'on') -}}"
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ states(weather_service) == 'partlycloudy' }}"
              - condition: template
                value_template: "{{ states(weather_service) == 'sunny' }}"
          - 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(weather_service, '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: and
          #   conditions:
          #     - condition: template
          #       value_template: "{{ states(weather_service) != 'partlycloudy' }}"
          #     - condition: template
          #       value_template: "{{ states(weather_service) != 'sunny' }}"
          - 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.
  • 09.06.2022 Remove trigger confitions and change in order to be triggerd every 5 mintues and add condition to be fired only the day
  • 09.06.2022 Clarification with the use of variable
6 Likes

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

1 Like

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

Hey @mougeat,
yes, the Sun integration is set up and the Blueprint config looks good to me:

Any ideas?

Hy Sorry but I do not understand the problem. I have the same installation and it is working fine

Hello I am using the blue print and I also have install the variable via haces but I have the next error:

Unable to find service var.set

What can I do?

Thanks

Hello,

you will have to install GitHub - snarky-snark/home-assistant-variables: A custom Home Assistant component for declaring and setting generic variable entities dynamically.

Hello, I have found the problem. You will have to remove fallowing code from the trigger :slight_smile:

 - 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"

I have changed the blueprint

1 Like

Thanks, mate!

I will try it later today and keep you posted :slight_smile:

Thanks again and have a nice, sunny day (but not sunny inside) :wink:

I love this blueprint! But, I have one problem.
My covers use a switch to go “open” or “closed”, therefor I cannot select it as the “entity” I want to control.
Is there a workaround for this?

You will have to create a templated cover

my_templated_cover:
  unique_id: my_templated_cover
  device_class: shutter
  value_template: >-
    {% if is_state('switch.cover_close', 'on') %}
      {% set state = "closed" %}
    {% elif is_state('switch.cover_open', 'on') %}
      {% set state = "open" %}
    {% endif %}

    {{ state }}
  open_cover:
    service: switch.turn_on
    entity_id: switch.cover_open
  close_cover:
    service: switch.turn_on
    entity_id: switch.cover_close
  stop_cover:
    service: switch.turn_off
    entity_id: group.switch_cover_open_close
1 Like