And a small edit: if You want to resume something that was playing on some media player before (sorry, no Spotify - do not use anyway) can give this a try:
alias: "Send Announcement to Speakers with Resume"
icon: mdi:volume-high
sequence:
# 1. Take a snapshot of the current state and volume of the speakers
- action: scene.create
data:
scene_id: speakers_state_before_announcement
snapshot_entities:
- media_player.kitchen_mini
- media_player.restroom_mini
# 2. Send the text to speakers as an announcement
- action: media_player.play_media
target:
entity_id:
- media_player.kitchen_mini
- media_player.restroom_mini
data:
media_content_id: >-
media-source://tts/tts.home_assistant_cloud?message={{ states('input_text.announcement_text') }}
media_content_type: music
announce: true
# 3. Wait for the speaker to finish talking (change seconds if needed)
- delay: "00:00:05"
# 4. Restore the exact previous state of the speakers and resume music
- action: scene.turn_on
target:
entity_id: scene.speakers_state_before_announcement
# 5. Automatically clear the text box after the announcement
- action: input_text.set_value
target:
entity_id: input_text.announcement_text
data:
value: ""