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

112 lines
3.5 KiB
YAML

blueprint:
name: Open Windows/Doors Notification
description: Notify when windows or doors are open based on weather state or temperature thresholds.
domain: automation
input:
openings:
name: Windows & Doors
description: Select windows and doors to monitor
selector:
entity:
domain: binary_sensor
multiple: true
weather_sensor:
name: Weather Sensor
description: Optional weather entity to trigger notification
selector:
entity:
domain: weather
weather_trigger_states:
name: Weather Trigger States
description: Select weather states that should trigger notification
default:
- storm
- rain
selector:
text:
multiline: true
temperature_sensor:
name: Temperature Sensor
description: Optional temperature entity to trigger notification
selector:
entity:
domain:
- sensor
- weather
device_class: temperature
temp_above:
name: Notify if Temperature Above
description: Optional threshold to trigger notification
default: 22
selector:
number:
min: -50
max: 50
unit_of_measurement: °C
temp_below:
name: Notify if Temperature Below
description: Optional threshold to trigger notification
default: 17
selector:
number:
min: -50
max: 50
unit_of_measurement: °C
notify_target:
name: Notification Target
selector:
target: {}
custom_message:
name: Custom Notification Message
default: "{{ entity_name }} is open! Trigger: {{ trigger_state }}"
selector:
text: {}
trigger:
- platform: state
entity_id: !input weather_sensor
to: "{{ !input weather_trigger_states.split(',') | map('trim') | list }}"
- platform: numeric_state
entity_id: !input temperature_sensor
above: !input temp_above
- platform: numeric_state
entity_id: !input temperature_sensor
below: !input temp_below
condition:
- condition: state
entity_id: !input openings
state: 'on'
action:
- variables:
open_entities: >
{% set openings = states.binary_sensor | selectattr('entity_id', 'in', !input openings) | selectattr('state', 'eq', 'on') | map(attribute='attributes.friendly_name') | list %}
{% if openings | length > 0 %}
{{ openings }}
{% else %}
[]
{% endif %}
- if: "{{ open_entities | length > 0 }}"
then:
- service: notify.notify
data:
target: !input notify_target
message: >
{% set trigger_state = 'Unknown' %}
{% if trigger.platform == 'numeric_state' %}
{% if trigger.above is defined %}
{% set trigger_state = 'Temperature > ' + trigger.above | string %}
{% elif trigger.below is defined %}
{% set trigger_state = 'Temperature < ' + trigger.below | string %}
{% endif %}
{% elif trigger.platform == 'state' %}
{% set trigger_state = trigger.to_state.state %}
{% endif %}
{% set msg = !input custom_message | replace('{{ trigger_state }}', trigger_state) %}
{% set message_parts = [] %}
{% for entity_name in open_entities %}
{% set message_parts = message_parts + [msg | replace('{{ entity_name }}', entity_name)] %}
{% endfor %}
{{ message_parts | join("\n") }}