284 lines
10 KiB
YAML
284 lines
10 KiB
YAML
# =============================================================================
|
|
# Multi-Sensor Alarm & Notification Blueprint
|
|
# =============================================================================
|
|
# This blueprint monitors multiple binary sensors and triggers:
|
|
# - Push notifications when sensors activate
|
|
# - Alarm device control (with configurable melody and volume)
|
|
#
|
|
# Features:
|
|
# - Per-sensor custom notification messages
|
|
# - Debounce timer to prevent false alarms from brief sensor triggers
|
|
# - Optional melody and volume selection for alarm devices
|
|
# - Automatic alarm turn-off when all sensors clear
|
|
# =============================================================================
|
|
|
|
blueprint:
|
|
name: "Custom: Multi-Sensor Alarm & Notification"
|
|
description: >
|
|
Triggers notifications and alarm actions when any of the configured binary sensors
|
|
change to "on". Supports per-sensor notification texts, optional alarm switch,
|
|
melody and volume selectors.
|
|
domain: automation
|
|
|
|
input:
|
|
# -------------------------------------------------------------------------
|
|
# Sensor Configuration
|
|
# -------------------------------------------------------------------------
|
|
devices:
|
|
name: "Devices"
|
|
collapsed: false
|
|
input:
|
|
binary_sensors:
|
|
name: Binary Sensors
|
|
description: List of binary sensors or input booleans to monitor for alarm triggers
|
|
selector:
|
|
entity:
|
|
domain:
|
|
- binary_sensor
|
|
- input_boolean
|
|
multiple: true
|
|
|
|
binary_sensors_debounce_duration:
|
|
name: Sensor Debounce Duration
|
|
description: >
|
|
Minimum time a sensor must stay ON before triggering an alarm.
|
|
Helps prevent false alarms from brief or spurious sensor activations.
|
|
default: 5
|
|
selector:
|
|
number:
|
|
min: 0
|
|
max: 30
|
|
unit_of_measurement: seconds
|
|
|
|
# -------------------------------------------------------------------------
|
|
# Notification Configuration
|
|
# -------------------------------------------------------------------------
|
|
notification:
|
|
name: "Notification"
|
|
collapsed: false
|
|
input:
|
|
notify_target:
|
|
name: Notification Target (optional)
|
|
description: >
|
|
Notify entity to send notifications (e.g., notify.mobile_app_phone).
|
|
Leave empty to disable notifications.
|
|
default:
|
|
selector:
|
|
entity:
|
|
domain: notify
|
|
|
|
notify_texts:
|
|
name: Notification Messages
|
|
description: >
|
|
Custom message for each sensor (one per line, in same order as sensor list).
|
|
If a sensor doesn't have a corresponding message, a default will be used.
|
|
default: []
|
|
selector:
|
|
text:
|
|
multiple: true
|
|
|
|
# -------------------------------------------------------------------------
|
|
# Alarm Device Configuration
|
|
# -------------------------------------------------------------------------
|
|
alarm_group:
|
|
name: "Alarm"
|
|
collapsed: false
|
|
input:
|
|
alarm_switch:
|
|
name: Alarm Switch (optional)
|
|
description: Switch entity to control the alarm device. Leave empty to disable alarm control.
|
|
default: []
|
|
selector:
|
|
entity:
|
|
domain: switch
|
|
multiple: false
|
|
|
|
melody_select:
|
|
name: Melody Selector (optional)
|
|
description: Select entity for choosing alarm melody/ringtone
|
|
default: []
|
|
selector:
|
|
entity:
|
|
domain:
|
|
- input_select
|
|
- select
|
|
multiple: false
|
|
|
|
melody_id:
|
|
name: Melody Value
|
|
description: The melody/ringtone option to select when alarm triggers
|
|
default: ""
|
|
selector:
|
|
text:
|
|
|
|
volume_select:
|
|
name: Volume Selector (optional)
|
|
description: Select entity for choosing alarm volume level
|
|
default: []
|
|
selector:
|
|
entity:
|
|
domain:
|
|
- input_select
|
|
- select
|
|
multiple: false
|
|
|
|
volume_id:
|
|
name: Volume Value
|
|
description: The volume level option to select when alarm triggers
|
|
default: ""
|
|
selector:
|
|
text:
|
|
|
|
# Restart mode ensures rapid sensor changes are handled cleanly
|
|
mode: restart
|
|
|
|
# =============================================================================
|
|
# Triggers
|
|
# =============================================================================
|
|
trigger:
|
|
# Sensor turned ON and stayed on for the debounce duration
|
|
- platform: state
|
|
entity_id: !input binary_sensors
|
|
to: "on"
|
|
for:
|
|
seconds: !input binary_sensors_debounce_duration
|
|
id: "sensor_on"
|
|
|
|
# Sensor turned OFF (for turning off alarm when all clear)
|
|
- platform: state
|
|
entity_id: !input binary_sensors
|
|
to: "off"
|
|
id: "sensor_off"
|
|
|
|
# =============================================================================
|
|
# Variables
|
|
# =============================================================================
|
|
variables:
|
|
# Input references
|
|
binary_sensors: !input binary_sensors
|
|
notify_target: !input notify_target
|
|
notify_texts: !input notify_texts
|
|
alarm_switch: !input alarm_switch
|
|
melody_select: !input melody_select
|
|
melody_id: !input melody_id
|
|
volume_select: !input volume_select
|
|
volume_id: !input volume_id
|
|
|
|
# Computed state values
|
|
enabled_sensors: "{{ binary_sensors | select('is_state', 'on') | list }}"
|
|
is_any_sensor_on: "{{ enabled_sensors | length > 0 }}"
|
|
|
|
# Small delay between setting melody/volume to ensure device processes each command
|
|
delay_between_commands_ms: 100
|
|
|
|
# Debug flag - set to true to enable persistent notifications for troubleshooting
|
|
is_debug: false
|
|
|
|
# =============================================================================
|
|
# Actions
|
|
# =============================================================================
|
|
action:
|
|
# ---------------------------------------------------------------------------
|
|
# Debug Logging (optional)
|
|
# ---------------------------------------------------------------------------
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
value_template: "{{ is_debug }}"
|
|
sequence:
|
|
- service: persistent_notification.create
|
|
data:
|
|
title: "Alarm Notification Debug"
|
|
message: >
|
|
Trigger: {{ trigger.id }}
|
|
Entity: {{ trigger.entity_id }}
|
|
|
|
Sensors: {{ binary_sensors }}
|
|
Active: {{ enabled_sensors }}
|
|
Any On: {{ is_any_sensor_on }}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Send Notification (when sensor turns ON)
|
|
# ---------------------------------------------------------------------------
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
# Only notify if a sensor is on and notification target is configured
|
|
value_template: "{{ is_any_sensor_on and notify_target is not none }}"
|
|
sequence:
|
|
- variables:
|
|
# Get the sensor that triggered this automation
|
|
sensor: "{{ trigger.entity_id }}"
|
|
# Find index of this sensor in the list
|
|
sensor_index: >
|
|
{% set idx = binary_sensors | list %}
|
|
{{ idx.index(sensor) if sensor in idx else -1 }}
|
|
# Get custom message or use default
|
|
message: >
|
|
{% set messages = notify_texts | list %}
|
|
{% if sensor_index >= 0 and sensor_index < messages | length %}
|
|
{{ messages[sensor_index] }}
|
|
{% else %}
|
|
Alarm: {{ state_attr(sensor, 'friendly_name') | default(sensor) }} triggered
|
|
{% endif %}
|
|
|
|
- service: notify.send_message
|
|
target:
|
|
entity_id: "{{ notify_target }}"
|
|
data:
|
|
message: "{{ message }}"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Alarm Device Control
|
|
# ---------------------------------------------------------------------------
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
# Only control alarm if alarm switch is configured
|
|
value_template: "{{ alarm_switch | length > 0 }}"
|
|
sequence:
|
|
# Set melody (if configured)
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
value_template: "{{ melody_select | length > 0 and melody_id | length > 0 }}"
|
|
sequence:
|
|
- service: select.select_option
|
|
target:
|
|
entity_id: "{{ melody_select }}"
|
|
data:
|
|
option: "{{ melody_id }}"
|
|
- delay:
|
|
milliseconds: "{{ delay_between_commands_ms }}"
|
|
|
|
# Set volume (if configured)
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
value_template: "{{ volume_select | length > 0 and volume_id | length > 0 }}"
|
|
sequence:
|
|
- service: select.select_option
|
|
target:
|
|
entity_id: "{{ volume_select }}"
|
|
data:
|
|
option: "{{ volume_id }}"
|
|
- delay:
|
|
milliseconds: "{{ delay_between_commands_ms }}"
|
|
|
|
# Turn alarm ON or OFF based on sensor state
|
|
- choose:
|
|
# Any sensor active -> turn alarm ON
|
|
- conditions:
|
|
- condition: template
|
|
value_template: "{{ is_any_sensor_on }}"
|
|
sequence:
|
|
- service: switch.turn_on
|
|
target:
|
|
entity_id: "{{ alarm_switch }}"
|
|
|
|
# All sensors clear -> turn alarm OFF
|
|
default:
|
|
- service: switch.turn_off
|
|
target:
|
|
entity_id: "{{ alarm_switch }}"
|