jdawes
(jdawes)
1
I have created a script with variables that can send a notification to my iPhone.
The service call looks like this:
service: notify.mobile_app_jarles_iphone_12_pro_max
data:
message: "{{message}}"
title: "{{tittel}}"
data:
image: "{{bilde}}"
actions: "{{actions}}"
When I look at the trace, I see that “|-” is inserted before my variable:
actions: |-
- action: ALARM
title: Start Alarm
icon: sfsymbols:cart
- action: URI
title: Open VG
uri: https://www.vg.no
icon: sfsymbols:cart
- action: IGNORE
title: Ignorer
icon: sfsymbols:xmark
destructive: true
…and this is not working.
The variable “actions” is now a template selector, but I have also tried with text selector. The value sent is:
- action: ALARM
title: Start Alarm
icon: sfsymbols:cart
- action: URI
title: Open VG
uri: "https://www.vg.no
icon: sfsymbols:cart
- action: IGNORE
title: Ignorer
icon: sfsymbols:xmark
destructive: true
If I run the call from the Developer tools->Services, it works fine without “|-”, but not with. The message is sent, but the actions is not there.
Is there anyone that know a solution to this ?
It looks like you are sending the list of actions as a list-shaped string, not an actual list.
Post the complete script so we can see what is actually going on.
jdawes
(jdawes)
3
I have created a smaller example because my original script contains too much.
Script:
alias: Send notifikasjon - Simple
sequence:
- service: notify.mobile_app_jarles_iphone_12_pro_max
data:
message: "{{message}}"
title: "{{title}}"
data:
image: "{{image}}"
actions: "{{actions}}"
mode: queued
fields:
title:
selector:
text: null
name: Title
description: Title for the message
message:
selector:
text:
multiline: true
name: Melding
description: Meldingen som skal sendes
required: false
image:
selector:
text: null
name: Image
description: Url to image
actions:
selector:
template: null
name: Actions
description: Actions for mobile
icon: mdi:message
max: 10
Automation to call the script:
service: script.send_notifikasjon_simple
data:
title: The title
message: The message
actions: |-
- action: ALARM
title: Start Alarm
icon: "sfsymbols:cart"
- action: URI
title: Open VG
uri: "https://www.vg.no"
icon: "sfsymbols:cart"
- action: IGNORE
title: Ignorer
icon: "sfsymbols:xmark"
destructive: true
Now I see that the Automation already includes the “|-”.
Is it any way to send just :
- action: ALARM
title: Start Alarm
icon: "sfsymbols:cart"
- action: URI
title: Open VG
uri: "https://www.vg.no"
icon: "sfsymbols:cart"
- action: IGNORE
title: Ignorer
icon: "sfsymbols:xmark"
destructive: true
…so the service “notify.mobile_app_jarles_iphone_12_pro_max”-call looks like this:
service: notify.mobile_app_jarles_iphone_12_pro_max
data:
message: "{{message}}"
title: "{{title}}"
data:
image: "{{image}}"
actions:
- action: ALARM
title: Start Alarm
icon: "sfsymbols:cart"
- action: URI
title: Open VG
uri: "https://www.vg.no"
icon: "sfsymbols:cart"
- action: IGNORE
title: Ignorer
icon: "sfsymbols:xmark"
destructive: true
That is not what you want… that will send your list as a string.
There are a few acceptable formats. All three of the following work on my instance:
action:
- service: script.send_notifikasjon_simple
data:
title: YAML only
message: The message
actions:
- action: ALARM
title: Start Alarm
icon: sfsymbols:cart
- action: URI
title: Open VG
uri: https://www.vg.no
icon: sfsymbols:cart
- action: IGNORE
title: Ignorer
icon: sfsymbols:xmark
destructive: true
- service: script.send_notifikasjon_simple
data: {"title": "JSON Only", "message": "The message", "actions": [{"action":"ALARM","title":"Start Alarm","icon":"sfsymbols:cart"}, {"action":"URI","title":"Open VG","uri":"https://www.vg.no","icon":"sfsymbols:cart"}, {"action":"IGNORE","title":"Ignorer","icon":"sfsymbols:xmark","destructive":true}]}
- service: script.send_notifikasjon_simple
data:
title: Templated list
message: The message
actions: |-
{{ [{"action":"ALARM","title":"Start Alarm","icon":"sfsymbols:cart"},
{"action":"URI","title":"Open VG","uri":"https://www.vg.no","icon":"sfsymbols:cart"},
{"action":"IGNORE","title":"Ignorer","icon":"sfsymbols:xmark","destructive":true}] }}
jdawes
(jdawes)
5
Thank you very much. This solved my problem

The solution was to configure the actions in YAML and not in the UI.