TTS to media_player and resume stream

Hello everyone!
Just solved one of my major problems and thought to share.
THIS WILL ONLY WORK IF YOU’RE STREAMING!
Setup:
I have only simple media_players (1 Kodi, 1 mpd with snapcast and 3 snapcast clients). No google home devices to use broadcast. Kodi is usually turned off unless playing a movie or something and it’s set on a pc, so I don’t use it for TTS as it’s no point. MPD with snapcast on the other hand is perfect for the job since it’s always on. When it’s playing music, it’s from a web radio, meaning it’s a stream.
The problem is that when MPD streamed radio and I used the TTS service, it stopped the stream, played the TTS and then, silence! That was frustrating!
So along searching and getting replies on how to keep the stream and restart it(thanks everyone who helped!), I eventually figured it out.

Steps:
First of all, install hass-variables from here:

Then we go to configuration.yaml and declare our variables:
variable:

  mpdstream:
    value: 0
    attributes:
      icon: mdi:volume-high
  mpdcheck:
    value: 0
  ttssay:
    value: 0

mpdstream is the variable where we will store our stream url
mpdcheck is a variable to check if the media_player was previously streaming. If not, there’s no point to start playing radio!
ttssay is the variable where we will store our message. I didn’t use it at first, but I have at least 3 automations using this tts with radio and it was no point to flood the automation.yaml with code not needed. You’ll understand later.

Moving on to automation.yaml:

- id: Overtemp
  alias: Suggest options when temp is too high
  trigger:
  - platform: numeric_state
    entity_id: sensor.0x00158d00036b744d_temperature
    above: 29.00
    for:
      minutes: 2
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: group.all_devices
      state: home
  action:
    - service: variable.set_variable
      data:
        variable: ttssay
        value: 'Temperature on living room is high. Turn on the A C'
    - service: script.ttssay

This is just an example. You only care about the action part. This is where we store a random message to the variable ttssay. And we call the script ttssay.

Moving on to the last part, scripts.yaml:

ttssay:
    alias: Say google commands
    sequence:
    - service: variable.set_variable
      data:
        variable: mpdcheck
        value_template: >
          {% if is_state('media_player.mpd', 'playing')  %}
          1
          {% else %}
          0
          {% endif %}
    - service: variable.set_variable
      data_template:
        variable: mpdstream
        value: > 
          {% if is_state('variable.mpdcheck', '1') %}
          {{ states.media_player.mpd.attributes.media_content_id }}
          {% else %}
          http://radio.1055rock.gr:30000/1055
          {% endif %}
    - service: tts.google_say
      entity_id: media_player.mpd
      data_template:
        message: '{{ states.variable.ttssay.state }}'
        language: 'en'
    - delay: '00:00:07'
    - service_template: >
          {% if is_state('variable.mpdcheck', '1') %} 
          script.mpdrestore
          {% else %} 
          script.mpdoff
          {% endif %}

Ok this is where it gets somewhat tricky. Here we check at first if our media_player (media_player.mpd in my case) is playing and if yes, we store 1 to variable mpdcheck, if not we store 0.
Next one is for my flavor. Since I usually listen to a standard station and I have a button on the house that toggles the media_player, I want to have the stream ready at all times. I just hit turn on media_player.mpd and it starts this stream. But if the media_player was already playing another stream, it will store that instead.
So what this does is, if the media_player is playing now, store it’s stream to the variable mpdstream. If it’s not playing, store the stream http://radio.1055rock.gr:30000/1055 (or your personal flavor)
Next one is of course the tts! It will say whatever we stored on automations. This is very handy since you can have multiple automations with tts and you wont fill the yaml with useless code! The variable stores in whatever language, it doesn’t care! So in my case it’s Greek with Greek characters and it works correctly.
Next one is a delay that waits for the tts to finish before launching the stream to the media_player.
And last, we check again if the media_player was playing or not and we launch the appropriate script.
The last scripts are:

mpdrestore:
    alias: Restore Stream from welcome home automation
    sequence:
      - service: media_extractor.play_media
        data_template:
          entity_id: media_player.mpd
          media_content_id: >
            {{ states.variable.mpdstream.state }}
          media_content_type: "music"
            
mpdoff:
    alias: Turn off MPD
    sequence:
      - service: media_extractor.play_media
        data_template:
          entity_id: media_player.mpd
          media_content_id: >
            {{ states.variable.mpdstream.state }}
          media_content_type: "music"
      - delay: '00:00:01'
      - service: media_player.turn_off
        data:
            entity_id: media_player.mpd

Fist one I think is self explanatory. If the media_player was playing, we inject the stream it had and play it.
Second one is for what I mentioned earlier to my personal flavor. It’s a “bandage fix” that tries to play the “default” stream I use and then turn it off, so it will be always loaded when I hit the power on of the mpd. Luckily the mopidy doesn’t play immediately, more of “try to play 200ms of music, then stop, then after 500ms I play normally”. So with the delay I have, I only hear a 200ms sound and it stops. As long as it works, I don’t care.
If you have better solutions, please post!
Or refined code, all answers are welcome!

4 Likes

For the “media_extractor.play_media” to work it requires the following in the configuration.yaml file:

media_extractor:

I haven’t had change to get this all working but its a great post to start with. I noticed you use mpdvolume but do not define it in the variables?
Should that have been defined?

Has anyone had any luck making this work for Chromecasts?

Whoops, that was a typo! Corrected the mpdvolume!
You also stand correct on the media_extractor. It is needed.

I think, but not too sure, I tried it with a google home and worked, so I think it will also work. Then again, since google home had voice commands and has the broadcast feature, I ultimately put the snapcast part on hold. I will return to it when I get the time and plan to use speakers throughout the house and want to sync the radio.
If you can use media_extractor with chromecast and TTS, then you’ll be able to use this

To make this work now, you need to change the line that contains tts.google_say
to
tts.google_translate_say

Thanks for your post. Using your post I was able to create a script myself.
Since I’m using a routine in my Google Assistant settings, I only use a script, and no automation.
I’m also not using the variables plugin from HACS, but the built in helpers in HA (input_text and input_number)

For this script to work, you’ll need to add the input_number.is_playing and input_text.chromecast_stream.

Just placing it here because it might help someone.

trash_container_script:
  alias: Which trash container
  sequence:
  - service: input_number.set_value
    entity_id: input_number.is_playing
    data_template:
      value: >
        {% if is_state('media_player.kitchen_hub', 'playing')  %}
        1
        {% else %}
        0
        {% endif %}
  - service: input_text.set_value
    entity_id: input_text.chromecast_stream
    data_template:
      value: > 
        {% if is_state('input_number.is_playing', '1.0') %}
        {{ state_attr('media_player.kitchen_hub', 'media_content_id') }}
        {% else %}
        http://icecast.omroep.nl/radio2-bb-aac
        {% endif %}
  - service: tts.google_translate_say
    entity_id: media_player.keuken_hub
    data_template:
      message: "The {{states('sensor.next_container')}}. should be place outside {{ state_attr('sensor.next_container, 'when') }} . "
      cache: false
  - delay: '00:00:08'
  - condition: numeric_state
    entity_id: input_number.is_playing
    above: 0.1
  - service: media_extractor.play_media
    data_template:
      entity_id: media_player.kitchen_hub
      media_content_id: >
        {{ states('input_text.chromecast_stream') }}
      media_content_type: "music"

2020-09-23 - I’ve edited this post because I could simplify the script a bit, and added the part on how to call this script from another script or automation

2020-11-06 - Another small edit, because I noticed that service: media_extractor was not needed, and media_player.play_media could be used
I’ve also added a wait template instead of the fixed delay of 8 seconds which was previously included. Left in a 2 second delay because the media player is idle shortly before the TTS starts, and otherwise the TTS would be skipped

For those who stumble upon this posts. As from version 0.115 you can use variables in Home Assistant without additional plugins. I’ve rewritten my script to this. It resumes both TuneIn radio and Spotify.
For Spotify you’ll need Spotcast installed though. And in my script I assumed the Spoify account used on the Google Home is always the same account (the one Spotcast also uses)

kitchen_hub_say:
  alias: Kitchen - TTS for Google Nest Hub in Kitchen
  sequence:
  - variables:
      spotify: >-
        {{ is_state_attr('media_player.keuken_hub', 'app_name', 'Spotify') }}
      playing: >-
        {{ is_state('media_player.keuken_hub', 'playing')  }}
      media_content: >-
        {{ state_attr('media_player.kitchen_hub', 'media_content_id') }}
      media_type: >-
        {{ state_attr('media_player.kitchen_hub', 'media_content_type') }}
  - service: tts.google_translate_say
    entity_id: media_player.kitchen_hub
    data:
      message: "{{ kitchen_hub_say }}"
      cache: false
  - delay: 2
  - wait_template: "{{ is_state('media_player.kitchen_hub', 'idle') }}"
  - service: media_player.turn_on
    entity_id: media_player.kitchen_hub
  - choose:
    - conditions: "{{ spotify }}"
      sequence:
      - service: spotcast.start
        data:
          device_name: Kitchen Hub
    - conditions: "{{ playing }}"
      sequence:
      - service: media_player.play_media
        data:
          entity_id: media_player.kitchen_hub
          media_content_id: "{{ media_content }}"
          media_content_type: "{{ media_type }}"

The media_player.turn_on lines just after the TTS part are to make sure the TTS screen isn’t being displayed on the hub anymore after it is finished.

The script can be called like this from another script or automation:

- service: script.turn_on
  entity_id: script.kitchen_hub_say
  data:
    variables:
      kitchen_hub_say: "Enter text or template containing the text to be sent to the script"
5 Likes

Hi @TheFes I have a question.

I have several google minis around my house and I was wondering if there’s a way to adapt this script in order to be used with several device.

I tried with templating but I’m not good with it!

Thank you!

The same way I stopped using this script, is to use the “broadcast” command for google home minis.
What this does is pause whats playing, say the message and continue automatically.
But it plays on all google home minis. Don’t know if you want this.

Yes I want this but I noticed that if the message contains some word messages are not delivered. So I’m searching for an alternative

Some questions:

  • Do you always want to use the same Google Mini devices for the TTS?
  • Are they playing the same media, or could it be that one is playing radio chanel 1, the other chanel 2, and a third Spotify?

If they don’t play the same media, you would need to create device specific variables, so e.g. spotify_mini_kitchen, and separate actions to play it again. However if you do play the same media, it could become out of sync. It will be a bit tricky I guess.
For playing the same media on seperate devices, I guess you could use speaker groups in the Google Home app, but then you would need to build in additional checks if a spearker group is used.

Sorry I lost the notification.

  1. no I want to use different mini based on different messages and time (avoid bedroom at night for example)

  2. sometimes they play same device from spotify. Sometimes me and my wife listen different musics.

Hi

Sorry from my side as well, notification got lost in my email.
But I’m afraid that does make it a bit more complex, and I currently don’t have the time to dig into it. Working on a big list of HA projects for my own house as well (and my boss also wants me to do my work I get paid for ;))

1 Like

yes you’re right! :slight_smile:

Verry nice,

I try to change the script and detect the casting speaker group and spotify account usage. I have some troubles with my script, but i can’t find out where.

Maybe someone sees it:

My action:

  action:
    - service: script.run_tts_say
      data_template: 
        tts_say: "Test"
        tts_to: "reserve"
        tts_volume: "0.6"

And the script:

run_tts_say:
  alias: TTS Spotify test resume
  sequence:
  - variables:
      spotify: >-
        {{ is_state_attr('media_player.{{ tts_to }}', 'app_name', 'Spotify') }}
      playing: >-
        {{ is_state('media_player.{{ tts_to }}', 'playing')  }}
      media_content: >-
        {{ state_attr('media_player.{{ tts_to }}', 'media_content_id') }}
      media_type: >-
        {{ state_attr('media_player.{{ tts_to }}', 'media_content_type') }}
  - service: tts.google_say
    data:
      entity_id: "media_player.{{ tts_to }}"
      message: "{{ tts_say }}"
      cache: false
  - delay: 2
  - wait_template: "{{ is_state('media_player.{{ tts_to }}', 'idle') }}"
  - service: media_player.turn_on
    entity_id: media_player.{{ tts_to }}
  - choose:
    - conditions: "{{ spotify }}"
      sequence:
      - variables:
          spot_castingto: >-
            {% if is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Reserve') %}
              {{ 'reserve' }}
            {% elif is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Woonkamer') %}
              {{ 'woonkamer' }}
            {% elif is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Keuken') %}
              {{ 'keuken' }}
            {% elif is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Thuisgroep') %}
              {{ 'thuisgroep' }}   
            {% elif is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Beneden') %}
              {{ 'beneden' }}  
            {% elif is_state("media_player.spotify_asterixonline", "playing") and is_state_attr('media_player.spotify_asterixonline','source','Test') %}
              {{ 'test' }}                                              
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Reserve') %}
              {{ 'reserve' }}
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Woonkamer') %}
              {{ 'woonkamer' }}
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Keuken') %}
              {{ 'keuken' }}
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Thuisgroep') %}
              {{ 'thuisgroep' }}  
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Beneden') %}
              {{ 'beneden' }}   
            {% elif is_state("media_player.spotify_joelle", "playing") and is_state_attr('media_player.spotify_joelle','source','Test') %}
              {{ 'test' }}       
            {% else %}
              {{ tts_to }}
            {% endif %}  
          spcast_account: >-
            {% if is_state("media_player.spotify_joelle", "playing") %}
              'joelle'  
            {% else %}
            {% endif %}              
      - service: spotcast.start
        data:
          device_name: "{{ spot_castingto }}"
          account: "{{ spcast_account }}"
      - delay: 4          
      - service: media_player.media_play
        target:
          entity_id: media_player.{{ spot_castingto }}
    - conditions: "{{ playing }}"
      sequence:
      - service: media_player.play_media
        data:
          entity_id: media_player.{{ tts_to }}
          media_content_id: "{{ media_content }}"
          media_content_type: "{{ media_type }}"   

Thanx for advice.

“some troubles” isn’t a lot of information to start debugging :stuck_out_tongue:
Any issues/warnings in your log? Does it work partly, or not at all? etc etc etc.

1 Like

I think the if, else is not working somehow, I get no issues when saving from file editor. But when reloading scripts it gives me a warning about variables. The script is not valid as it don’t show up as a script. I’ll post the error .

The if else then works .

This is an issue:

  - variables:
      spotify: >-
        {{ is_state_attr('media_player.{{ tts_to }}', 'app_name', 'Spotify') }}

the media player identity is not working. and therefore the rest of the script isnt.
Later in the script i use it for sending google tts, and that works well.

  - service: tts.google_say
    data:
      entity_id: "media_player.{{ tts_to }}"
      message: "{{ tts_say }}"
      cache: false

Verry strange.

I didn’t find out how to solve this.

So, i’m verry close, it works with spotify, but when a second message is there, the source status give me a wrong source. When it’s playing on two or more speakers, it give me only one speaker. Maybe that’s an issue with spotcast.

For now the action looks like:

  action:
    - service: script.run_tts_say
      data_template: 
        tts_say: "Test Bericht"
        tts_to: reserve #speaker you want to cast to
        tts_volume: 0.4

And the script:

run_tts_say:
  alias: TTS Spotify test resume
  sequence:
  - variables:
      tts_curvolume: >-
        {{ state_attr('media_player.'~tts_to, 'volume_level') }}
      spcast_joelle: >-
        {{ is_state('media_player.spotify_joelle', 'playing') }}
      spotify: >-
        {{ is_state_attr('media_player.'~tts_to, 'app_name', 'Spotify') }}
      playing: >-
        {{ is_state('media_player.'~tts_to, 'playing') }}
      media_content: >-
        {{ state_attr('media_player.'~tts_to, 'media_content_id') }}
      media_type: >-
        {{ state_attr('media_player.'~tts_to, 'media_content_type') }}
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.{{ tts_to }}
      volume_level: "{{ tts_volume }}"
  - service: tts.google_say
    data:
      entity_id: media_player.{{ tts_to }}
      message: "{{ tts_say }}"
      cache: false
  - delay: '00:00:03'
  - wait_template: "{{ is_state('media_player.'~tts_to, 'idle') }}"
  - choose:
    - conditions: "{{ spotify }}"
      sequence:
      - choose:
        - conditions: "{{ spcast_joelle }}"
          sequence:
          - variables:
              spot_castingto: >-
                {{ state_attr('media_player.spotify_joelle', 'source') }}
          - delay: '00:00:01'            
          - service: spotcast.start
            data:
              entity_id: media_player.{{ spot_castingto }}
              force_playback: true          
              account: joelle
        - conditions: []
          sequence:
          - variables:
              spot_castingto: >-
                {{ state_attr('media_player.spotify_asterixonline', 'source') }}
          - delay: '00:00:01'            
          - service: spotcast.start
            data:
              entity_id: media_player.{{ spot_castingto }}
              force_playback: true          
      - delay: '00:00:01'         
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.{{ tts_to }}
          volume_level: "{{ tts_curvolume }}" 
    - conditions: "{{ playing }}"
      sequence:
      - service: media_player.play_media
        data:
          entity_id: media_player.{{ tts_to }}
          media_content_id: "{{ media_content }}"
          media_content_type: "{{ media_type }}"
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.{{ tts_to }}
          volume_level: "{{ tts_curvolume }}"
    - conditions: []
      sequence:  
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.{{ tts_to }}
          volume_level: "{{ tts_curvolume }}"    

I use multiple spotify accounts, so there is a detection build in.

Maybe someone can use it.

@Reijer and others :slight_smile:
I’ve been doing some updates to the script to support resuming playback on speaker groups and multiply Spotify accounts. I’ve also made it generic, so it can be used for all the Google Home speakers, and not only one specific speaker.

Prerequisites and comments for this new version:

  • You need to create groups in home assistant with the media_players belonging to the speaker groups in the Google Home app. This is used for the player_resume variable
  • My speaker group media_player.home_group contains all my Google Home speakers, so that is why I did not include a check if the speaker is belonging to that group for the player_resume variable
  • In spotcast there is one primary account, you need to enter that one in the variable primary_spotcast
  • For Spotify you need to add the accounts to the Spotify integration, and also to spotcast. Be sure to name the spotify entity_id’s like media_player.spotify_{{ spotcast user }}
  • After the script has been called (e.g. because it announced the doorbell rang) the app_name for radio will no longer be TuneIn Free. So the script did not recognize anymore that radio was playing. As a work around I added a variable where the first part of the TuneIn url of frequently used radio stations can be added, so the media_content_id can be compared to that list.
  • I’ve added a variable where you can add Google Nest Hubs (the ones with screen). If a TTS was played on such a device, and no music is resumed, the TTS cast icon was not removed from the screen.
  • I’m using Microsoft TTS, you eed to change the TTS service to yours if you are not using Microsoft
  • I’ve added fields, so you see which variables can be entered when using the GUI, both in yaml mode, and full GUI. player and tts_message are required. If volume is not entered it will use the volume_old variable for the TTS volume (so basically it will remain the same)
  • There is a short delay for updating the media_content_id attribute for the Spotify integration. I use that to determine which spotcast account should be used. So therefor in case there is only one Spotify account active, it will use that one. In case there is more than one active and the new song just started, it could be that the account is not recognized. In that case the primary account will be used.

The script can be started like this in an automation or script:
In case you want to have your script/automation wait for the TTS script to be completed

  - alias: "TTS voor Nest Hub Kitchen"
    service: script.google_home_say
    data:
      tts_message: "Hello, hello! This is a test!"
      player: media_player.google_kitchen
      volume: 0.35

In case you want your script/automation to resume with the next action immediately

  - alias: "TTS voor Nest Hub Kitchen"
    service: script.turn_on 
    target:
      entity_id: script.google_home_say
    data:
      variables:
        tts_message: "Hello, hello! This is a test!"
        player: media_player.google_kitchen
        volume: 0.35

And this is then the amended script:

google_home_say:
  alias: "TTS for Google Home"
  icon: mdi:cast-audio
  mode: parallel
  fields: 
    tts_message:
      description: "Message to be uses as TTS for Google Home."
      example: "Hello, this is a test message."
      required: true
      selector:
        text:
    player:
      description: "The target Google Home."
      example: media_player.google_keuken
      required: true
      selector:
        entity:
          integration: cast
          domain: media_player
    volume:
      description: "Volume for TTS message (value between 0 and 1)."
      example: 0.25
      required: false
      selector:
        number:
          min: 0
          max: 1
          step: 0.05
          mode: slider
  variables: # General variables for script
    players_screen:
      - media_player.google_kitchen
    # TuneIn stream url without http(s):// until first /. Used because app_name 
    # is not visible after this script has been used before in the same session
    frequent_radio: 
      - icecast.omroep.nl
      - playerservices.streamtheworld.com
    # Make sure the entity_id's match this format, and the last part should 
    # match the spotcast account
    spotify_media_players: 
      - media_player.spotify_user1
      - media_player.spotify_user2
      - media_player.spotify_user3
    primary_spotcast: "user1"
  sequence:
    - alias: "Variables for this specific run of the script"
      variables: 
        volume_old: >
          {{ state_attr(player, 'volume_level') | default('0.25', true) | round(2) }}
        spotify: >
          {{ is_state_attr(player, 'app_name', 'Spotify') }}
        radio: >
          {{ 
            is_state_attr(player, 'app_name', 'TuneIn Free') 
            or (state_attr(player, 'media_content_id')
              .split('//')[1]| default('no/tunein', true)).split('/')[0]
              in frequent_radio 
          }}
        media_content: >
          {{ state_attr(player, 'media_content_id') | default('geen', true) }}
        player_resume: >
          {% if is_state('media_player.home_group', 'playing') %}
            media_player.home_group
          {% 
            elif ((player in state_attr('group.first_floor_group', 'entity_id')) 
            and is_state('media_player.first_floor_group', 'playing')) 
          %}
            media_player.first_floor_group
          {% 
            elif ((player in state_attr('ground_floor_group', 'entity_id')) 
            and is_state('media_player.ground_floor_group', 'playing')) 
          %}
            media_player.ground_floor_group
          {% else %}
            {{ player }}
          {% endif %}
        screen: "{{ player in players_screen }}"
        spotcast_account: >
          {% 
            set spotify_playing = expand(spotify_media_players) 
                                  | selectattr('state', 'eq', 'playing')
                                  | map(attribute='entity_id') 
                                  | list 
                                  | count 
          %}
          {% if spotify_playing == 1 %}
            {{ 
              ( 
                expand(spotify_media_players) 
                | selectattr('state', 'eq', 'playing')
                | map(attribute='entity_id') 
                | join
              ).split('_')[2] 
            }}
          {% else %}
            {{ 
              (
                expand(spotify_media_players) 
                | selectattr('attributes.media_content_id', 'eq', media_content)
                | map(attribute='entity_id') 
                | join
              ).split('_')[2]  | default(primary_spotcast, true)
            }}
          {% endif %}
    - alias: "Apply TTS volume"
      service: media_player.volume_set
      target:
        entity_id: "{{ player }}"
      data:
        volume_level: "{{ volume | default(volume_old, true) }}"
    - alias: "Send TTS message"
      service: tts.microsoft_say
      data:
        entity_id: "{{ player }}"
        message: "{{ tts_message }}"
    - alias: "Short delay to make sure the TTS message has started"
      delay: 2
    - alias: "Wait until TTS message is complete"
      wait_template: "{{ states(player) in ['idle', 'off'] }}"
    - alias: "Set volume back to old state"
      service: media_player.volume_set
      target:
        entity_id: "{{ player }}"
      data:
        volume_level: "{{ volume_old }}"
    - alias: "Google Home with screen?"
      choose: 
        - conditions: "{{ screen }}"
          sequence:
            - alias: "Turn Google Home on to return to idle mode (photo display)"
              service: media_player.turn_on
              target:
                entity_id: "{{ player }}"
    - alias: "Was something playing?"
      choose:
        - alias: "Spotify?"
          conditions: "{{ spotify }}"
          sequence:
            - alias: "Primary spotcast account?"
              choose:
              - conditions: "{{ spotcast_account == primary_spotcast }}"
                sequence:
                  - alias: "Resume Spotify with primary spotcast account"
                    service: spotcast.start
                    data:
                      entity_id: "{{ player_resume }}"
              default:
                - alias: "Resume Spotify with specific account"
                  service: spotcast.start
                  data:
                    entity_id: "{{ player_resume }}"
                    account: "{{ spotcast_account }}"
        - alias: "Radio?"
          conditions: "{{ radio }}"
          sequence:
            - alias: "Resume radio"
              service: media_player.play_media
              target:
                entity_id: "{{ player_resume }}"
              data:
                media_content_id: "{{ media_content }}"
                media_content_type: "music"
2 Likes

I posted a new version here:

2 Likes