Skip to content

Instantly share code, notes, and snippets.

@mougeat
Last active September 13, 2024 15:16
Show Gist options
  • Save mougeat/bec9f93c723c8e7d1a9c64c2592fa471 to your computer and use it in GitHub Desktop.
Save mougeat/bec9f93c723c8e7d1a9c64c2592fa471 to your computer and use it in GitHub Desktop.
# #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
@fbjerggaard
Copy link

At line 70:

  var_e: "{{ 'var.' + cover_e[6:] }}"

It should probably be

  var_e: "{{ 'var.cover_' + cover_e[6:] }}"

To match what is written in the HA community forum

@fisch55
Copy link

fisch55 commented Jun 13, 2023

At line 70:

  var_e: "{{ 'var.' + cover_e[6:] }}"

It should probably be

  var_e: "{{ 'var.cover_' + cover_e[6:] }}"

To match what is written in the HA community forum

di have to change it in the blueprint? my var every time shows 0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment