#Controlling media players with custom sentences not working

1 messages · Page 1 of 1 (latest)

languid jacinth
#

Hi, I am having a problem for using custom sentences in the "custom_sentences/en "path with the config.yaml for controlling media players... it responds but doesn't execute actions. Does anyone have solutions for that, because I followed the documentation and did the exact first, then tried modifying the "intent_script" in configuration.yaml in different ways, and nothing works: https://www.home-assistant.io/voice_control/custom_sentences/

`

Example config/custom_sentences/en/media.yaml

language: "en"
intents:
SetVolume:
data:
- sentences:
- "(set|change) {media_player} volume to {volume} [percent]"
- "(set|change) [the] volume for {media_player} to {volume} [percent]"
- "(set|change) [the] {media_player} volume to {volume} [percent]"

lists:
media_player:
values:
- in: "living room"
out: "media_player.lg_tv"
- in: "bedroom"
out: "media_player.vlc_telnet"
volume:
range:
from: 0
to: 100
`

Home Assistant

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

#
# Example configuration.yaml
intent_script:
  SetVolume:
    actions:
      service: "media_player.volume_set"
      data:
        entity_id: "{{ media_player }}"
        volume_level: "{{ volume / 100.0 }}"
    speech:
      text: "Volume changed to {{ volume }}"
late vine
#

first of all

intent_script:
  SetVolume:
    actions:
      service: "media_player.volume_set"
      data:
        entity_id: "{{ media_player }}"
        volume_level: "{{ volume|float(0) / 100.0 }}" # <--- convert to float before dividing
    speech:
      text: "Volume changed to {{ volume }}"
languid jacinth
late vine
#

oh, right

intent_script:
  SetVolume:
    actions:
      service: "media_player.volume_set"
      target: # <- this is how you specify the target
        entity_id: "{{ media_player }}"
      data:
        volume_level: "{{ volume|float(0) / 100.0 }}" # <--- convert to float before dividing
    speech:
      text: "Volume changed to {{ volume }}"
#

you should test the calls you make in intent_scripts in the actions dev console before using them

languid jacinth
#

Alright, here are the results:

intent:
  name: SetVolume
slots:
  media_player: bedroom
  volume: '30'
details:
  media_player:
    name: media_player
    value: media_player.vlc_telnet
    text: bedroom
  volume:
    name: volume
    value: 30
    text: '30'
targets: {}
match: true
sentence_template: (set|change) {media_player} volume to {volume} [percent]
unmatched_slots: {}
source: custom
file: en/media.yaml
late vine
languid jacinth
#

That's my current configuration:

intent_sctipt:
  SetVolume:
    actions:
      service: "media_player.volume_set"
      data:
        entity_id: "{{ media_player }}"
        volume_level: "{{ volume | float(0) / 100.0 }}"
    speech:
      text: "Volume changed to {{ volume }}"

What to modify?

late vine
#

even commenting what the modification is

languid jacinth
# late vine oh, right ```yaml intent_script: SetVolume: actions: service: "media...

Doesn't work also as expected!

intent:
  name: SetVolume
slots:
  media_player: bedroom
  volume: '31'
details:
  media_player:
    name: media_player
    value: media_player.vlc_telnet
    text: bedroom
  volume:
    name: volume
    value: 31
    text: '31'
targets: {}
match: true
sentence_template: (set|change) {media_player} volume to {volume} [percent]
unmatched_slots: {}
source: custom
file: en/media.yaml

Almost, the same resutls.

#

As I am saying I tried modifying it several times, and nothing works!

#

in different ways

late vine
#

there should be log messages with errors. you should say what you tried "several times", as nobody can guess
you can stop pasting the debug, as we've seen that the slot gets nicely populated. the trouble seems to be with the action call in your intent_script

#

saying "you've tried things" and "nothing works" does not help anyone help you

languid jacinth
# late vine saying "you've tried things" and "nothing works" does not help anyone help you

For example, I tried to replace service with action as it was changed in the recent update:

intent_sctipt:
  SetVolume:
    actions:
      action: "media_player.volume_set"
      target: # <- this is how you specify the target
        entity_id: "{{ media_player }}"
      data:
        volume_level: "{{ volume|float(0) / 100.0 }}" # <--- convert to float before dividing
    speech:
      text: "Volume changed to {{ volume }}"
late vine
#

It was changed for automations and scripts, not for intent_script

languid jacinth
#

I could reach nothing in the log file: home-assistant.log

languid jacinth
#

And nothing happens!

stark rain
#

Another thing to do is to create actual script with this logic, with corresponding fields - and use it in intent script. Then you can actyally trace it after calling, and see the error.

languid jacinth
#

How to implement it in actual script?

#

How to define that triggered sentence in a separate script? as it's a part of an intent script

late vine
#

you don't. the only action in your intent script will be calling the script, providing parameters such as volume and target

olive willow
#

Also, if you use the dev tools and directly call the media_player.volume_set command with those arguments, does it work? I don't think every media player entity supports set volume, it's dependent on that particular media_player implementation

languid jacinth
#

Yeah, I tried it with dev tools for both media players: vlc telnet and the lg tv

#

The strange thing is that it doesn't work with sentences after following the documentation!

olive willow
#

but it does work in dev tools?

#

And if you try this intent in the Assist chat, you get back the expected reply from it?

#

And maybe a dumb question, but after you added the intent script, did you reload conversation and intent scripts from dev tools YAML section?

languid jacinth
olive willow
#

I assume {{ volume }} is the actual volume level?

languid jacinth
#

It should be the determined volume by the sentence

olive willow
#

Yeah, is that what it is showing? Or is it just showing the template variable?

#

Also not sure if this is causing problems, but usually the action portion of the intent script isn't wrapped in quotes

#

the media_player.volume_set value

languid jacinth
#

when testing it in a script or dev toos it says: "Error rendering data template: UndefinedError: 'volume' is undefined"

olive willow
#

yeah, so volume needs to be a slot passed to the intent script from your intent. So if whenever you call this from chat, it replies back and shows {{ volume }} instead of the volume you asked, that means volume isn't getting passed into the intent script, which would be why no action is occurring 🙂

#

so it would be a matter of figuring out why that is happening if that's the case

#

though usually I think the system log would report that, like the intent attempting to fire with an invalid value.

languid jacinth
#

This happens when using assist, but action doesn't execute

olive willow
#

and your system log doesn't report anything about the intent run?

#

Home Assistant Core Log

languid jacinth
#

No I can't find anything in the log related to volume or intents

olive willow
#

may not show as intent, it would usually report that a service was called with invalid arguments

#

also as a debugging step, you could try adding {{ media_player }} to your speech output string to ensure it is actually correctly resolving the media_player slot

#

like "Volume on {{ media_player }} changed to {{ volume }}"

#

and we're sure media_player.vlc_telnet is the actual entity ID for what you are trying to control? 🙂 There's also a way in scripts to resolve the entity ID from the friendly name

#

And also not sure if you are aware, but I think there's actually a built-in intent in Home Assistant for setting volume now that I think of it

#

actually just tested that and it is working for my media players without any custom intent script

#

Another thing I just thought of, are the devices you are trying to control exposed to assist?

#

because I think if they are not exposed, then the intent script will not be allowed to touch them

languid jacinth
#

It works only by default when a device is playing, but if not it says that no device is playing

#

for example, like when the LG TV is on the Live TV input

languid jacinth
olive willow
#

might need to see if they are exposed to assist.

languid jacinth
olive willow
#

Otherwise not sure what could be wrong. I have some custom intent scripts that work this way and havent had any issues like this :/

languid jacinth
olive willow
#
description: "Used to increase the volume on a media player. Takes one argument 'name' which is the name of the media player to lower the volume on."
action:
  - repeat:
      count: 5
      sequence:
        - service: media_player.volume_up
          target:
            entity_id: >-
              {{ states.media_player | selectattr('name', 'in', name) | map(attribute='entity_id') | list | first | default }}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 200
speech:
  text: "Increased volume on {{name}}."

This is a script I use to bump volume, maybe you can use this as a template that might help.

#

this one works by deriving the entity ID from the spoken friendly name.

#

I use this with an LLM though, so I don't have a sentence/intent set up for it but should work the same.

#

or a simpler example:

description: "Used to stop a media player. Takes one argument, 'name', which is the name of the media player to stop."
action:
  - service: media_player.media_stop
    target:
      entity_id: >-
        {{ states.media_player | selectattr('name', 'in', name) | map(attribute='entity_id') | list | first | default }}
speech:
  text: "Stopped {{name}}."
languid jacinth
#

All what I want is to determine the volume number I want to set in a sentence and it executes the action even when the device state doesn't appear playing, I am trying it within a long time ago since I got the documentation, but can't reach solutions till now. Cause I want to use this also to set alarms by sentences determineing the date and time, and when it comes then play a specific audio on media player and so on.

late vine
#

Did you do what both Nick and i suggested, i.e. test the action in the dev tools?

languid jacinth
#

and this is logical, cause the sentence didn't trigger

#

but when doing something like this in dev tools it works normally:

action: media_player.volume_set
data:
  volume_level: 0.38
target:
  entity_id: media_player.vlc_telnet
#

At this point, I think the problem is with the intent script itself!

languid jacinth
#

which should set it to 38 when the sentence is triggered

late vine
late vine
languid jacinth
#

I restarted home assistant many times

#

after each change in the configuration.yaml

late vine
#

I nearly forgot: do you have

conversation:

in your configuration.yaml?

languid jacinth
#

Yes

late vine
#

well, actually, sure you do. Otherwise the custom sentences wouldn't get recognized

languid jacinth
#

For this:


conversation:
  intents:
    HelloIntent:
      - "hello"
      - "hi"
      - "hey"
      - "hey Jarvis"
      - "hello Jarvis"
    WhatsUpIntent:
      - "what's up"
      - "how are you"
      - "how are you Jarvis"
      - "how are you doing"
      - "how are you doing Jarvis"
      - "what's going on"
      - "what's going on Jarvis"
    NameIntent:
      - "what is your name"
      - "what's your name"
      - "who are you"
      - "tell me your name"
    AgeIntent:
      - "how old are you"
      - "how old are you Jarvis"
      - "what's your age"
      - "what's your age Jarvis"
      - "tell me your age"
      - "tell me your age Jarvis"
    JokeIntent:
      - "tell me a joke"
      - "tell me a joke jarvis"
      - "say a joke"
      - "say a joke jarvis"
      - "tell a joke"
      - "tell a joke jarvis"
      - "joke"
    RiddleIntent:
      - "tell me a riddle"
      - "tell me a riddle jarvis"
      - "say a riddle"
      - "say a riddle jarvis"
      - "tell a riddle"
      - "tell a riddle jarvis"
      - "riddle"
    StoryIntent:
      - "tell me a story"
      - "tell me a story jarvis"
      - "say a story"
      - "say a story jarvis"
      - "tell a story"
      - "tell a story jarvis"
      - "story"
    ThanksIntent:
      - "thanks"
      - "thanks Jarvis"
      - "thanks so much"
      - "thanks so much Jarvis"
      - "thank you"
      - "thank you Jarvis"
      - "thank you very much"
      - "thank you very much Jarvis"
      - "much appreciated"
      - "much appreciated Jarviis"
    SetAlarmIntent:
      - "set an alarm for {datetime}"
      - "wake me at {datetime}"
      - "wake me up at {datetime}"
      - "set alarm at {datetime}"
      - "set the alarm at {datetime}"
      - "set an alarm for {datetime} jarvis"
      - "wake me at {datetime} jarvis"
      - "wake me up at {datetime} jarvis"
      - "set alarm at {datetime} jarvis"
      - "set the alarm at {datetime} jarvis"
#

But, the intent script for media player in this path: config/custom_sentences/en/media.yaml

late vine
#

I'm not sure this works in tandem with custom_sentences. Could you temporarily delete everything apart from the first line?

late vine
#

to be able to define custom sentences

languid jacinth
#

Alright, I did this and tested the intent after restarting, and nothing happens!

late vine
#

but the intent is recognized, right? it just does not alter the volume

late vine
languid jacinth
#

I did this and it also responds but does nothing! as expected:

SetVolume:
    actions:
      service: notify.persistent_notification
      data:
        message: set volume
    speech:
      text: "Volume changed to {{ volume }}"
#

I know from the start that it won't work, before testing

languid jacinth
#

Something else on my mind that I've been suspecting for a while but I don't want to judge it now lest I be a liar until I'm finally sure

languid jacinth
#

Did anyone find solutions for that?

stark rain
#

Damn. It was hard to notice.
Replace your actions: with action:, that's correct syntax.

languid jacinth
#

Honestly, I copied and pasted from the documentation

stark rain
#

Well, all i can say i don't see anything wrong with your code. Mine has sections action and speech, and i was copying from docs too. So maybe you try?

languid jacinth
#

Do you believe it worked?😃

stark rain
#

Although in list of params it's called "actions". Looks like mistype

stark rain
languid jacinth
stark rain
#

For sure. It's inconsistent even on that single page.

#

You may make a PR for that.

#

Best place for first PR honestly 🙂

languid jacinth
#

Sure☺️ I will

novel plaza
#

Thanks @stark rain for catching that! Let me know when your PR is ready @languid jacinth 🙂

languid jacinth
#

Going to do it right now!

#

Alright?

stark rain
#

There's another "actions" on the bottom of the page.

languid jacinth
#

Where? I can't find any other intent_script in yaml except this one that I modified:

# Example configuration.yaml
intent_script:
  SetVolume:
    actions:
      service: "media_player.volume_set"
      data:
        entity_id: "{{ media_player }}"
        volume_level: "{{ volume / 100.0 }}"
    speech:
      text: "Volume changed to {{ volume }}"
stark rain
languid jacinth
stark rain
#

Both have...

#

Thanks for digging this one too! Good job!

stark rain
# languid jacinth This one?

Geezuz. I guess it all convoluted?
I wonder when was this introduced - from scratch, or with renaming services to actions...

#

Try searching for "actions:" in whole repo - probably it wasn't good assumption about easy-peezy PR...

languid jacinth
#

I actually did

languid jacinth
stark rain
#

Is it in different repo?

languid jacinth
#

It's a another file in different source

stark rain
languid jacinth
#

Yea, I modified it too

stark rain
languid jacinth
#

OK, done

stark rain
#

@novel plaza wanna take a look?

stark rain
#

Franck merged it. Congratulations!

languid jacinth
#

Yes👍 ✌️