I’ve read through the script syntax here, but I can’t see where I’m going wrong.
I’m trying to send a notification that will appear on my TV.
To do it, I’m using most of this script … this bit works great.
I see the notification on the TV without a problem.
# ===============================================================
# Send a Notification to the Lounge TV
# ===============================================================
notification_to_lounge_tv:
alias: "Send a Notification to the Lounge TV"
mode: restart
sequence:
- choose:
- conditions:
- condition: state
entity_id: media_player.lounge_tv
state: "on"
sequence:
- service: notify.lounge_tv
data:
message: "This is a test message"
title: "TITLE"
However, what I really want to do is pass the message to it as a variable when its called from an automation. So in this case, I’m using this script which is almost the same …
# ===============================================================
# Send a Notification to the Lounge TV
# ===============================================================
notification_to_lounge_tv:
alias: "Send a Notification to the Lounge TV"
mode: restart
sequence:
- choose:
- conditions:
- condition: state
entity_id: media_player.lounge_tv
state: "on"
sequence:
- service: notify.lounge_tv
data:
message: "{{ message }}"
title: "{{ title }}"
and for the automation …
# ===============================================================
# Person detected in the Front Garden
# ===============================================================
- id: '5C43859D-5396-41E2-A93D-71F1020FD0BF'
mode: single
alias: "Person detected"
trigger:
- platform: state
entity_id: sensor.front_garden_camera_detected_object
to: person
action:
- service: script.notification_to_lounge_tv
data:
variables:
title: "TITLE"
message: "Person Detected"
- service: notify.mobile_app_iphone
data:
message: "Person Detected"
In this case, I get the notification on the iPhone, so I know the automation is firing, but I’m not getting the notification on the TV.
Clearly I’m missing a trick, but I just can’t see it. There are no errors in my logs.
If you call the script as a service directly, instead of calling the script.turn_on service on the script, you do not need to use the variables configuration…
- id: '5C43859D-5396-41E2-A93D-71F1020FD0BF'
mode: single
alias: "Person detected"
trigger:
- platform: state
entity_id: sensor.front_garden_camera_detected_object
to: person
action:
- service: script.notification_to_lounge_tv
data:
title: "TITLE"
message: "Person Detected"
- service: notify.mobile_app_iphone
data:
message: "Person Detected"
This proposed solution fine for this specific use-case, but I would still like to know how to pass a variable to a script, which is called from a service.
For example, I can call this script, but attempt to pass the message field don’t work:
service: notify.alexa_one
data:
message: Message from H.A. "{{message}}"
What you have posted is a service call to what looks like a custom notifier, not a complete script… if you want help, it’s much easier for us if you post actual, complete scripts or automations, including custom component configuration where applicable.
Using the following works fine for me:
#script
alias: Test script variable
sequence:
- service: notify.alexa_media_kitchen
data:
message: |
Message from Home Assistant {{ message }}
data:
type: tts
mode: single
# service call to use in another script or automation
service: script.test_script_variable
data:
message: This is a test
#OR
service: script.turn_on
data:
variables:
message: Just testing stuff
target:
entity_id: script.test_script_variable
OP’s issue was that they had made a mash-up of the two service call types, using the variable configuration from the script.turn_on (i.e. indirect) service while using the direct service call method.
I am trying to do something similar to those above and, if I pass in a string to the script then it does in fact work. My problem is that when instead I try to pass a trigger variable from the automation to the script the script executes with a null value in the field.
In the automation the triggers are all calendar events. This works:
i actually only had the typo in the post here sorry, i was editing things around, i have it without typo in home assistant and it doesn’t work.
edited my initial post to have actual copy/paste now
EDIT: i think i figured it out, my problem is with the “=” in the value… i am guessing it needs to be escaped somehow? removing that everything works fine