Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save max-scopp/822bc9acf7ae1771e70cd5de898f103c to your computer and use it in GitHub Desktop.
Save max-scopp/822bc9acf7ae1771e70cd5de898f103c to your computer and use it in GitHub Desktop.
blueprint:
name: "Sunlight Based Shutter Control"
description: >
Adjust shutters based on the time of day and their current position.
Between sunrise and sunset, if the average current position is below the target percentage, the shutters will be set to that target.
Outside these hours (between sunset and sunrise), the shutters are fully closed.
domain: automation
input:
shutters:
name: Shutters
description: "Select the shutters to control (entities from the cover domain)."
selector:
target:
entity:
domain: cover
target_percentage:
name: Target Percentage
description: >
The percentage to which the shutters should be opened between sunrise and sunset,
if the average current position is below this value.
default: 75
selector:
number:
min: 0
max: 100
unit_of_measurement: "%"
check_interval:
name: Check Interval (minutes)
description: "How often (in minutes) to check and adjust the shutters."
default: 5
selector:
number:
min: 1
max: 60
trigger:
- platform: time_pattern
minutes: "/{{ check_interval }}"
condition: []
action:
- choose:
# Branch for when the sun is up and the average shutter position is below the target.
- conditions:
- condition: sun
after: sunrise
before: sunset
- condition: template
value_template: >
{% set shutter_entities = expand(shutters) %}
{% set positions = shutter_entities
| map(attribute='attributes.current_position')
| select('is_number') | list %}
{% if positions|length == 0 %}
false
{% else %}
{{ (positions | sum / positions|length) < target_percentage }}
{% endif %}
sequence:
- service: cover.set_cover_position
data:
position: "{{ target_percentage }}"
target: !input shutters
# Branch for when the sun is down (i.e. between sunset and sunrise) to fully close shutters.
- conditions:
- condition: template
value_template: "{{ states.sun.sun.state != 'above_horizon' }}"
sequence:
- service: cover.close_cover
target: !input shutters
default: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment