I’m trying to create my first intent-to-reponse-with-action flow but am stuck at passing the actions response_variable to the speach: section. The only documentation example is horrible, but I’m familiar enough with scripts to understand its intent (pun intended… ok I’ll stop). I’ve tried quite a few different things, including using the example as writen (in case I completely failed to understand it), and no matter what I try I get an unexpected error where the response_variable is undefined. The only thing I can think of is that the response_variable is out of scope for the speach section, in which case the documentation example shouldn’t even exist.
I’m hoping that someone could point out what I might be doing wrong and/or point me in the right direction.
WasteItems:
action:
action: "calendar.get_events"
target:
entity_id: calendar.waste_collect_calendar # This needs to be dynamic somehow
data:
duration:
hours: 144
minutes: 0
seconds: 0
response_variable: collection
speech:
text: >-
"The waste items to be picked up
{% if collection['calendar.waste_collect_calendar'].events[0].start
|as_timestamp|timestamp_custom('%A %B %-d') == now()|as_timestamp|timestamp_custom('%A %B %-d') %}
{{ "today" }}
{% else %}
on {{ collection['calendar.waste_collect_calendar'].events[0].start
|as_timestamp|timestamp_custom('%A %B %-d') }}
{% endif %}
are: {{ collection['calendar.waste_collect_calendar'].events[0].summary }}
The relevant log info from the 2 errors are… homeassistant.exceptions.TemplateError: UndefinedError: 'collection' is undefined
and homeassistant.helpers.intent.IntentUnexpectedError: Error handling WasteItems
The first thing to do is to get rid of the first " in the text response of the intent script.
Then, IIRC, you need to include a stop action to return the response from the calendar query:
WasteItems:
action:
- action: "calendar.get_events"
target:
entity_id:
- calendar.example
- calendar.waste_collect_calendar
data:
duration:
hours: 144
minutes: 0
seconds: 0
response_variable: collection
- stop: "Return value to intent script"
response_variable: collection
speech:
text: >-
The waste items to be picked up
{% if (action_response['calendar.example'].events[0].start | as_datetime).date() == now().date() %}
today
{% else %}
on {{ action_response['calendar.waste_collect_calendar'].events[0].start|as_timestamp|timestamp_custom('%A %B %-d') }}
{% endif %}
are: {{ action_response['calendar.waste_collect_calendar'].events[0].summary }}
I agree that the documentation for speech is woefully underdeveloped and scattered all over the place. While I have been able to put together a few custom intents/scripts that work fine, I’ve also had quite a few that I could never get to work even though everything seemed to be correct. All but one of those I was able to get working using Sentence triggers in automations instead of intents/scripts. You might find you have better luck trying it that way.
Thanks for your response, would you be so kind as to remove my home address from your response? I corrected my OP since I apparently doxed myself unintentionally (missed 2 entries ).
Removing the surrounding "s and adding in the stop: yields the same results unfortunately.
Son of a… it works… the documentation example is correct. A documented simple explanation of what’s going on and why would go a long way in helping an intermediate like me.
Anyways thank you very much for helping me out and getting me on a good path, it’s very much appreciated.