service: notify.alexa_media_everywhere
data:
message: "{{ state_attr('calendar.website_calendar','message') }} is about to start"
data:
type: announce
method: all
It keeps putting quotes around my message. If I remove the quotes, it doesn’t like the yaml. Did I forget a closing brace somewhere?
This is what it looks like in developer tools. It only likes it when I put single or double quotes around the message, but then the part within curly braces does not execute.
I’m not familiar with the notify service however I question the use of two ‘data:’ entries in the yaml. Shouldn’t the yaml be;
service: notify.alexa_media_everywhere
data:
message: "{{ state_attr('calendar.website_calendar','message') }} is about to start"
type: announce
method: all
It won’t work without quotes when using a single-line statement. What is your aim? By the way: If I remember right, method: all has no function anymore. Edit: It was the show method.
The second data is supposed to be there, and is absolutely required in this instance. @atv is calling the service on an Alexa speaker group, which needs to have the data type set to announce.
service: notify.alexa_media_everywhere
data_template:
message: "{{ state_attr('calendar.website_calendar','message') }} is about to start"
data:
type: announce
method: all
I don’t think that’s the issue… data_template still works in AMP calls, and it was necessary for a while after core stopped requiring it… but that hasn’t been the case for a year or two.
From the text of the message, it seems like you may be planning on using a calendar event trigger with an offset. If that is the case, you should be basing the message’s template on the trigger variable:
service: notify.alexa_media_everywhere
data:
message: "{{ trigger.calendar_event.summary }} is about to start"
data:
type: announce
method: all
Just keep in mind that you can’t directly test a template like this in the template editor tool since the variable trigger doesn’t have a value there unless you assign it one.
I guess this is the better way, I’ll try and use the trigger instead.
It seems to work now using developer tools, so I put that in the automation. I guess the quotes threw me off as I don’t usually use that, and it didn’t trigger for some reason. It also doesn’t highlight the {{ }} once enclosed in quotes, so I thought it was interpreting it as a string.
I thought I’ve used it before without quotes, never been to stringent on it but maybe I overlooked it. So when using multiline I can use it without quotes?
It’s a custom integration so I felt it was prudent to use what it recommended. After all, the OP reported the template (when correctly quoted) failed to be evaluated … which is not a nominal result.
It’s better but not for the reason you may think.
The “part within the curly braces” is a Jinja2 template. So the template you used:
should have been interpreted as a Jinja2 template and evaluated. In other words, it should have reported the value of the message attribute. Had it failed to be recognized as a template, it would have literally spoken the template.
So what was the value of the message attribute in calendar.website_calendar when you originally tested it?
If calendar.website_calendar didn’t have a message attribute (i.e. no scheduled event) then state_attr() would have reported nothing.
How did you test it because you cannot test a trigger object in the Template Editor:
{{ trigger.calendar_event.summary }}
^^^^^^^
Cannot test this in Developer Tools > Template
Perhaps I guess the quotes threw me off as I don’t usually use that, and it didn’t trigger for some reason.
The quotes are required in your original template. Your belief they needed to be removed only exacerbated the problem.
It’s the old way of doing things. You’re using a custom integration so I thought it best to follow its recommendations (using the old fashioned way) but it seems its documentation is simply outdated.
message: "{{ state_attr('calendar.website_calendar','message') }} is about to start"
Because the OP said the template failed to execute.
What I think happened is that the template did execute but state_attr() reported nothing because, at the time of the test, the message attribute didn’t exist (no scheduled event).
It would be instructive if the OP posted the automation’s trace that was produced at the time of the (alleged) failure.
I don’t think anything was wrong with your template, as it was being used in the Services tool. My point was to forewarn OP that they might need to change it for use in an automation so they don’t come back tomorrow saying “This template is broken. It always announces the thing that just ended even though I’m using event: start in my trigger”
Pretty sure there was a message, as I tested it in developer tools as well (not with the trigger, but with the state of the message attribute. But I can’t reproduce it now and I only have 5 traces, which are gone now.
Maybe HA or Alexa TTS had a problem (or I overlooked something more likely).