#How to have the music pause?

1 messages · Page 1 of 1 (latest)

worldly pasture
#

According to https://esphome.io/components/voice_assistant.html, there's two events (on_listening and on_wake_word_detected) which should let me have something happen once I say "Hey Jarvis". I tried both. Alas, the music keeps on playing. Where am I going wrong?

alias: Pause Music on wake word
description: ""
triggers:
  - event_type: on_listening
    trigger: event
conditions: []
actions:
  - action: media_player.media_pause
    metadata: {}
    data: {}
    target:
      floor_id: og3o
little jacinth
worldly pasture
#

Koala Satellites. Everything works. I can even ask Jarvis to tell me a joke. With classical music (i.e. without anyone singing, just instruments) it even works with the music playing. Otherwise he gets confused.

#

Actually, it's impressive how well the wakeword works. In the kitchen, there's very powerful speakers and they're only half a meter from the satellite. Even at high volume levels and me further from the satellite than the speakers are, the wakeword still works.

little jacinth
#

I think you want to trigger on the state of the entity instead of event

#
entity_id:
  - assist_satellite.YOUR_DEVICE_ENTITY
to: listening
#

i think you got a bit confused between home assistant automations and esphome firmware config files.

you could probably do this on the hardware too with esphome config but i would have to see your devices config to suggest on that

worldly pasture
#

okay, so that fixed the trigger part. the action part is weird. it seems only the satellites are actually seen as media players. the snapcast clients (via music assistant) are ... not?

#

music assistant itself has no pause action

#

that's why i went with this

#

which unfortunately doesn't list the speakers, only the satellites

#

they're all there though (except for the workshop-speakers, which is alright, since they're turned off, like the workshop-satellite)

little jacinth
#

so if you you use media player cause and hit "choose entity" they dont show up in the suggested list?

little jacinth
#

what happens if you manually put in the entity?

worldly pasture
#

Oh! "Entity media_player.kitchen_speakers does not support action media_player.media_pause."

#

Aha! But the Stop action works!

little jacinth
#

yeah some players may just not support pause, thats why it hid them i guess

worldly pasture
#

Makes sense.

#

I just installed Music Assistant because this didn't work with the Snapcast Integration. Perhaps I should take another look at that, too.

little jacinth
#

snapcast doesnt support pause by the looks of it

#

music assistant documentation
Pausing has been implemented as best as can be achieved with the limitations of Snapcast. MA issues a STOP and RESUME command to achieve the pause effect but this means the resulting player state never changes to paused.

#

music assistant has to workaround

worldly pasture
#

that would work as far as snapcast is concerned, but the Snapcast Integration doesn't provide such a workaround, and the Music Asisstant Integration seems to not make use of Music Assistant's workaround.

#

i can set the volume though.

little jacinth
#

you could get them to stop by just sending pause to to the sattilites and sending stop to the others

the resuming might be the issue, although music assistant might take care of that automatically. i am not sure

worldly pasture
#

the satellites are not supposed to pause.

#

and i'd prefer to be able to uninstall music assistant again, if at all possible. i only installed it because i wasn't able to make it work through the snapcast integration.

little jacinth
#

fair enough, sending the stop command is going to be the best you can do i think whichever way you integrate them

worldly pasture
#

i'm now thinking that lowering the volume is actually kinda more elegant 🙂

little jacinth
#

yeah surpresing the output whilst talking is not a bad plan

#

something like

trigger on listen
create variable with player volume
change volume to 10% (or whatever)
wait for state to leave listening
set volume to variable stored earlier

worldly pasture
#

oh wow, i was just researching how this might work.
so there's variables and a way to wait for a state to change.
i have some documentation to read it seems.

worldly pasture
# little jacinth something like trigger on listen create variable with player volume change volu...

I aaaalmost have it working! I think the variable is being saved, but what's not working is to restore it. If it's a fixed number instead, then it's working fine. Looks like this now:

alias: Mute speakers on wake word
description: ""
triggers:
  - trigger: state
    entity_id:
      - assist_satellite.kitchen_satellite_assist_satellite
    to: listening
conditions: []
actions:
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.01
    target:
      entity_id: media_player.og3o_snapcast_group
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - assist_satellite.kitchen_satellite_assist_satellite
        to: idle
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ previous_volume | float }}"
    target:
      entity_id: media_player.og3o_snapcast_group
variables:
  previous_volume: "{{ states('media_player.og3o_snapcast_group.volume_level') }}"
#

Complains it's not float despite the | float.

little jacinth
#

dont define variable there or like that

#

sec

#
description: ""
triggers:
  - trigger: state
    entity_id:
      - assist_satellite.kitchen_satellite_assist_satellite
    to: listening
conditions: []
actions:
  - variables:
      previous_volume: "{{ state_attr('media_player.og3o_snapcast_group', 'volume_level') }}"
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.01
    target:
      entity_id: media_player.og3o_snapcast_group
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - assist_satellite.kitchen_satellite_assist_satellite
        to: idle
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ previous_volume }}"
    target:
      entity_id: media_player.og3o_snapcast_group```
worldly pasture
#

oh, inside the action

#

and no type casting needed

little jacinth
#

no i dont think it should need it as you are reading a float using state_attr

#

if it fails you can try casting to float again but i dont think its needed

worldly pasture
#

it's working!!!

#

thank you so much, Michael!

#

first time i've faced a non-trivial automation 🙂

little jacinth
#

no worries, I hope you learned a thing or to about how stuff works and will be easier next time

#

suppression i think is totally a better way to go tbh. its how voice satellites like the VPE deal with stuff playing whilst running assist

#

and for what its worth, give music assistant a go. its really great. i have been playing with it a bit recently and its pretty cool

worldly pasture
worldly pasture
# little jacinth and for what its worth, give music assistant a go. its really great. i have been...

I have nothing against it, it's just not really intended to work how i work. usually i'll sit at my desktop or have the laptop nearby, open up Youtube or Spotify or some radio station's website and want that to come out of all the speakers. hence the solution with everything centered around Snapcast. Plus, unfortunately Music Assistant has a very particular (non-configurable) way of how it deals with Snapcast.

little jacinth
#

yeah that's fair enough

#

if what you have works then go for it 🙂