haushalt
(Wolfgang Koeppner-Bures)
March 9, 2025, 3:44pm
1
I have defined my first intent in the configuration.yaml but I cant get to the slot values in the intent-script
conversation:
intents:
FetchSpotify:
- "Transfer spotify to (my|the) {player}"
intent_script:
FetchSpotify:
action:
- action: rest_command.call_smartflat
data:
intent: "fetch_spotify"
JSONData: >
{
"playername": "{{ intent.slots.player }}"
}
response_variable: result # get action response
- stop: ""
response_variable: result # and return it
speech:
text: "{{ action_response['rest_command.call_smartflat'].reply }}"
Whatever I tried to recevie the “player” slot I find a logentry like this
ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'intent' is undefined when rendering '{
"playername": "{{ intent.slots.player }}"
}'
wmaker
(Tommy Long)
March 9, 2025, 8:13pm
2
Try using {{ player }}
instead of {{ intent.slots.player }}
haushalt
(Wolfgang Koeppner-Bures)
March 10, 2025, 6:43pm
4
That’s where I started… :-/
Current state is the following error log:
2025-03-10 19:38:46.826 INFO (MainThread) [homeassistant.helpers.intent] Triggering intent handler <ScriptIntentHandler - FetchSpotify>
2025-03-10 19:38:46.845 INFO (MainThread) [homeassistant.helpers.script.intent_script_fetchspotify] Intent Script FetchSpotify: Running intent_script script
2025-03-10 19:38:46.846 INFO (MainThread) [homeassistant.helpers.script.intent_script_fetchspotify] Intent Script FetchSpotify: Executing step call service
2025-03-10 19:38:46.847 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘player’ is undefined when rendering ‘{
“playername”: “{{player}}”
}’
2025-03-10 19:38:47.250 INFO (MainThread) [homeassistant.helpers.script.intent_script_fetchspotify] Intent Script FetchSpotify: Stop script sequence:
2025-03-10 19:38:47.251 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: ‘dict object’ has no attribute ‘rest_command.call_smartflat’ when rendering ‘{{ action_response[‘rest_command.call_smartflat’].reply }}’
with this code in the config
rest_command:
call_smartflat:
url: "https://xxxxxxxxxx"
method: "POST"
headers:
Content-Type: "application/json"
payload: >
{
"Intent": "{{ intent }}",
"JSONData": {{ params | tojson }}
}
intent_script:
FetchSpotify:
description: Ask Smartflat to transfer spotify to requested device
action:
- action: rest_command.call_smartflat
data:
intent: "fetch_spotify"
params: >
{
"playername": "{{player}}"
}
response_variable: result # get action response
- stop: ""
response_variable: result # and return it
speech:
text: "{{ action_response['rest_command.call_smartflat'].reply }}"
Thx for any help, this is sooo much new to me
wmaker
(Tommy Long)
March 10, 2025, 6:48pm
5
Looks like you are missing some YAML lines “data” and “sentences”. Check the docs.
haushalt
(Wolfgang Koeppner-Bures)
March 10, 2025, 8:27pm
6
So I managed to get the params correct:
intent_script:
FetchSpotify:
description: Ask Smartflat to transfer spotify to requested device
action:
- action: rest_command.call_smartflat
data:
intent: "fetch_spotify"
params:
playername: "{{ player }}"
response_variable: result # get action response
- stop: ""
response_variable: result # and return it
speech:
text: "{{ action_response['rest_command.result'].reply }}"
No I only fail to get the response right.
2025-03-10 21:19:59.338 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: ‘dict object’ has no attribute ‘rest_command.result’ when rendering ‘{{ action_response[‘rest_command.result’].reply }}’
same for ‘rest_command.call_smartflat.result’…
Referring to Intent Script - Home Assistant
wmaker
(Tommy Long)
March 10, 2025, 9:01pm
7
I don’t have spotify, so can’t help there. However if you run that action in DevTools and can show the “Response”, then maybe I or someone else can help.
haushalt
(Wolfgang Koeppner-Bures)
March 11, 2025, 11:27am
8
I’m not talking directly to spotify anyway, the response looks something like this:
{“state”:“OK”,“reply”:“Now playing on SMARTHOME”}
wmaker
(Tommy Long)
March 11, 2025, 5:12pm
9
I think the way this works, is that the results of the rest command gets stored in response_variable and response_variable in turn is copied into action_response.
Something like action_response = {“state”:“OK”,“reply”:“Now playing on SMARTHOME”}
so try {{ action_response['reply'] }}
haushalt
(Wolfgang Koeppner-Bures)
March 12, 2025, 8:46pm
10
THANK YOU VERY MUCH!
action_response.content.reply did the trick then.