Add Periodic Notification blueprint
Sends notifications at specified times every N days when a control flag is enabled. Supports multiple notification targets, flexible time scheduling, and optional day interval with configurable start date. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
53
Common/Periodic Notification/README.md
Normal file
53
Common/Periodic Notification/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Periodic Notification
|
||||
|
||||
Sends notifications at specified times on a repeating day schedule, controlled by a toggle entity.
|
||||
|
||||
## Features
|
||||
|
||||
- Multiple notification targets (notify entities)
|
||||
- Customizable multiline message
|
||||
- Flexible time schedule (multiple times per day)
|
||||
- Configurable day interval (every N days)
|
||||
- On/off control via input_boolean or switch entity
|
||||
|
||||
## How It Works
|
||||
|
||||
1. The automation triggers at each configured notification time (checked every minute)
|
||||
2. It verifies the control flag entity is ON
|
||||
3. It calculates whether today falls on the correct day in the interval cycle, counting from the configured start date
|
||||
4. If all conditions pass, the message is sent to all notification targets
|
||||
|
||||
### Day Interval Calculation
|
||||
|
||||
The day interval uses a **start date** as a reference point. Notifications fire every N days from that date. For example, with a start date of January 1 and a 3-day interval, notifications fire on January 1, 4, 7, 10, and so on.
|
||||
|
||||
If no start date is set, the day interval is ignored and notifications are sent every day at the configured times.
|
||||
|
||||
Setting the day interval to **1** sends notifications every day.
|
||||
|
||||
## Configuration
|
||||
|
||||
| Input | Description |
|
||||
|---|---|
|
||||
| **Notification Targets** | One or more `notify` entities (e.g., `notify.mobile_app_phone`) |
|
||||
| **Message** | The notification text to send (supports multiline) |
|
||||
| **Notification Times** | Comma-separated times in 24-hour `HH:MM` format (e.g., `08:00, 14:30, 20:00`) |
|
||||
| **Day Interval** | Number of days between notification cycles (1 = daily) |
|
||||
| **Start Date** | Reference date for the interval calculation (optional — leave empty to send every day) |
|
||||
| **Control Flag** | `input_boolean` or `switch` entity to enable/disable notifications |
|
||||
|
||||
### Time Format
|
||||
|
||||
Times must use 24-hour format with leading zeros:
|
||||
|
||||
- `08:00` (not `8:00`)
|
||||
- `14:30`
|
||||
- `20:00`
|
||||
|
||||
### Debug Mode
|
||||
|
||||
Set the `is_debug` variable to `true` in the automation YAML to enable persistent notification logging for troubleshooting.
|
||||
|
||||
## Author
|
||||
|
||||
Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
||||
176
Common/Periodic Notification/blueprint.yaml
Normal file
176
Common/Periodic Notification/blueprint.yaml
Normal file
@@ -0,0 +1,176 @@
|
||||
# Periodic Notification
|
||||
# Sends notifications at specified times on a repeating day schedule.
|
||||
# See README.md for detailed documentation.
|
||||
#
|
||||
# Author: Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
||||
|
||||
blueprint:
|
||||
name: "Custom: Periodic Notification"
|
||||
description: >
|
||||
Sends notifications at specified times every N days when a control
|
||||
flag is enabled. Supports multiple notification targets and flexible
|
||||
scheduling.
|
||||
domain: automation
|
||||
|
||||
input:
|
||||
# -------------------------------------------------------------------------
|
||||
# Notification Configuration
|
||||
# -------------------------------------------------------------------------
|
||||
notification:
|
||||
name: "Notification"
|
||||
collapsed: false
|
||||
input:
|
||||
notify_targets:
|
||||
name: Notification Targets
|
||||
description: >
|
||||
Notify entities to send notifications to
|
||||
(e.g., notify.mobile_app_phone).
|
||||
selector:
|
||||
entity:
|
||||
domain: notify
|
||||
multiple: true
|
||||
|
||||
message:
|
||||
name: Message
|
||||
description: The notification message to send.
|
||||
selector:
|
||||
text:
|
||||
multiline: true
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Schedule Configuration
|
||||
# -------------------------------------------------------------------------
|
||||
schedule:
|
||||
name: "Schedule"
|
||||
collapsed: false
|
||||
input:
|
||||
notification_times:
|
||||
name: Notification Times
|
||||
description: >
|
||||
Comma-separated list of times in 24-hour format with leading
|
||||
zeros (e.g., "08:00, 14:30, 20:00").
|
||||
selector:
|
||||
text:
|
||||
|
||||
day_interval:
|
||||
name: Day Interval
|
||||
description: >
|
||||
How often to send notifications (in days).
|
||||
Set to 1 for daily notifications.
|
||||
default: 1
|
||||
selector:
|
||||
number:
|
||||
min: 1
|
||||
max: 365
|
||||
mode: box
|
||||
unit_of_measurement: days
|
||||
|
||||
start_date:
|
||||
name: Start Date (optional)
|
||||
description: >
|
||||
Reference start date for the day interval calculation.
|
||||
Notifications are sent every N days counting from this date.
|
||||
Leave empty to ignore the day interval and send every day.
|
||||
default: ""
|
||||
selector:
|
||||
date:
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Control
|
||||
# -------------------------------------------------------------------------
|
||||
control:
|
||||
name: "Control"
|
||||
collapsed: false
|
||||
input:
|
||||
control_flag:
|
||||
name: Control Flag
|
||||
description: >
|
||||
Toggle entity to enable or disable notifications.
|
||||
Notifications are only sent when this entity is ON.
|
||||
selector:
|
||||
entity:
|
||||
domain:
|
||||
- input_boolean
|
||||
- switch
|
||||
|
||||
# Single mode prevents overlapping notification sends
|
||||
mode: single
|
||||
|
||||
# =============================================================================
|
||||
# Trigger Variables (available in trigger templates)
|
||||
# =============================================================================
|
||||
trigger_variables:
|
||||
input_times: !input notification_times
|
||||
|
||||
# =============================================================================
|
||||
# Triggers
|
||||
# =============================================================================
|
||||
trigger:
|
||||
# Fire when the current time matches any configured notification time
|
||||
- platform: template
|
||||
value_template: >
|
||||
{{ now().strftime('%H:%M') in (input_times.split(',') | map('trim') | list) }}
|
||||
|
||||
# =============================================================================
|
||||
# Variables
|
||||
# =============================================================================
|
||||
variables:
|
||||
# Input references
|
||||
notify_targets: !input notify_targets
|
||||
message_text: !input message
|
||||
interval: !input day_interval
|
||||
start_date: !input start_date
|
||||
|
||||
# Debug flag - set to true to enable persistent notifications for troubleshooting
|
||||
is_debug: false
|
||||
|
||||
# =============================================================================
|
||||
# Conditions
|
||||
# =============================================================================
|
||||
condition:
|
||||
# Control flag must be ON
|
||||
- condition: state
|
||||
entity_id: !input control_flag
|
||||
state: "on"
|
||||
|
||||
# Today must fall on the correct day in the interval cycle (skipped if no start date)
|
||||
- condition: template
|
||||
value_template: >
|
||||
{%- if start_date | length == 0 -%}
|
||||
true
|
||||
{%- else -%}
|
||||
{%- set today_ts = as_timestamp(now().strftime('%Y-%m-%d') ~ 'T00:00:00') -%}
|
||||
{%- set start_ts = as_timestamp(start_date ~ 'T00:00:00') -%}
|
||||
{%- set days_since = ((today_ts - start_ts) / 86400) | round(0) | int -%}
|
||||
{{ days_since >= 0 and days_since % (interval | int) == 0 }}
|
||||
{%- endif -%}
|
||||
|
||||
# =============================================================================
|
||||
# Actions
|
||||
# =============================================================================
|
||||
action:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Debug Logging (optional)
|
||||
# ---------------------------------------------------------------------------
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ is_debug }}"
|
||||
sequence:
|
||||
- service: persistent_notification.create
|
||||
data:
|
||||
title: "Periodic Notification Debug"
|
||||
message: >
|
||||
Targets: {{ notify_targets }}
|
||||
Message: {{ message_text }}
|
||||
Interval: every {{ interval }} day(s)
|
||||
Start Date: {{ start_date }}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Send Notification
|
||||
# ---------------------------------------------------------------------------
|
||||
- service: notify.send_message
|
||||
target:
|
||||
entity_id: "{{ notify_targets }}"
|
||||
data:
|
||||
message: "{{ message_text }}"
|
||||
Reference in New Issue
Block a user