You can put it into a script file and then call the script from the automation’s action.
BTW, here’s another way to write the template:
{% set t = now().strftime("%H")|int %}
{% if t < 12 %} Good morning
{% elif t < 18 %} Good afternoon
{% else %} Good evening
{% endif %}
{{ [ "Mr.","Sir","Boss" ] | random }}! Can you read me?
Short answer: No
Longer answer: It is sadly not possible to include multiple script-files, not include a script file in another !included script-file, so like I do here:
it’ll include the text fron the /jeeves_morning_briefing.yaml file, but if I were to use another !include, say in said file, it just responds back the line word for word, as a made up response here:
So, unless I’m missing something, it means nested speech scripts are out of the question, yet.
I’m still hoping to get an answer on exactly this in my post you read and linked.
Sadly, when I Google “home-assistant notify parse nested”, I show up as the top answer so far.
And yeah, I ended stuck on the same situation…
How are you working around this limitation? A file for each message, with the full sentence? Anything new/different?
Maybe we should transform this on a ticket on Github…
Yup, I’m doing a full sentence added file - but then again I don’t have more than a few/10 different notification messages currently, so it’s not a big bother - yet.
I’d love a Github ticket, but I think it’s a complication with the yaml language because it compiles the messages before running the script, resulting in the problematic code.
Currently, this doesn’t allow me to change variables based on the triggered entities.
I imagine a template would be able to do just that, although I haven’t toyed with those enough to be able to confidently set up one.
I can however show you more automations, such as my sunset notifications:
>
{{ [
"Sundown is upon us, Sir.",
"The sun has set. Good Evening, Master Wayne.",
"It is evening now, Sir."
] | random }}
Notice the pointy bracket ( > )beginning in the file.
This allows for a multi-line included file.
This is a quite simple automation with one function: When the state of the sun.sun sensor triggers the sunset event state, the automation calls the notify-action I’ve set up called Jeeves.
Jeeves then informs me on my phone with the message, a pre-configured yaml-script with three different outputs.
"Sundown is upon us, Sir.",
"The sun has set. Good Evening, Master Wayne.",
or
"It is evening now, Sir."