I’m a software engineer, so I want to DRY my code. One aspect that I would really like to centralize is sending notifications to a specific set of devices. For this reason, I would like to create a script which can be used to send notifications to specific devices, but the title, message, actions, etc should all be dictated by the automation or other trigger.
It is trivial to pass title and message to the script (doc for reference); however according to the section on passing parameters, it seems like only strings are supported. This means that I cannot pass dynamic actions which is a big feature of the notifications I would like to send to mobile devices specifically.
Here is my script so far:
alias: Notify Monitors - Basic
sequence:
- service: notify.mobile_app_bryans_iphone
data:
title: '{{ title }}'
message: '{{ message }}'
description: Notify all of devices
fields:
title:
description: The Title of the notification
example: Example text
message:
description: The content
example: Example text
required: true
mode: single
icon: mdi:message-badge
Even if I add the actions parameter to the script and attempt to pass it to the notify.... service under data (like normal), it fails. It seems like the parameter is probably being stringified which is probably not supported by the notifier.
Am I missing anything, or is this just a limitation of the system at this time?
did you find a solution for this? I had the exact same idea, making a generic notification script and invoking it with parameters. I use ‘dynamic content’ in the strings as well
I hope you eventually found a solution to your problem! I also wanted to say ‘thank you’ for the example! I’m using this script so I don’t have to recreate the wheel everytime I want to send notifications from an automation. Thanks!!
not sure if this is still valid for you or not, but i had the same problem today and was able to solve it. So i decided to post the solution here in case someone else would need to help with this.
So the way i pass the actions is through the additional field with type object:
data:
selector:
object: {}
name: Data
default: {}
required: true
after that in the actions i just use the value the same way as the other fields:
Had a long time trouble with the error message: “expected dict for dictionary value @ data[‘data’]. Got None”
when passing inputs from an automation to a script to another script and had no idea why.