Here is what I did: I created a script.
This was my notify.yaml file which was included in the configuration.yaml:
---
- name: admin_telegram
platform: telegram
chat_id: !secret telegram_chatid
- name: family_telegram
platform: telegram
chat_id: !secret telegram_family_chatid
- name: persistent
platform: rest
resource: 'https://localhost:8443/api/services/persistent_notification/create'
method: POST_JSON
headers:
Authorization: !secret persistent_api
Content-Type: 'application/json'
message_param_name: message
title_param_name: title
target_param_name: notification_id
- name: admin_notify
platform: group
services:
- service: admin_telegram
- service: persistent
- service: mobile_app_device
- name: family_notify
platform: group
services:
- service: family_telegram
I took out all but the persistent notify service.
Then I had this HA script created:
send_notification:
alias: Send notification
description: Unified notification with optional Telegram photo/video
fields:
target:
description: Who to notify (admin or family)
example: admin
title:
description: Notification title
example: "Something happened"
message:
description: Notification body
example: "The front door opened."
notification_id:
description: Optional ID for persistent notifications
example: "door_open"
photo_file:
description: Optional local path to photo to send via Telegram
example: "/config/www/snapshot.jpg"
photo_url:
description: Optional URL to photo to send via Telegram
example: "https://example.com/snapshot.jpg"
video_file:
description: Optional local path to video to send via Telegram
example: "/config/www/clip.mp4"
video_url:
description: Optional URL to video to send via Telegram
example: "https://example.com/clip.mp4"
sequence:
- choose:
# ADMIN: Telegram + persistent + mobile app
- conditions:
- condition: template
value_template: "{{ target == 'admin' }}"
sequence:
# Text message to admin via Telegram
- action: telegram_bot.send_message
data:
target: !secret telegram_chatid
message: "{{ message }}"
# optional: caption-like title prefix
# message: "{{ title ~ ': ' ~ message if title else message }}"
# Optional photo
- choose:
- conditions: "{{ photo_file is defined and photo_file != '' }}"
sequence:
- action: telegram_bot.send_photo
data:
target: !secret telegram_chatid
file: "{{ photo_file }}"
caption: "{{ title if title is defined else '' }}"
- conditions: "{{ photo_url is defined and photo_url != '' }}"
sequence:
- action: telegram_bot.send_photo
data:
target: !secret telegram_chatid
url: "{{ photo_url }}"
caption: "{{ title if title is defined else '' }}"
# Optional video
- choose:
- conditions: "{{ video_file is defined and video_file != '' }}"
sequence:
- action: telegram_bot.send_video
data:
target: !secret telegram_chatid
file: "{{ video_file }}"
caption: "{{ title if title is defined else '' }}"
- conditions: "{{ video_url is defined and video_url != '' }}"
sequence:
- action: telegram_bot.send_video
data:
target: !secret telegram_chatid
url: "{{ video_url }}"
caption: "{{ title if title is defined else '' }}"
# Existing REST persistent notification
- action: notify.persistent
data:
message: "{{ message }}"
title: "{{ title | default('') }}"
target: "{{ notification_id | default('ha_notification') }}"
# Existing mobile app notification
- action: notify.mobile_app_device
data:
message: "{{ message }}"
title: "{{ title | default('') }}"
# FAMILY: Telegram only (same media options)
- conditions:
- condition: template
value_template: "{{ target == 'family' }}"
sequence:
- action: telegram_bot.send_message
data:
target: !secret telegram_family_chatid
message: "{{ message }}"
- choose:
- conditions: "{{ photo_file is defined and photo_file != '' }}"
sequence:
- action: telegram_bot.send_photo
data:
target: !secret telegram_family_chatid
file: "{{ photo_file }}"
caption: "{{ title if title is defined else '' }}"
- conditions: "{{ photo_url is defined and photo_url != '' }}"
sequence:
- action: telegram_bot.send_photo
data:
target: !secret telegram_family_chatid
url: "{{ photo_url }}"
caption: "{{ title if title is defined else '' }}"
- choose:
- conditions: "{{ video_file is defined and video_file != '' }}"
sequence:
- action: telegram_bot.send_video
data:
target: !secret telegram_family_chatid
file: "{{ video_file }}"
caption: "{{ title if title is defined else '' }}"
- conditions: "{{ video_url is defined and video_url != '' }}"
sequence:
- action: telegram_bot.send_video
data:
target: !secret telegram_family_chatid
url: "{{ video_url }}"
caption: "{{ title if title is defined else '' }}"
And instead of using this code to send a notification:
- service: notify.family_notify
data:
message: Er is iemand bij de deur
data:
photo:
- file: '{{ snapshot_filename }}'
I now use this code:
- service: script.send_notification
data:
target: "family"
title: "Deurbel"
message: "Er is iemand bij de deur"
photo_file: '{{ snapshot_filename }}'
I hope this helps.