feat: add message_tts parameter + fix parse_mode for notify channels#21
feat: add message_tts parameter + fix parse_mode for notify channels#21jokerigno wants to merge 2 commits into
Conversation
Adds an optional message_tts field to the send service schema.
When provided, voice channels (Google Home, Alexa) use message_tts
instead of message, while text channels (Telegram, Mobile App) keep
using message. Falls back to message if message_tts is not set.
Also supported per-target via target_data[alias][message_tts].
Use case: send emoji/markdown-rich text to Telegram while sending
clean, readable speech to voice assistants from a single service call.
Example:
action: universal_notifier.send
data:
message: '✅ R2D2 ha finito! Batteria: 85% 🤖'
message_tts: 'R2D2 ha terminato le pulizie. Batteria all ottantacinque percento.'
targets: [telegram, google_home]
When building text messages with HTML or MarkdownV2 formatting, the parse_mode was stripped before reaching the notify service call. This caused Telegram to reject messages silently when the bot's default parse_mode (e.g. markdownv2) didn't match the tags in the formatted text (e.g. <b> HTML tags). Now parse_mode is injected into service_payload['data'] for notify channels so Telegram renders formatting correctly.
There was a problem hiding this comment.
Pull request overview
This PR enhances the universal_notifier.send Home Assistant service to better support mixed text + voice notification setups, and fixes Telegram formatting delivery for notify.* channels by correctly propagating parse_mode.
Changes:
- Added optional
message_ttsservice input (and per-target override) so voice channels can speak different text than what text channels display. - Fixed
parse_modepropagation for non-voicenotify.*calls by injecting it intoservice_payload["data"].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
custom_components/universal_notifier/const.py |
Introduces CONF_MESSAGE_TTS constant for the new service parameter. |
custom_components/universal_notifier/__init__.py |
Extends the send service schema and routing logic to support message_tts, and ensures parse_mode is passed to notify.* payloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SEND_SERVICE_SCHEMA = vol.Schema({ | ||
| vol.Required(CONF_MESSAGE): cv.string, | ||
| vol.Required(CONF_TARGETS): vol.All(cv.ensure_list, [cv.string]), | ||
| vol.Optional(CONF_MESSAGE_TTS): cv.string, | ||
| vol.Optional(CONF_TITLE): cv.string, | ||
| vol.Optional(CONF_DATA): dict, | ||
| vol.Optional(CONF_TARGET_DATA): dict, |
|
Aggiungo un commento: Migrando a Universal Notifier per inviare notifiche contemporaneamente su Telegram e su speaker Google (via tts.speak). Ho notato che il campo title: è globale: viene applicato a tutti i canali indistintamente. Comportamento attuale: Su Telegram: title diventa l'intestazione della notifica (OK) if final_title: Un flag nella configurazione del canale (es. ignore_title: true) ciao! |
Summary
This PR adds two improvements identified while testing migration from the AppDaemon Package-Notification-HUB.
1. New
message_ttsparameterAdds an optional
message_ttsfield to thesendservice. When provided, voice channels (Google Home, Alexa) use this text instead ofmessage, while text channels (Telegram, Mobile App) continue to usemessage.This allows sending emoji/markdown-rich text to Telegram and clean, readable speech to speakers from a single service call — a common pattern in the AppDaemon Notifier ecosystem.
Example:
Also supported per-target via
target_data[alias][message_tts]. Falls back tomessageif not provided.2. Fix: pass
parse_modeto notify servicesThe
parse_modeused to format the message (HTML or MarkdownV2) was being stripped before thenotify.*service call. This caused Telegram to silently reject messages when the bot's default parse_mode (e.g.markdownv2) did not match the tags in the formatted text (e.g.<b>HTML tags frombold_prefix).parse_modeis now injected intoservice_payload["data"]for non-voicenotifychannels so Telegram renders formatting correctly.Testing
Tested on a live Home Assistant instance with:
notify.telegrammarcochannel (telegram_bot configured withparse_mode: markdownv2)messageandmessage_ttsfieldsBefore fix: messages silently dropped by Telegram due to parse_mode mismatch. After fix: messages received correctly with formatting rendered.