#Custom sentence for playback on sonos speaker

1 messages Β· Page 1 of 1 (latest)

ashen flint
#

Yes, please, share some code

granite root
#

Sorry missed your message, can i upload here more than 15 lines or do i use pastebin?

distant muralBOT
#

Please use a code share site to share code or logs, for example:

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.

granite root
#

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.

ashen flint
#

so source is going into state_attr(media_player, 'media_title') and it takes a while, right?

granite root
#

Yes correct

ashen flint
#

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

granite root
#

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 πŸ™‚

ashen flint
#

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

granite root
#

Give me a second i going to test it right away.

ashen flint
#

also, if you use slots.source in the reponse, you no longer need the delay, as the value is available immediately

granite root
#

Yes going to remove the wait trigger and change the state_attr(media_player, 'media_title') with {{ slots.source }}.

ashen flint
#

that's a delay action, not a "wait trigger". a "wait trigger" actually exists and is something else

granite root
#

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?

ashen flint
#

if it said something went wrong, there should be an error in the HA core logs. What is it?

#

the response seems ok, yes

granite root
#

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') }}"'

ashen flint
#

but like i said, i can't remember if you can use slots in the intent_script response

#

oh, there it is

granite root
#

slots is undefined, no idea why πŸ™‚

ashen flint
#

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

granite root
#

Without the brackets?

ashen flint
#

with them, i've edited the reply

granite root
#

Oh okay just a second.

ashen flint
granite root
#

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 πŸ™‚

ashen flint
#

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?

granite root
#

Yeah it don't make sense to me because i don't know all these codes for every radiostation πŸ™‚

ashen flint
#

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

granite root
#

do i keep the speech: part itself?

ashen flint
#

nope

granite root
#

OK wait i going to show you if it is correct what i do

ashen flint
granite root
#

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}"
ashen flint
#

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

granite root
#

Going to test, but the place i added it is OK?

ashen flint
#

yeah, it's fine

granite root
#

ok

ashen flint
#

spacing was the most important, as it always is in YAML

granite root
#

Now it just stays on the 3 dots response

ashen flint
#

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

ashen flint
granite root
#

yes

#

Just true the Assist icon

ashen flint
#

ok. have you reloaded conversation?

granite root
#

I always reload all yaml config?

ashen flint
#

ok, that's good

#

and paste the output

granite root
#

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```
ashen flint
#

you haven't updated the sentence or list, so that's still relevant

#

but why have you switched back?

granite root
#

I was just checking what it outputs

#

just a second i'm to test it with your solution πŸ™‚

ashen flint
#

it should be the exact same

granite root
#

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```
ashen flint
#

the same, as expected

#

only it works and doesn't time out

granite root
#

it still outputs the 3 dots

#

in the normal assist...

ashen flint
#

then paste the RAW output (full) here

granite root
#
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```
ashen flint
#

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
granite root
#

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```
ashen flint
#

no, with the spaces, so that response is at the same level as sentences

granite root
#

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 }}"```
ashen flint
granite root
#

No it the normal Assist window

ashen flint
#

anything appearing in the HA logs as a consequence?

granite root
#

No strange thing is that it dont outputs a warning?

ashen flint
#

πŸ€·β€β™‚οΈ i'm out of ideas. have you tried turning it off and on again? πŸ˜…

granite root
#

🀣

#

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.

ashen flint
#

yes

granite root
#

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 }}?

granite root
#

Tested allot of different things but nothing seems to work

#

Ok think I found a solution to use {{ source }}. πŸ™‚

ashen flint
#

Check out what your issue was initially

ashen flint
granite root
#

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') }}

ashen flint
#

That works for intent script responses with speech, yes

granite root
#

Not that it’s a big deal but it makes the code a bit cleaner.

ashen flint
#

It's not yet supported. I want it to be, if you are asking my opinion πŸ˜‹

granite root
#

Well seems very reasonable for me also to add this. πŸ˜‰

#

One last question. Don’t know if you familiar with Siri Shortcuts? Is there any change to output the speech to a shortcut. Will be good to also have the response wen I’m using the Voice Assist Siri Shortcut.