I’ve just reworked my code for announcing messages, and I thought I’d share it. There are blueprints available for this functionality, but I find my approach much cleaner and more streamlined. Let me know if you have any thoughts!
Home Assistant: Announce Messages with Google Home
This guide helps you set up a feature in Home Assistant where:
- A user types a message into a text input field.
- The message is announced on a Google Home speaker when the “Send” button is pressed.
- After the message is announced, the input field resets to blank.
Step 1: Configure the Input Field
Create a text input for users to enter messages.
-
Open your
configuration.yaml
file or use the Helpers UI in Home Assistant. -
Add the following configuration:
input_text: message_to_bedroom: name: What You Got to Say? initial: "" max: 255
-
Restart Home Assistant to apply the changes.
Step 2: Create the Script
The script will:
- Announce the entered message using TTS.
- Reset the input field after sending.
-
Go to Settings > Automations & Scenes > Scripts.
-
Create a new script and paste the following YAML:
alias: Announce TTS Message description: Announce a typed message to the bedroom Google Home speaker mode: single sequence: - service: tts.cloud_say data: entity_id: media_player.YOURS message: "{{ states('input_text.message_to_bedroom') }}" - service: input_text.set_value target: entity_id: input_text.message_to_bedroom data: value: ""
-
Save the script.
Step 3: Add the Lovelace Card
Create a card with:
- A text input field for entering the message.
- A “Send” button to trigger the script.
-
Edit your Lovelace dashboard.
-
Add a Manual Card and use the following configuration:
type: horizontal-stack cards: - type: entities entities: - entity: input_text.message_to_bedroom name: What You Got to Say? icon: mdi:chat - type: custom:button-card icon: hass:send show_icon: true show_name: false styles: card: - height: 90px - width: 90px tap_action: action: call-service service: script.turn_on service_data: entity_id: script.announce_tts_message
-
Save the card.
Step 4: Test the Setup
- Open your dashboard.
- Enter a message in the text field (e.g., “Wake Up Time!”).
- Press the Send button.
- The message should:
- Be announced on the Google Home speaker.
- Reset the text field to blank.