Open jowinthe opened 3 days ago
Hey there @thrawnarn, @louischrist, mind taking a look at this feedback as it has been labeled with an integration (bluesound
) you are listed as a code owner for? Thanks!
I was not aware of this functionality. This could maybe be implemented for the bluesound integration. It might not work for all audio sources, though. They are inconsistent in how they work and not well documented.
It might already work with the help of source
and volume_level
. The following is a rough idea of how it might work. I tested the volume part. I haven't tested the source. You might have to call play afterwards. And it might not work for all sources.
alias: New automation
mode: single
description: ""
triggers: []
conditions: []
actions:
# snapshot
- variables:
source: "{{ state_attr('media_player.node', 'source') }}"
volume: "{{ state_attr('media_player.node', 'volume_level') }}"
# do tts
- action: tts.speak
data: {}
# restore
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ volume }}"
target:
entity_id: media_player.node
- action: media_player.select_source
metadata: {}
data:
source: "{{ source }}"
target:
entity_id: media_player.node
Thanks for the swift reply! Yes, that works! I had to put in a delay according to the length of the TTS announcement, but other than that it's a definite thumbs up. Both TuneIN and Spotify reverted back to the original source. Volume adjusted correctly (before and) after the TTS.
Here's the YAML code I used:
alias: Bluesound tts
description: ""
triggers: []
conditions: []
actions:
- variables:
source: "{{ state_attr('media_player.bluesound_livingroom', 'source') }}"
volume: "{{ state_attr('media_player.bluesound_livingroom', 'volume_level') }}"
- action: media_player.volume_set
metadata: {}
data:
volume_level: 0.1
target:
device_id: xxx
- action: tts.google_translate_say
metadata: {}
data:
entity_id: media_player.bluesound_livingroom
message: The garage door...is open
cache: true
- delay:
hours: 0
minutes: 0
seconds: 4
milliseconds: 0
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ volume }}"
target:
entity_id: media_player.bluesound_livingroom
- action: media_player.select_source
metadata: {}
data:
source: "{{ source }}"
target:
entity_id: media_player.bluesound_livingroom
mode: single
I am a little bit surprised that it works for TuneIn :thinking: Do you have a preset for the TuneIn Station you were listening to?
I did some testing. This was a bit tricky. Here's what I found: The code works while;
When a TuneIN station is not stored in the Preset List, the code changes the volume and plays the TTS message, but fails to restore the previous stream. Instead it reverts to the last Library track that was played (in my case a .flac file) in pause mode. In other words, the music stops.
While streaming from the Library (for example a .flac file in a NAS), it works, with the exception that is skips to the next track, and with subsequent runs of the code it fails (until a new track is manually selected or Pause->Play is pressed). By "fails" I mean that the volume changes correctly, but the track just keeps playing when the TTS was supposed to kick in.
I hope this helps. Unfortunately I don't have the programming skills to solve this.
Feedback
In the Sonos integration there is a functionality to take a snapshot of the current state of the media player, and then to restore the same state, e.g. after an interruption from a TTS announcement. This works quite well, and make it relatively easy to use the Sonos system for TTS applications. Are there any plans to incorporate something similar in the Bluesound integration? And, if not, are you aware of any blueprints or other code that one could use as a template for this purpose?
URL
https://www.home-assistant.io/integrations/bluesound/
Version
2024.10.2
Additional information
From a TTS blueprint for Sonos: (https://community.home-assistant.io/t/script-for-sonos-speakers-to-do-text-to-speech-and-handle-typical-oddities/424842)
sequence:
save current state so we can restore to whatever was happening previously