I’m trying to build a generic TTS notification script that will play a message to one of my Google Nest Minis, Sonos speakers, or a pre-defined group of them. The script should take two parameters: the text of the message to convert to speech and the media player entity or entities for playing the message.
My plan is to use the generic notification TTS script with numerous other automations to create more complex notification messages based on templates combining sensor, weather, and other data. For example, I want to create a good morning message that’s customized to me with a weather forecast, traffic conditions, calendar information, etc. that will play on a Google Nest Mini when I first enter the kitchen in the morning.
I am a Home Assistant Coud subscriber and have confirmed that I can do basic TTS to any of my smart speakers using the tts.speak
action.
I have searched and searched and have so far been unable to create what seems like it should be a pretty simple script. Here’s what I have to this point:
alias: Play Custom Audio Notification
sequence:
- action: tts.speak
metadata: {}
data:
message_text: "{{ message_text }}"
message_target: "{{ message_target }}"
target:
entity_id: tts.home_assistant_cloud
description: >-
Play a custom audio notification after accepting parameters for message and
target.
icon: mdi:bell-ring-outline
fields:
message_text:
selector:
text: null
name: message_text
description: Text of message to be spoken
required: true
message_target:
selector:
entity: {}
name: message_target
description: Entity of media player to play message
required: true
I created a simple automation that is triggered from an input boolean helper:
alias: TTS test
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.dummy
from: null
to: "on"
condition: []
action:
- action: script.play_custom_audio_notification
data:
message_text: This is a message from Home Assistant.
message_target: media_player.sonos_roam
mode: single
Nothing happens when I trigger the automation, and I get the following in the log:
2024-09-25 18:08:45.342 ERROR (MainThread) [homeassistant.components.script.play_custom_audio_notification] Play Custom Audio Notification: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['message_text']
2024-09-25 18:08:45.343 ERROR (MainThread) [homeassistant.components.automation.tts_test] TTS test: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['message_text']
2024-09-25 18:08:45.344 ERROR (MainThread) [homeassistant.components.automation.tts_test] Error while executing automation automation.tts_test: extra keys not allowed @ data['message_text']
I’m sure this is not nearly as complicated as I’m trying to make it. Can anyone offer some guidance on where to go from here?