#Custom sentence for playback on sonos speaker
1 messages Β· Page 1 of 1 (latest)
Sorry missed your message, can i upload here more than 15 lines or do i use pastebin?
Please use a code share site to share code or logs, for example:
- https://dpaste.org/ (select YAML for the language, and consider picking a longer expiry)
- http://pastie.org/ (select YAML for the language)
- https://paste.debian.net/ (you guessed it, select YAML as the language)
Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.
intent_script: https://paste.ubuntu.com/p/n4Hj4HcYZt/
custom_sentence: https://paste.ubuntu.com/p/Wp2j3wpVRC/
Like i said, the problem is that it takes a few seconds before the source is showing as media_title attr.
Ow just see that message 'Please don't use Pastebin" π
Anyway i know the code is working.
so source is going into state_attr(media_player, 'media_title') and it takes a while, right?
Yes correct
ok. are you aware you could use {{ slots.source }} in the response? if so, is there any reason you avoid it?
it would be populated with exactly what you said in the triggering sentence
Well...
I read allot about slots.source (i mean using slots...) but i have no idea what it is
I'm not a code engineer so π
a "slot" is a placeholder that was used to trigger the Assist pipeline. it could either be explicitly used in a sentence (e.g. turn on {name} where name is the slot automatically provided by HA or source in your example, where source is a text value slot)
you can access slots in reponses with the slots dictionary, which contains all slots. in your case, you should output slots.source
however, i think i recall there was a bug or missing feature with the response being provided in the intent_script. if that produces an error, then let me know and i can give you an alternative solution that works
Give me a second i going to test it right away.
also, if you use slots.source in the reponse, you no longer need the delay, as the value is available immediately
Yes going to remove the wait trigger and change the state_attr(media_player, 'media_title') with {{ slots.source }}.
that's a delay action, not a "wait trigger". a "wait trigger" actually exists and is something else
Yeah sorry that's what i mean π
I have a little knowledge after using home assistant for a few years but it's just hard time making all the code, automations etc without any coding knowledge...
It outputs sorry something went wrong
But assist is still working and plays the source
text: |-
"OK, {{ slots.source }} wordt afgespeeld in {{ state_attr(media_player, 'friendly_name') }}"```
I think this is OK?
if it said something went wrong, there should be an error in the HA core logs. What is it?
the response seems ok, yes
Logger: homeassistant.helpers.template
Source: helpers/template.py:2345
First occurred: 14:27:49 (2 occurrences)
Last logged: 14:29:06
Template variable error: 'slots' is undefined when rendering '"OK, {{ slots.source }} wordt afgespeeld in {{ state_attr(media_player, 'friendly_name') }}"'
but like i said, i can't remember if you can use slots in the intent_script response
oh, there it is
slots is undefined, no idea why π
in that case, remove everything under the speech part in the intent script and add this to your custom sentence file, just above lists::
wait
replace {{ slots.source }} with {{ source }} and try again please
Without the brackets?
with them, i've edited the reply
Oh okay just a second.
don't forget to reload intent_script from dev tools https://my.home-assistant.io/redirect/server_controls/
yep done that and it works, but...
Now it says "OK, FV:2/61 wordt afgespeeld in Badkamer"
They removed the source_list from the sonos entities and replaced it with a sensor that holds the sources
and now it outputs that π
right. that makes sense, though. that's what the intent_script gets, the value, not the spoken text
what you've defined in the out: part of your list
i'm guessing that's not acceptable, right?
Yeah it don't make sense to me because i don't know all these codes for every radiostation π
remove everything under the speech: part in the intent_script and add this to your custom sentence file, just above lists::
responses:
intents:
HassGetState:
default: "OK, {{ slots.source }} wordt afgespeeld in {{ state_attr(slots.media_player, 'friendly_name') }}"
then reload intent_script and conversation from dev tools
do i keep the speech: part itself?
nope
OK wait i going to show you if it is correct what i do
that probably won't work because you won't get the value for media_player. π€
I can try? π
so like this?
responses:
intents:
HassGetState:
default: "OK, {{ slots.source }} wordt afgespeeld in {{ state_attr(slots.media_player, 'friendly_name') }}"
intents:
SonosSource:
data:
- sentences:
- "(zet|wijzig|speel) [radio|sonos] [op] {source} [af|op|naar] [in] [de] {media_player}"
- "(zet|wijzig|speel) [radio|sonos] {media_player} op {source}"
you can try, but i don't think it will work. replace {{ state_attr(slots.media_player, 'friendly_name') }} with {{ slots.media_player }} and it will work, although it will not do what you want
i'm looking for a solution in the meantime
Going to test, but the place i added it is OK?
yeah, it's fine
ok
spacing was the most important, as it always is in YAML
Now it just stays on the 3 dots response
yeah, you can't get both the media_player entity ID (the out of a text list value) and the spoken source (the in of a text list value) in the same response, unfortunately
i don't know why or where. are you testing via text?
ok. have you reloaded conversation?
I always reload all yaml config?
ok, that's good
can you also test your sentence here? https://my.home-assistant.io/redirect/developer_assist/
and paste the output
This is what i get with my original code with the delay action
name: SonosSource
slots:
source: joe
media_player: badkamer
details:
source:
name: source
value: FV:2/61
text: joe
media_player:
name: media_player
value: media_player.badkamer
text: badkamer
targets: {}
match: true
sentence_template: >-
(zet|wijzig|speel) [radio|sonos] [op] {source} [af|op|naar] [in] [de]
{media_player}
unmatched_slots: {}
source: custom
file: nl/sonos_source.yaml```
you haven't updated the sentence or list, so that's still relevant
but why have you switched back?
I was just checking what it outputs
just a second i'm to test it with your solution π
it should be the exact same
I think i made a mistake with the code you provided π
going to test it again
This is with your code
name: SonosSource
slots:
source: joe
media_player: badkamer
details:
source:
name: source
value: FV:2/61
text: joe
media_player:
name: media_player
value: media_player.badkamer
text: badkamer
targets: {}
match: true
sentence_template: >-
(zet|wijzig|speel) [radio|sonos] [op] {source} [af|op|naar] [in] [de]
{media_player}
unmatched_slots: {}
source: custom
file: nl/sonos_source.yaml```
one last test: https://my.home-assistant.io/redirect/voice_assistants/ > {your pipeline} >
> Debug
then paste the RAW output (full) here
run:
pipeline: 01gzjghmyggfh2sbs0mzqkp3wg
language: nl
runner_data:
stt_binary_handler_id: null
timeout: 300
events:
- type: run-start
data:
pipeline: 01gzjghmyggfh2sbs0mzqkp3wg
language: nl
runner_data:
stt_binary_handler_id: null
timeout: 300
timestamp: "2024-02-15T14:00:35.324153+00:00"
- type: intent-start
data:
engine: homeassistant
language: nl
intent_input: zet joe op in badkamer
conversation_id: null
device_id: null
timestamp: "2024-02-15T14:00:35.324380+00:00"
- type: intent-end
data:
intent_output:
response:
speech: {}
card: {}
language: nl
response_type: action_done
data:
targets: []
success: []
failed: []
conversation_id: null
timestamp: "2024-02-15T14:00:42.800591+00:00"
- type: run-end
data: null
timestamp: "2024-02-15T14:00:42.800732+00:00"
intent:
engine: homeassistant
language: nl
intent_input: zet joe op in badkamer
conversation_id: null
device_id: null
done: true
intent_output:
response:
speech: {}
card: {}
language: nl
response_type: action_done
data:
targets: []
success: []
failed: []
conversation_id: null```
ah! or course...
the sentence(s) you defined do not specify what response to offer. add the following line after everything here #1207346883073413120 message
the spacing is important
response: default
So like this?
responses:
intents:
HassGetState:
default: "OK, {{ slots.source }} wordt afgespeeld in {{ state_attr(slots.media_player, 'friendly_name') }}"
intents:
SonosSource:
data:
- sentences:
- "(zet|wijzig|speel) [radio|sonos] [op] {source} [af|op|naar] [in] [de] {media_player}"
- "(zet|wijzig|speel) [radio|sonos] {media_player} op {source}"
response: default```
no, with the spaces, so that response is at the same level as sentences
Ah ok
responses:
intents:
HassGetState:
default: "OK, {{ slots.source }} wordt afgespeeld in {{ slots.media_player }}"
intents:
SonosSource:
data:
- sentences:
- "(zet|wijzig|speel) [radio|sonos] [op] {source} [af|op|naar] [in] [de] {media_player}"
- "(zet|wijzig|speel) [radio|sonos] {media_player} op {source}"
response: default```
Still got no response and only the 3 dots?
The intent_script looks like this
SonosSource:
action:
- service: "media_player.play_media"
target:
entity_id: "{{ media_player }}"
data:
media_content_type: "favorite_item_id"
media_content_id: "{{ source }}"```
in the debug tool?
No it the normal Assist window
anything appearing in the HA logs as a consequence?
No strange thing is that it dont outputs a warning?
π€·ββοΈ i'm out of ideas. have you tried turning it off and on again? π
π€£
Anyway thanks allot for your time and support, learned some things i can maybe use in other cases. π
Anyway the code i shared seems OK to you?
I mean the two latest blocks i shared.
yes
You still there? π
This one works perfect for my Apple TV sources?
action:
- service: "media_player.select_source"
target:
entity_id: "{{ media_player }}"
data:
source: "{{ source }}"
speech:
text: |-
"OK, {{ source }} wordt afgespeeld op {{ state_attr(media_player, 'friendly_name') }}"```
so is it possible to do something like {{ source.out }}?
Tested allot of different things but nothing seems to work
Ok think I found a solution to use {{ source }}. π
The out value is available by default in intent scripts
Check out what your issue was initially
This is what i mean
Ok fixed it
For some weird reason the sensor.favorites also can be used with service: media_player.select_source
So i changed the action and now it works fine with {{ source }}.
I tested changing {{ state_attr(media_player, 'friendly_name') }} with {{ slots.name) }} or {{ slots.media_player) }} but name returns the entity and media_player returns nothing
So it seems i have to keep {{ state_attr(media_player, 'friendly_name') }}
That works for intent script responses with speech, yes
So I canβt replace it with slots.name?
Not that itβs a big deal but it makes the code a bit cleaner.
It's not yet supported. I want it to be, if you are asking my opinion π