-
-
Save thanksmister/5b50fc11860117feea83282e1ffa1b6e to your computer and use it in GitHub Desktop.
Homeassistant blueprint to close/open covers depending on sun position and weather
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: cover rain | |
description: Close cover when it rains (or other weather conditions. | |
domain: automation | |
input: | |
cover_entity: | |
name: cover | |
selector: | |
entity: | |
domain: cover | |
close_position: | |
name: Closing position of curtain | |
description: "Target position for closed curtain. Note: 100 is open!" | |
default: 0 | |
selector: | |
number: | |
min: 0 | |
max: 100 | |
open_at_time: | |
name: Opening after this time | |
description: The time the cover should open. | |
default: "07:30:00" | |
selector: | |
time: | |
close_at_time: | |
name: Opening after this time | |
description: The time the cover should open. | |
default: "19:30:00" | |
selector: | |
time: | |
close_temp: | |
name: Temperature threshold | |
description: Temperature above which the shutters will not open. | |
default: 30 | |
selector: | |
number: | |
min: 0 | |
max: 34 | |
unit_of_measurement: °C | |
open_temp: | |
name: Temperature threshold | |
description: Temperature above which the shutters will not open. | |
default: 18 | |
selector: | |
number: | |
min: 0 | |
max: 30 | |
unit_of_measurement: °C | |
temperature_entity: | |
name: Temperature source | |
default: "weather.home" | |
selector: | |
entity: | |
filter: | |
- domain: | |
- weather | |
- device_class: | |
- temperature | |
weather: | |
name: Weather service | |
default: "weather.home" | |
selector: | |
entity: | |
domain: weather | |
close_weather_conditions: | |
name: Weather conditions | |
description: Close curtain on all of the selected weather conditions (if all other conditions are met) | |
default: | |
- rainy | |
- pouring | |
- lightning-rainy | |
- hail | |
selector: | |
select: | |
multiple: true | |
options: | |
- "clear-night" | |
- "cloudy" | |
- "fog" | |
- "hail" | |
- "lightning" | |
- "lightning-rainy" | |
- "partlycloudy" | |
- "pouring" | |
- "rainy" | |
- "snowy" | |
- "snowy-rainy" | |
- "sunny" | |
- "windy" | |
- "windy-variant" | |
- "exceptional" | |
variables: | |
curtain_entity_id: !input cover_entity | |
curtain_target_position: !input close_position | |
open_at_time: !input open_at_time | |
temp_close: !input close_temp | |
temp_open: !input open_temp | |
temperature_entity_id: !input temperature_entity | |
weather_entity_id: !input weather | |
weather_close: !input close_weather_conditions | |
curtain_current_position: "{{ state_attr(curtain_entity_id, 'current_position') if state_attr(curtain_entity_id, 'current_position') is not none else state_attr(curtain_entity_id, 'position') }}" | |
current_temp: "{{ state_attr(temperature_entity_id, 'temperature') if state_attr(temperature_entity_id, 'temperature') is not none else states(temperature_entity_id) }}" | |
mode: queued # We rely on trigger changes, so 'single' and 'restart' are not possible. 'parallel' might work. | |
trigger: | |
- platform: state | |
entity_id: !input weather | |
to: !input close_weather_conditions | |
not_from: !input close_weather_conditions | |
id: t_weather_not_sunny | |
- platform: state | |
entity_id: !input weather | |
not_to: !input close_weather_conditions | |
from: !input close_weather_conditions | |
id: t_weather_sunny | |
# note: temperature_entity can either be a weather or temperature entity! | |
- platform: numeric_state | |
entity_id: !input temperature_entity | |
attribute: temperature | |
above: !input close_temp | |
id: t_temp_above_weather | |
- platform: numeric_state | |
entity_id: !input temperature_entity | |
above: !input close_temp | |
id: t_temp_above_temp | |
- platform: numeric_state | |
entity_id: !input temperature_entity | |
attribute: temperature | |
below: !input open_temp | |
id: t_temp_below_weather | |
- platform: numeric_state | |
entity_id: !input temperature_entity | |
below: !input open_temp | |
id: t_temp_below_temp | |
condition: | |
- condition: or | |
conditions: | |
# do close (when it is above curtain_target_position): | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position > curtain_target_position }}" | |
- condition: template | |
value_template: "{{ states(weather_entity_id) in weather_close }}" | |
- condition: or | |
conditions: | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position > curtain_target_position }}" | |
- condition: template | |
value_template: "{{ current_temp >= temp_close }}" | |
- condition: or | |
conditions: | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position > curtain_target_position }}" | |
- condition: template | |
value_template: "{{ now() > today_at(close_after_time) }}" | |
# do open | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position <= 100 }}" | |
- condition: template | |
value_template: "{{ now() > today_at(open_after_time) }}" | |
- condition: or | |
conditions: | |
- condition: and | |
conditions: | |
- condition: trigger | |
id: t_weather_not_sunny | |
- condition: template | |
value_template: "{{ current_temp >= temp_open }}" | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ states(weather_entity_id) in weather_close }}" | |
- condition: template | |
value_template: "{{ current_temp >= temp_open }}" | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ states(weather_entity_id) in weather_close }}" | |
- condition: template | |
value_template: "{{ current_temp >= temp_open }}" | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ states(weather_entity_id) in weather_close }}" | |
- condition: or | |
conditions: | |
- condition: trigger | |
id: t_temp_below_weather | |
- condition: trigger | |
id: t_temp_below_temp | |
action: | |
- choose: | |
# close cover | |
- conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position > curtain_target_position }}" | |
- condition: template | |
value_template: "{{ states(weather_entity_id) in weather_close }}" | |
- condition: template | |
value_template: "{{ current_temp >= temp_close }}" | |
sequence: | |
- service: cover.set_cover_position | |
data: | |
position: "{{ curtain_target_position }}" | |
target: | |
entity_id: "{{ curtain_entity_id }}" | |
# open cover (conditions are somewhat redundant here, as 'condition' is more specific..) | |
- conditions: | |
- condition: template | |
value_template: "{{ curtain_current_position <= curtain_target_position }}" | |
- condition: or | |
conditions: | |
- condition: template | |
value_template: "{{ states(weather_entity_id) not in weather_close }}" | |
- condition: template | |
value_template: "{{ current_temp < temp_close }}" | |
sequence: | |
- service: cover.set_cover_position | |
data: | |
position: 100 | |
target: | |
entity_id: "{{ curtain_entity_id }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updating blueprint to work with window motors, for opening and closing the windows based on time and weather conditions.