Files
hass-blueprints/blueprints/automation/wd-close-weather-notification.yaml

144 lines
4.4 KiB
YAML

blueprint:
name: Open Windows/Doors Notification (Clean Final)
description: Notify when windows or doors are open. Triggers on weather, temperature, or manual execution. Only sends notifications if windows/doors are open.
domain: automation
input:
openings:
name: Windows & Doors
selector:
entity:
domain: binary_sensor
multiple: true
weather_sensor:
name: Weather Sensor
selector:
entity:
domain: weather
multiple: false
weather_trigger_states:
name: Weather Trigger States (comma-separated)
default: storm,rain
selector:
text: {}
temperature_sensor:
name: Temperature Sensor
selector:
entity:
domain:
- sensor
- weather
device_class: temperature
temp_above:
name: Notify if Temperature Above
default: 22
selector:
number:
min: -50
max: 50
unit_of_measurement: °C
temp_below:
name: Notify if Temperature Below
default: 17
selector:
number:
min: -50
max: 50
unit_of_measurement: °C
notify_service:
name: Notification Service
default: notify.notify
selector:
text: {}
custom_message:
name: Custom Message Template
default: "{{ entity_name }} is open! Trigger: {{ trigger_info }}"
selector:
text: {}
trigger:
- platform: state
entity_id: !input weather_sensor
- platform: numeric_state
entity_id: !input temperature_sensor
above: !input temp_above
- platform: numeric_state
entity_id: !input temperature_sensor
below: !input temp_below
action:
- variables:
# Inputs
openings_list: !input openings
weather_sensor_id: !input weather_sensor
temperature_sensor_id: !input temperature_sensor
raw_weather_states: !input weather_trigger_states
notify_service_name: !input notify_service
message_template: !input custom_message
temp_above_threshold: !input temp_above
temp_below_threshold: !input temp_below
# Process weather states
weather_states: "{{ raw_weather_states.split(',') | map('trim') | list }}"
# Current weather and temperature
current_weather: >
{% if states(weather_sensor_id) is not none %}
{{ states(weather_sensor_id).state }}
{% else %}
unknown
{% endif %}
current_temperature: >
{% if states(temperature_sensor_id) is not none %}
{{ states(temperature_sensor_id).state }}
{% else %}
unknown
{% endif %}
# Detect open windows/doors
open_entities: >
{% set list = [] %}
{% for ent_id in openings_list %}
{% set st = states(ent_id) %}
{% if st is not none and st.state == 'on' %}
{% set _ = list.append(st.attributes.friendly_name | default(ent_id)) %}
{% endif %}
{% endfor %}
{{ list }}
# Determine trigger info for message
trigger_info: >
{% if trigger.platform == 'state' and trigger.entity_id == weather_sensor_id %}
Weather: {{ current_weather }}
{% elif trigger.platform == 'numeric_state' and trigger.entity_id == temperature_sensor_id %}
Temperature: {{ current_temperature }}°C
{% else %}
Manual trigger
{% endif %}
# Filter conditions
weather_match: >
{% if trigger.platform == 'state' and trigger.entity_id == weather_sensor_id %}
{{ current_weather in weather_states }}
{% else %}
true
{% endif %}
temperature_match: >
{% if trigger.platform == 'numeric_state' and trigger.entity_id == temperature_sensor_id %}
{{ (trigger.to_state.state | float >= temp_above_threshold) or (trigger.to_state.state | float <= temp_below_threshold) }}
{% else %}
true
{% endif %}
- choose:
- conditions:
- condition: template
value_template: "{{ open_entities | count > 0 and weather_match and temperature_match }}"
sequence:
- service: "{{ notify_service_name }}"
data:
message: >
{{ message_template
| replace('{{ entity_name }}', open_entities | join(', '))
| replace('{{ trigger_info }}', trigger_info)
}}