Skip to content

Fix notify.send_message target passed inside service_data - #38

Open
Rabosa616 wants to merge 6 commits into
jumping2000:mainfrom
Rabosa616:fix/notify-send-message-target
Open

Rabosa616 wants to merge 6 commits into
jumping2000:mainfrom
Rabosa616:fix/notify-send-message-target

Conversation

@Rabosa616

@Rabosa616 Rabosa616 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problema

notify.send_message (HA 2023.8+) no funciona correctament amb universal_notifier per tres raons:

  1. target dins service_data: notify.send_message requereix target com a kwarg separat a async_call, no dins service_data.
  2. data dins service_payload: universal_notifier afegeix data: {parse_mode: html} a service_payload, però notify.send_message no accepta la clau data.
  3. Format HTML a iOS: l'app companion d'iOS no renderitza HTML. El prefix [Home Assistant - hora] Salutació. i les etiquetes HTML es mostren com a text pla.

Solució

__init__.py — Secció J (dispatch)

Per a notify.send_message, extreu target de service_payload i passa'l com a target={"entity_id": [...]} a async_call. Elimina també la clau data que no accepta aquest servei.

utils.py — Tres noves funcions

def apply_apple_notify_text_formatting(message, title) -> tuple
def apply_android_notify_text_formatting(message, title, name, time_str, greeting, parse_mode, use_bold_prefix, skip_assistant_name) -> tuple
def apply_mobile_notify_text_formatting(message, title, device_type, **kwargs) -> tuple
  • apply_apple_notify_text_formatting: elimina HTML, no afegeix prefix ni salutació (iOS mostra text pla).
  • apply_android_notify_text_formatting: format HTML estàndard amb prefix [nom - hora] i salutació.
  • apply_mobile_notify_text_formatting: dispatcher — detecta tipus de dispositiu i crida la funció corresponent.

La detecció iOS/Android usa device_registry i entity_registry (funció is_apple_device en utils.py): si el fabricant del dispositiu és "apple" → iOS, sinó → Android.

__init__.py — Secció D (format missatge)

Substitueix el bloc duplicat iOS/Android per una crida neta:

elif srv_domain == "notify" and srv_name == "send_message":
    device_type = "apple" if is_apple_device(hass, dynamic_entities) else "android"
    final_msg, final_title = apply_mobile_notify_text_formatting(
        message=target_raw_message,
        title=final_title,
        device_type=device_type,
        name=raw_name,
        time_str=raw_time_str,
        greeting=current_greeting,
        parse_mode=parse_mode,
        use_bold_prefix=use_bold_prefix,
        skip_assistant_name=skip_assistant_name,
    )

Context

Testejat amb HA 2026.8 (WSL2). Canals configurats: mobil_oscarnotify.goldeneggsxv, mobil_ipadnotify.vaoss_ipad. Ambdós dispositius target són Apple (iOS). Telegram i Voice PE (tts.speak) funcionen correctament.

HA 2024+ notify entities (mobile companion app) require target to be
passed as a separate async_call parameter, not inside service_data.
Passing target in service_data raises:
  extra keys not allowed @ data['target']

For notify.send_message calls, extract the target entities from the
payload and pass them via the target= kwarg of async_call instead.
notify.send_message does not accept 'data' in service_data either,
causing 'extra keys not allowed @ data[data]'.
companion app renders plain text only; no prefix [HA - time] or
greeting needed for mobile push notifications.
iOS (Apple manufacturer): plain text, no HTML, no HA prefix/greeting.
Android: standard HTML formatting with prefix and greeting.
- strip_html(): strips HTML tags returning plain text
- is_apple_device(): checks device registry for Apple manufacturer
__init__.py now uses these helpers instead of inline logic.
Add apply_apple_notify_text_formatting, apply_android_notify_text_formatting
and apply_mobile_notify_text_formatting to utils.py.

Simplify __init__.py Section D: replace duplicated iOS/Android logic with
a single call to apply_mobile_notify_text_formatting.
@jumping2000

jumping2000 commented Sep 6, 2026

Copy link
Copy Markdown
Owner

hello, I need to understand your PR about iOS app, you can already decide if you want markdoen or html or plain text in your notifications.

@Rabosa616

Copy link
Copy Markdown
Contributor Author

Hello @jumping2000
The issue is that Apple, like alexa or other voice devices does not support HTML on notifications.
If I setup plain or md format I loose the html capabilities on other devices, like for example my wall panell that is an Android or Telegram.
Another solution could be to be able to select per channel instead of a general setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants