The resume based on home status, or other events is actually a very good idea. Iāll look into that.
For the integration part, those are written in python, and thatās something I donāt have any experience with. Maybe somewhere in the future, but not in short or middle long term.
iām using an automation with google tts and a camera feed when someone has pushed the doorbel. it first says someone is at the door and then pushes the camera feed onto the hubs. Because these are 2 actions with a delay in between, would this script still work to resume what was playing before? since the last action would be a camera stream and not google tts/spotify,etcā¦
Yes, you can sure make that work, however delays are not service calls, so you can not use them directly in the script. I think this will work.
Note that I have split it up into one automation and two scripts. One script could also work, but this will work better with the update Iām about to publish (hopefully later today).
It could be that the nest hubs are resumed before the camera feed starts, in that case you might need to increase the delay at the end of the first script.
### YOUR NEW "DE BEL GAAT" SCRIPT"
de_bel_gaat:
alias: Script voor als de bel gaat
sequence:
- service: media_player.volume_set
target:
entity_id:
- media_player.nest_hub
- media_player.badkamer
- media_player.google_opslagkamer
- media_player.grote_slaapkamer_hub
data:
volume_level: 0.5
- service: tts.google_translate_say
data:
entity_id: media_player.nest_hub
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.grote_slaapkamer_hub
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.badkamer
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.google_opslagkamer
message: DE BEL GAAT
cache: true
- service: script.camera_als_de_bel_gaat
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
### SEPARATE SCRIPT FOR THE CAMERA FEEDS, TO NOT DELAY THE OTHERS
camera_als_bel_gaat:
alias: Script voor de camera feed als de bel gaat
sequence:
- wait_template: >
{{
states('media_player.nest_hub') in [ 'idle', 'off']
and states('media_player.grote_slaapkamer_hub') in [ 'idle', 'off']
}}
- data:
media_player: media_player.nest_hub
target:
entity_id: camera.dome_camera
service: camera.play_stream
- data:
media_player: media_player.grote_slaapkamer_hub
target:
entity_id: camera.dome_camera
service: camera.play_stream
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- data: {}
service: media_player.turn_off
target:
entity_id:
- media_player.nest_hub
- media_player.grote_slaapkamer_hub
Just tested and it seem to be working very well, thank you!
I was wondering if thereās any way of stopping or āmutingā the google waking up sound along with your script. Since it seems to be generating a new group everytime, it seems to never stay āupā so itās doing a beep sound eveytime the script is used. It would be awesome to find a way to mute it.
That sound is the sound the Google Home makes when you start casting to it, it has never annoyed me much, so I didnāt look into it. But it is not related to my script, you will get the sound when you play anything using media_player.play_media or even when you cast something from your phone.
The generation of the groups is completely unrelated to this, this is just to store the entity_idās of the speakers for which the script is active, they are not used to target or start the Google Homes.
If you search for it on the community forum or Google, one of the solutions seems to be to play a silent mp3 every few minutes to keep them awake.
This version brings quite some changes, which will require also to update the Google Home Voice script in case you use that one as well.
The script is now split into one main script (script.google_home_resume) and 3 helper-scripts (script.google_home_resume_perform_resume, script.google_home_resume_restore_non_playing and script.google_home_resume_ytube_seek). This allows the resume of different speakers to be ran in parallel, instead of that they will have to wait for each other. So in case you send a TTS and a video feed to one of your Nest Hubs, and only a TTS to a Nest Mini, the Nest Mini can already resume before the Nest Hub is finished. All the scripts are in one yaml-file, the one linked below, please make sure that you copy everything. The script for the resume of the ytube music player integration is at the bottom, if you donāt use that, you donāt need that script and you can leave it out of your configuration.
Improvements
The ytube music player integration will now resume at the right position in the track
Added a variable group_id which is just a random string to make sure no groups not belonging to this script are used.
Groups are now generated specifically for each script run by use of the the context.id which is used as a suffix of the script.
Lotās of changes in the way data is stored and shared, also in preparation of a new script which can store the state when you eg leave your house, and resume when you come back
Thanks for the quick answer! I have looked into it. I was just wondering since if you send more than one TTS message back to back to any google home device, it will make the beep twice using your code. If you use the standar TTS feature, you will hear it the first time, then the second TTS message wont have a beep until it automatically goes off after 4-5 mins of inactivity.
I tested it very quickly last night, Iāll have to do some more testing.
My script doesnāt do anything different to cause the bleep, if it is already awake, it wonāt bleep.
It could be that what you are hearing is the volume adjust sound, it adjust the volume before the TTS starts, and then back to the original value after the TTS.
That also causes some (maybe annoying) sound.
Error doing job: Task exception was never retrieved
6:26:05 PM ā (ERROR) core.py
00 š Google Home Resume - Restore non playing: Error executing script. Invalid data for call_service at pos 5: invalid slug resume_active__32a633f7fb2fb7e001a09d0a7b772914 (try resume_active_32a633f7fb2fb7e001a09d0a7b772914) for dictionary value @ data['object_id']
6:26:05 PM ā (ERROR) Script
Template variable warning: 'group_id' is undefined when rendering 'resume_active_{{ group_id }}_{{ context.id }}'
6:26:05 PM ā (WARNING) helpers/template.py
Error in 'choose[0]' evaluation: In 'template' condition: TypeError: first argument must be string or compiled pattern
6:26:05 PM ā (WARNING) helpers/script.py
I am testing this, but then the (spotify) song is resumed, it doesnt resume from when it was interrupted, but from a much earlier point (sometimes 30 seconds, sometimes more). Volume is restored correctly.
Any ideas?
Thanks!
Iāve been tring to get this script integrated in my setup but I cannot get it to work properly.
From what Iām guessing Iāve got 2 different problems:
A google speaker pair doesnāt seem to display what it is playing anymore (the google app will say itās playing but doesnāt display the contents (eg name of the radiostation) anymore) so when trying the resume script it doesnāt resume playback. with single speakers or in a group that doesnāt include a speaker pair it is working as expected.
there are 2 camerastreams being started, one of them is on the google hub in the kitchen so looks like to get that working I need to incorporate the same solution you suggested for āthe cobra 666ā?
this is the automation Iām using at the moment:
alias: Melding Deurbel
description: ''
trigger:
- platform: state
entity_id: binary_sensor.deurbel
from: 'off'
to: 'on'
condition: []
action:
- service: camera.snapshot
data:
filename: /config/www/images/deurbel.jpg
target:
device_id: 10eb922exxxxxxxxxxxxxxx318c3eafc38
- delay:
hours: 0
minutes: 0
seconds: 1
- service: notify.mobile_app_yvette_gsm
data:
message: Er staat iemand aan de deur! šŖ
title: Hoi Yvette,
data:
image: /local/images/deurbel.jpg
- service: notify.mobile_app_mvt_gsm
data:
message: Er staat iemand aan de deur! šŖ
title: Hey Maurice,
data:
image: /local/images/deurbel.jpg
- service: notify.lg_webos_tv_ym
data:
message: ER STAAT IEMAND AAN DE DEUR. šŖ
- service: script.google_home_resume
data:
action:
- service: media_player.volume_set
data:
volume_level: 0.25
target:
entity_id:
- media_player.kantoor
- media_player.badkamer
- media_player.woonkamer_speakers_2
- service: media_player.play_media
data:
media_content_id: http://192.168.2.3:8123/local/audio/duckbell.mp3
media_content_type: music
target:
entity_id:
- media_player.kantoor
- media_player.badkamer
- media_player.woonkamer_speakers_2
- service: browser_mod.popup
data:
command: popup
title: De deurbel gaat
large: 'true'
card:
entity: camera.voordeurcamera_profile_000
type: picture-entity
camera_view: live
deviceID:
- 06xxxx-xxxx0ec
- service: camera.play_stream
target:
device_id: 10eb922e29xxxxxxxxx18c3eafc38
data:
media_player: media_player.keuken
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- service: media_player.media_stop
data: {}
target:
device_id: 18f56952xxxxxxxxxxx682d6a05d38d
- service: browser_mod.close_popup
data: {}
mode: single
Speaker pairs indeed seem to have some issues with displaying the data. There is nothing I can do about that, best would be to log an issue for Home Assistent Core related to the cast integration.
For you second the approach I suggested earlier to create two scripts seems best for your automation as well.
I donāt think itās an issue with home assistant. the google home app doesnāt display the data either. As far as I can find it has something to do with the patent case from google/sonos.
I will try out the suggested scripts for the automation, thanks!
Sorryā¦ Iām new in HA and Node red. How do i āinstallā this script so the music repeats when the TTS has been played from Node red? The announcement work from Node red to speakers, but it stops ex. playing TuneIn Radio
When I just copy past the script in a new script create window (in yaml mode) it always says: Message malformed: extra keys not allowed @ data[āgoogle_home_resumeā]