Automation Question - Resume cast audio

Been struggling trying to figure out a way to resume cast audio in the event it is interrupted by one of my “open door/open window” audio alerts.

For example, I have a script to play Internet Radio to one of my Google Minis via Home Assistant. I have automations that cast “Front Door is Open” to selected minis. The issue is, if I’m playing Internet Radio on one of them - it doesn’t resume.

Does anyone have an example of how to best handle this if there is a way?

Thanks!

- Mark

You should be able to look at the media_content_id and stuff like that under attributes in Developer Tools. Try looking on the forums for other questions (search keyword: resume music).
PS: your - rendered as a bullet point, try using backticks around it, like this:
- Kendell

Probably should have mentioned I made *.mp3 audio files from the Google TTS output files for my automation to avoid it from needing the Internet/cloud and could play them local.

What would be ideal is somehow to “save state” of the google mini prior to running the door/window MP3 playing, so it could return to what it was playing previously.

Here is an example of one of my automations. At the end, it has a condition to return to playing a 12 hour whitenoise if it is nighttime.

 - id: Doors_and_Windows_Opened
  alias: 'Doors and Windows Opened'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: 
      - binary_sensor.front_door
      - binary_sensor.garage_entry_door
      - binary_sensor.kitchen_sliding_door
      - binary_sensor.foyer_window
      - binary_sensor.basement_sliding_door
    from: 'off'
    to: 'on'
  mode: restart
  action:
#    - service: script.radio_paused_for_message
    - service: switch.turn_on
      entity_id:
        - switch.beep_beep
        - switch.beep_beep_2
    - service: media_player.play_media
      entity_id:
        - media_player.marks_office_hub
        - media_player.foyer_mini
        - media_player.master_bedroom_mini
        - media_player.family_room_mini
        - media_player.basement_mini
      data_template:
        media_content_id: >
            http://192.168.0.14:8123/local/{{trigger.entity_id}}_is_open.mp3
        media_content_type: 'music'
#    - service: script.resume_radio_paused_for_message
    - condition: time
      after: '22:00:00'
      before: '06:30:00'
    - delay:
        seconds: 11
    - service: media_player.play_media
      data:
        entity_id:
          - media_player.master_bedroom_mini
      data_template:
        media_content_id: 'http://192.168.0.14:8123/local/White_Noise_10hrs.mp3'
        media_content_type: 'music'

Basic outline:

  • Make a couple of input_texts
  • Do something like this before you change it
    - service: input_text.set_value
      data_template:
        entity_id: input_text.media_id
        value: '{{state_attr(''media_player.mything'', ''media_content_id'')}}'
  • Later call media_player.play_media

Or you could use the scene create / restore actions to save your player’s state, anounce the message then restore the state.

See the example here: https://www.home-assistant.io/integrations/scene/#creating-scenes-on-the-fly

Great suggestions! Going to start tinkering, thanks!

Here is an example of my Google Office Hub playing Pandora. Currently, if the door opens and it plays the “Front Door is Open” mp3, it will stop Pandora and not resume.

Could capturing the media_content_id here allow it to resume? The other thing I just thought of, it is could get hosed up because it will say “Front Door Open”, then another MP3 for “Front Door Closed” shortly after (normally). It could potentially capture the previous automation’s info and still break the resuming of Pandora.

media_player.marks_office_hub	playing	volume_level: 0.26999998092651367
is_volume_muted: false
media_content_id: http://audio-sv5-t1-2-v4v6.pandora.com/access/4225969463000742574.mp4?version=5&lid=177595983&token=ekKLDAkCa8iEEKcPqsAkzmCqyydFAjwIcBxHTv6uYBx0J2XwVIsRnsF%2FtMmeXrmZMDm7%2FduaP%2Bx8uN0zrT%2FI511KddPYlEFBLF%2FBriTzMwYjUcG3bHfXmxvK23TGoTTdq5Lgp2A7UlTBCJS5bhPMyb%2BuneBYQen9X%2Fqef%2FvrwcuNzQa%2BLGLVStqjz6FJIfFdiPiUe%2FXwD%2F8IHzgNgWw2dDiu2CvlRB2RqgNgDsjUMz6aZpBnmzSocY39MVfQOBh6ZZ96DOedlhVmkypGBze9ahnvSUgB%2FUumFKIB4u6mFa5GhnKGC7Q86FmntdiPdp8Me1OVjbdhICPVn5pDr8iPgA%3D%3D
media_content_type: music
media_duration: 515
media_position: 29
media_position_updated_at: 2020-08-02T20:18:54.721885+00:00
media_title: The Grudge
media_artist: TOOL
media_album_name: Lateralus
media_album_artist: TOOL
app_id: 211CD751
app_name: Pandora
entity_picture_local: /api/media_player_proxy/media_player.marks_office_hub?token=0675489837cecfd42628574c53ee8d8ff9f62f17016ed40f8fdb50083c5bd85e&cache=34de9a4c7329f963
friendly_name: Mark's Office Hub
entity_picture: http://cont-4.p-cdn.us/images/public/int/4/6/7/4/886447824764_500W_500H.jpg
supported_features: 21437

@MarkHofmann11did you ever get this resolved?

Unfortunately, not. Part of the issue is I have a door open and door closed automation. If you open/close a window/door quickly, even if I was able to save the music playing prior to the open, the close would save the door open audio as being the last thing playing vs music. Just can’t figure out a perfect solution for this. First, I would need to ensure my door/window open/close automations were the same automation (not two different ones). Then maybe saving the audio prior to triggering would work. Just seems like there should be a much easier way to do this.

It would be so much easier if there was a “service snapshot” and “service restore” option similar to what you can do with the sonos speakers.

Did you ever make any progress on this? I am doing my own research now. I was wondering if my cast implementation would help your concern of the automations being done in the same automation. Basically I created a nodered flow to receive homeassistant/speak mqtt messages to initiate casts to speakers independent of the original automations.

Unfortunately not. I have never been able to “save/store” the previous status of what was playing on the Google mini/hub speakers to play “Front Door Open”, and then have it return to playing the same thing. Cast just stops whatever is playing and doesn’t resume.

The work-around would be to have dedicated google minis for different things. Not optimum, but I have no other solution at the present time.

I figured out how to capture the current state by monitoring msg.payload.playerState of node-red-contrib-castv2 for my google home and using a function to save the media data including spotify track and current time vs song duration to the current flow object.

I ran into a snag that in order to (re) initiate a spotify cast it requires a user authenticated request. I thought I found a node that would do that but couldn’t get it to work. I’ll keep trying and report.