I’ve copied (and slightly modified) a neat script to allow TTS to interrupt a music player and then resume, (source here: https://community.home-assistant.io/t/how-continue-play-the-previous-music-after-a-tts-voice-announcement/253053/10?u=crowbarhero) however I’m getting an error on execution:
tts and resume: Error executing script. Invalid data for call_service at pos 2: required key not provided @ data['media_player_entity_id']
Looking at the traces, I think it’s an issue with how the variables (player id and message) are passed, in that it’s not picking up the player ID properly.
What’s wierd is that it is suceeding in setting the volume level on that player, but not in passing the TTS bit??
Executed: December 31, 2024 at 08:52:54
Error: required key not provided @ data['media_player_entity_id']
Result:
params:
domain: tts
service: speak
service_data:
entity_id: media_player.squeezeoffice
language: en
message: Test message
target: {}
running_script: false
Any thoughts as to how I can get this working… ?
Full script below:
alias: tts and resume
variables:
mediaplayer_State: "{{ states(tts_entity) }}"
mediaplayer_media_content_id: "{{ state_attr(tts_entity,'media_content_id') }}"
mediaplayer_Source: "{{ state_attr(tts_entity,'media_channel') }}"
mediaplayer_volume_level: "{{ state_attr(tts_entity,'volume_level') }}"
mediaplayer_content_type: "{{ state_attr(tts_entity,'media_content_type') }}"
sequence:
- data:
entity_id: "{{ tts_entity }}"
volume_level: 0.75
action: media_player.volume_set
- data:
entity_id: "{{ tts_entity }}"
language: en
message: "{{ msg }}"
action: tts.speak
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- data:
entity_id: "{{ tts_entity }}"
volume_level: "{{ mediaplayer_volume_level }}"
action: media_player.volume_set
- data:
entity_id: "{{ tts_entity }}"
media_content_id: "{{ mediaplayer_media_content_id }}"
media_content_type: "{{ mediaplayer_content_type }}"
action: media_player.play_media
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- choose:
- conditions:
- condition: template
value_template: "{{ mediaplayer_Source != None }}"
sequence:
- data:
entity_id: "{{ tts_entity }}"
source: "{{ mediaplayer_Source }}"
action: media_player.select_source
- choose:
- conditions:
- condition: template
value_template: "{{ mediaplayer_State != 'playing' }}"
sequence:
- data:
entity_id: "{{ tts_entity }}"
action: media_player.media_pause
mode: single
fields:
tts_entity:
description: media player entity id
required: true
name: tts_entity
msg:
name: msg
description: message
required: true