TheFes / Google-Home-Resume

Google Home Resume package for Home Assistant
38 stars 2 forks source link

Google Home Resume Package

Table of contents


Background

This package started somewhere in 2020 as a simple script to resume a Google Cast device after it was interrupted by a TTS message. During the years more functionality was added, the Cast devices can also be resumed after playing an audio file, or casting a Home Assistant Dasboard. In the past years I also created others scripts using the Google Home Resume script. There is a script to determine on which device a question was asked and send a TTS or play a file on that specific device. Another script stores the state of the cast devices in a template sensor, so it can be resumed in later (for example store it when you leave home, and restore it when you arrive home again).

All these scripts are now combined in one package


🚨 USAGE OF THE AUTOMATION 🚨

The automation to start the resume is intended to be used as a backup. If you already know you are going to send (like a TTS or mp3) and know you want to resume what was playing afterwards, I strongly advice to start the script yourself, and not rely on the automation, as it is a bit flaky. See here for instructions how to do that.


Latest version

2024.9.0

🌟 IMPROVEMENTS

2023.8.0

πŸ“» GENERAL

🚨 BREAKING

:recycle: RESUME SCRIPT

✨ New features

πŸ› Bug fixes

Previous changes can be found here:


Requirements


Setup instructions

Updating from a previous version

Prior to 2022.11

If you are still using a version wich is not using the YYYY.MM version numbering, you are not using packages yet. Remove the existing Google Home scripts you are using (Resume/Voice/Event) and the Google Home Resume automation if you were using that. If you were using the Google Home Event script, also remove the template sensor used by that script.

After removing all the old stuff reload Scripts, Automations and Template entities from Developer Tools > YAML (Open your Home Assistant instance and show your server controls.) or restart Home Assistant. Then move on to Install the package.

From version 2022.11

Remove the Google Home Voice script if you were already using it, and the Google Home Event package if you were using that. Reload scripts and template entities in Developer Tools > YAML Developer Tools > YAML Open your Home Assistant instance and show your server controls. or restart Home Assistant.

🚨 IMPORTANT: Add the settings for the Voice Script to the settings you already have. The line voice_settings: &voice_settings needs to be included, otherwise you'll get errors while loading the configuration 🚨 Then copy everything below the settings from the package file on this GitHub repo and overwrite the current code in the package on your system using a file editor (like Visual Studio Code Add-on or File Editor Add-on), not via the GUI.

Make sure to add these voice_settings in a way that the current settings are still under the settings key.

## correct
settings: &settings
  primary_spotcast: john_doe
voice_settings: &voice_settings

## also correct
voice_settings: &voice_settings
settings: &settings
  primary_spotcast: john_doe

## not correct
settings: &settings
voice_settings: &voice_settings
  primary_spotcast: john_doe

Install the package

Link to the package

You can perform the steps above using a file editor (like Visual Studio Code Add-on or File Editor Add-on), not via the GUI.

Script Settings

There are no required settings, but if you use Google Home speaker groups you should define those as described below. Resuming Spotify with multiple accounts won't work properly without primary_spotcast. dummy_player is required to send a TTS with picture and text.

Variable Default Example Description
primary_spotcast pepijn The Spotify account which is used as primary account for spotcast, should match the last part of the Spotify media player.
radio_data My settings A dictionary with the pictures and titles. The picture urls should be full urls, not HA internal urls). As key value the artist should be used (check media_artist in developer tools > states)
speaker_groups My settings A combination of a dictionary and a list, with the speaker groups created in the Google Home app and it's members.
default_volume_level 0.25 0.5 The default volume level to use to restore the entity to if the old volume can not be retreived (this should actually never be used, but it there as a failsafe). This is not used for the TTS message
dummy_player media_player.vlc_telnet The dummy media_player used for the TTS with picture and text feature
default_resume_delay 20 seconds 20 The delay after which the resume will started when it was interrupted by sending an image. Follows the syntax of delay, so also "00:00:20" or seconds: 20 can be used.
max_runtime "00:10:00" The maximum duration the Resume script should run, if this time is reached the script will be stopped. This avoids entities being logged in the groups, which will stop them from being resumed on a new disruption. Follows the syntax of delay, so also 600 or minutes: 10 can be used.
stop_before_action false true If media_players should be stopped before the actions provided in the script data are performed.
automation_enabled false true If the automation for automatic resume should be used or not
dashboard_cast false false If the automation should be used in case a HA Dasboard is cast to the device
announce_volume_automation 0.75 The volume used for announcements in the automation, remove or leave empty to leave the volume as it is.

For the Google Home Voice script there are 2 specific settings, these are described in the [documentation]() of the Voice script.

Spotify resume

One Spotify Account

Multiple accounts
Example:

3 Spotify integrations:

image|440x279

The media_players entities connected to these Spotify integration are named:

media_player.spotify_floris
media_player.spotify_marleen
media_player.spotify_martijn

Spotcast setup (the Spotify account for Floris is the primary account, and has no named account in the spotcast setup), so the primary_account in this example is floris:

spotcast:
  sp_dc: !secret sp_dc
  sp_key: !secret sp_key
  country: NL
  accounts:
    marleen:
      sp_dc: !secret sp_dc_marleen
      sp_key: !secret sp_key_marleen
    floris:
      sp_dc: !secret sp_dc_martijn
      sp_key: !secret sp_key_martijn

YouTube Music resume

Dummy player for TTS with picture and text

In case you want to send a TTS with a picture and some text, you need to set up a dummy media_player which accepts TTS messages.

The feature to send a TTS together with picture and text works as as follows. The TTS is sent to a dummy player, and the script will wait for this event, and will take the url the the mp3 used as TTS message. It will then send this mp3 together with the picture and text to the actual target. As of Home Assistant 2022.4 there is a check if a target of a service call actually supports the service call. So the dummy player has to support TTS. As the media_player created by the VLC Telnet integration supports TTS, I use this.

In case you use HA OS, or run a supervised install, you can add the VLC Add-on from the add-on store. After starting the add-on it will automatically be detected by Home Assistant, and you can add the VLC Telnet integration. This will create media_player.vlc_telnet which you can use as dummy player.

In case you don't have the supervisor or already use this add-on for other purposes, you can possibly use the media_player created by the browser_mod custom component. Or you can buy an additionaly Nest Mini, set the volume to 0 and hide it somewhere πŸ˜‰


Description of scripts

Google Home Resume

The Google Home Resume script is used to resume a Google Home device after it has been interrupted. For example when a TTS has been sent, or when a sound has been played. You can manually trigger the script, and include the action after which it should be resumed in the service call for the script, or you can use the automation. More information on how to use the Google Home Resume script can be found here

Google Home Voice

The Google Home Voice script uses Google Home Routines and Ambient sounds to check on which device you issued a voice command, so it can send a TTS message or other action to that specific device. More information on how to use the Google Home Voice script can be found here

Google Home Event

The Google Home Event script can store the data of your devices in a template sensor, so you can restore the states on a later moment. So you can store the state when you leave the house, and restore the music when you come back in. More information on how to use the Google Home Event script can be found here


Known limitations


Questions/issues/bugs/feature requests?

In case you have a question, you found a bug, or have a feature request, you can either ask here, or open an issue on my GitHub repository. In case you create a GitHub issue, please label it with google home scripts

In case something isn't working or you found a bug, a trace of the script will be needed in most cases to determine the cause. The trace can be downloaded as a json file. To do this follow the steps below:

  1. Go to Configuration > Automations & Scenes > Scripts or use Open your Home Assistant instance and show your scripts.
  2. Find the Google Home scripts in the list.
  3. Click on 3 dot menu icon left of the script and then select Traces
  4. Make sure to select the right trace which contains the error
  5. Press the 3 dot menu icon in the top right corner, and select Download trace
  6. Press the download icon in the top right corner.
  7. Repeat for the Google Home Resume - Helper Script if the error is in that step.

In case you create the issue on GitHub you can upload the json files, in case you create the issue as a post here, you can copy the json files to a code sharing website like dpaste.org. Please create a different link for each json file.


Why not a blueprint?

I've been asked a couple of times if I ever considered to make a blueprint out of this script. I do understand this would make updates more easy, however there are also some things which make it quite complicated:

So, basically, I gave it a try, and decided it would not work :)


β˜• Coffee

If you like this script, please feel free to buy me a coffee (I might spend it on another beverage though). In case you decide to do so, thanks a lot!

Buy Me A Coffee