TTS to say sensor value

Hi,
I’m trying to make an automation that talks to me at one of my media player at 05.55 every morning.
I have tts setup and it’s working but when I ad a sensor value to the message it won’t work.
I have tried the example from ha example and it’s not working either.
Can someone please post an example of this how to make it work.

Tts every day at Time 05.55
Entity_id: mediaplayer.bosekitchen
Message: Godmorning temperature outside is now “Sensor.temp” and there is “sensor.pellets” percent left in the storage. Have a nice day.

1 Like

You need to use templating.

action:
- service: tts.your-tts-service
  entity_id: media_player.bosekitchen
  data_template:
    message: "Godmorning temperature outside is now {{ states('sensor.temp') }} and there is {{ states('sensor.pellets') }} percent left in the storage. Have a nice day."

Replace tts.your-tts-service with whatever TTS service you’re using.

5 Likes

Thank you this works :slight_smile:

One other question. Is it possible to round “sensor.temp” to whole number, so there is no decimal at all?

{{ states('sensor.temp') | round(0) }}
3 Likes

Sweet, thx m8

Hiu. Hoping someone can point me in the right direction. Trying for days to get google TTS to announce sensor battery voltage. I know I need to use a template but how? Where? In my HA automation I tried this:
action:

  • service: tts.google_translate_say
    entity_id: media_player.bosekitchen
    data_template:
    message: “Battery voltage is {{ states(‘sensor.jk_bms3_total_voltage’) }} .”

But google tts reads the text and not the sensor value (‘sensor.jk_bms3_total_voltage’). Any help/suggestion appreciated

There are vague hints one needs to create the automation in configuration.yaml file. It’s easy peasy to get dev/tool template to convert sensor value to the correct sensor text value but then what do I do? Vague indeed.

Solved. I was making this far too complicated. I needed to use “+” with the sensor entity.
action:

  • service: media_player.play_media
    target:
    entity_id: media_player.mpd
    data:
    media_content_id: >-
    media-source://tts/google_translate?message=The+battery+voltage+is+{{
    states(‘sensor.jk_bms3_total_voltage’) }}+volts
    media_content_type: provider
    metadata:
1 Like

Or this

service: tts.google_translate_say
data:
  entity_id: media_player.livingroomhp
  message: Hot water is {{states('sensor.rinnai_outlet_temperature') | round(0) }}.

Addind the period at the end of the line, when you are not using rounding, changes the reporting to sound different for numbers.
No period would report 80.0 as eighty point oh
Period would report 80.0 as eighty point zero

And if your media device is a homepod is your media device expect some issues over the long term.
If you are playing audio and you run your automation it will interupt your music , play you gTTs and not resume your music.

If you are not playing music it will play your gTTS and then leave your homepod in a “Playing” state even though it is not playing… The next time you try to play a gTTS it will not work to that Homepod mini unless you toggle for at least 200ms…A real pain to code around, but you can if you want to use seemless announcments.

1 Like