Keeping this here to help others as I could not find code examples anywhere. ChatGPT, Deepseek, and Claude 3 could not fix after 2 hours a trying them. Google’s Gemini fixed it first shot.
Code is different to attach an image to a notification for the built-in HA service when there are more-than-one recipient.
Code that works for a single (or group) entity…
default:
- service: notify.{{ notify_group_target }}
data:
title: !input notification_title
message: !input notification_message
data:
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
image: '{{ snapshot_access_file_path }}'
clickAction: !input data_clickaction_url
# video: !input notification_video
sticky: !input notification_sticky
alert_once: !input notification_alert_once
notification_icon: !input notification_icon
ttl: 0
priority: high
attachment:
url: '{{ snapshot_access_file_path }}'
content_type: JPEG
url: !input data_clickaction_url
push:
sound:
name: !input notification_sound
volume: !input notification_volume
critical: '{{ iif(notification_critical, 1, 0) }}'
actions:
- action: '{{ action_type }}'
title: '{{ action_title }}'
uri: '{{ action_uri }}'
Similar muli-recipient code send Notifications fine but Image is never attached…
- condition: template
value_template: '{{ notify_device != false }}'
- repeat:
for_each: !input notify_device
sequence:
- service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}"
data:
title: !input notification_title
message: !input notification_message
data:
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
image: '{{ snapshot_access_file_path }}'
clickAction: !input data_clickaction_url
sticky: !input notification_sticky
alert_once: !input notification_alert_once
notification_icon: !input notification_icon
ttl: 0
priority: high
attachment:
url: '{{ snapshot_access_file_path }}'
content_type: JPEG
url: !input data_clickaction_url
push:
sound:
name: !input notification_sound
volume: !input notification_volume
critical: '{{ notification_critical }}'
actions:
- action: '{{ action_type }}'
title: '{{ action_title }}'
uri: '{{ action_uri }}'
you must Explicitly scope the path variable inside the loop sequence. A nuance (aka pain and frustration) of the not-real programming language ![]()
working multi-recipient code…
- condition: template
value_template: '{{ notify_device != false }}'
- repeat:
for_each: !input notify_device
sequence:
- variables:
# Explicitly scope the path variable inside the loop sequence
img_path: '{{ snapshot_access_file_path }}'
- service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}"
data:
title: !input notification_title
message: !input notification_message
data:
# Android standard key
image: '{{ img_path }}'
# iOS standard key
attachment:
url: '{{ img_path }}'
content_type: JPEG
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
clickAction: !input data_clickaction_url
sticky: !input notification_sticky
alert_once: !input notification_alert_once
notification_icon: !input notification_icon
ttl: 0
priority: high
url: !input data_clickaction_url
push:
sound:
name: !input notification_sound
volume: !input notification_volume
critical: '{{ notification_critical }}'
actions:
- action: '{{ action_type }}'
title: '{{ action_title }}'
uri: '{{ action_uri }}'