Hello, I was trying to script a simple event. I want my sonos speaker to simply say goodnight, ill play some music. And to play a specific source at a given volume. The problem is, the message does not complete, meaning it is interrumpted and stops after goodnight. Then it does not play any music. This is the code:
night_music:
alias: Sleep with Music
sequence:
- service: tts.google_say
data:
entity_id: media_player.alvaros
message: 'Goodnight, I will play some music'
- service: light.turn_off
data:
entity_id: group.all_lights
- service: media_player.volume_set
data:
entity_id: media_player.alvaros
volume_level: 10
- service: media_player.select_source
data:
entity_id: media_player.alvaros
source: 'Hot Hip Hop'
- service: media_player.play_media
data:
entity_id: media_player.alvaros
Thats the code for the script. The problem somehow is selecting and playing the music and that it tries to do it so fast it doesnt get time to finish the voice message. Thank you!
Does it work if you remove the TTS section?
Assuming the problem is everything happening too fast, maybe just add in a couple of delays between as needed?
sequence:
- delay:
minutes: 1
So something like…
night_music:
alias: Sleep with Music
sequence:
- service: tts.google_say
data:
entity_id: media_player.alvaros
message: 'Goodnight, I will play some music'
- delay:
minutes: 1
- service: light.turn_off
data:
entity_id: group.all_lights
- service: media_player.volume_set
data:
entity_id: media_player.alvaros
volume_level: 10
- service: media_player.select_source
data:
entity_id: media_player.alvaros
source: 'Hot Hip Hop'
- delay:
seconds: 30
- service: media_player.play_media
data:
entity_id: media_player.alvaros
Thank you, it seems to work with a two second delay. I just hate the fact that the script now has a slider because of the delay. thank you!
I hardly ever look at the web interface, most of what I try and do is geared towards automation. This is the sort of thing you could easily trigger by voice, or a button on a tablet or phone.
I’m not sure if you can use “wait” instead of delay but a way around your problem might be to run scripts from within the script. You could just have another script like this as your trigger.
sleep_music:
alias: Sleep Music
sequence:
- service: script.night_music
I see, thank you very much, I ll definitely give it a try. anyways i am getting used to the sliders.
Try removing the comma in the phrase. Or put the phrase in quotes instead.