Easiest way to convert an input date_time into words, or plain language

I’m using the Alexa TTS script here

I came across a quirky behavior where it does not read Text if there is a colon in the message. I wanted to add a time stamp to a message from an input date time, so was hoping there was a reasonablly easy way to convert times into either words so that
08:30:00 becomes - eight thirty AM or at least broken down into 8 30 am. so I can use that instead

This is my message text

Based on current traffic, you have 15 minutes to leave if you want to get to work by {{ states('input_datetime.work_time') }} .  Traffic is {{ states('sensor.pauls_traffic_density_to_work') }} today.

what is spoken is right now is.

OO. Traffic is normal today

Sounds like Oh Oh. Traffic is normal today

Even breaking it out by colon will probably end up speaking something like
08 being said as ‘Oh eight 30’.

Anyone have any recommendations or thoughts.

Interesting. I use the following parser to convert HA entity values into spoken speech.

I will ensure i remove : from the final parse . Not noticed this before thank you :slight_smile:

I did see this, looked pretty cool. I have not gotten into appDaemon quite yet, but keep seeing more and more reason to make the leap. :slight_smile:

Yeah, I do need to figure this out. I forgot that I have more automations with time stamps. They are all not working of course. If I want to keep using the alexa TTS script this will quickly become annoying. Well at least to anyone who wants to speak a time that is from a sensor or input_time.

Is there a simple way in yaml to filter input_time, Input_texts, etc to remove a : or maybe to break it up in line without having to create a bunch of other inputs?

Like this

{{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }}

This renders the time without zero-padding .

{{ as_timestamp (now()) | timestamp_custom('%-I %-M %p') }}

In other words, if the current time is 21:36:00 the template will display it as:
9 36 PM

That should sound better when spoke by Alexa.

I’m unfamiliar with how Alexa converts text to speech. In the speech engine I use, commas are rendered as brief pauses. If that’s also true here then you may wish to tweak the template so it produces 9, 36, PM. The pauses might make the spoken time more understandable.

FWIW, I had encountered an issue where the word wind was pronounced as a verb like in to wind a clock. Unfortunately, it needed to be pronounced as a noun because the context was wind speed. To fix it, I replaced the word wind with a pronunciation hint: <partofsp part='noun'>Wind</partofsp>.

1 Like

you can strip out the : by using the following:

{{ as_timestamp(now())|timestamp_custom ('%-H %M') }}

as of the time of this writing the result is 19 32

if you want it as a 12 hour time then:

{{ as_timestamp(now())|timestamp_custom ('%-I %M') }}

will give you 7 32

If you want the leading 0’s then:

{{ as_timestamp(now())|timestamp_custom ('%H %M') }} = 19 32
{{ as_timestamp(now())|timestamp_custom ('%I %M') }} = 07 32
1 Like

sorry I cross posted to yours…

No problemo.

BTW, I just realized that your example doesn’t remove zero-padding for minutes whereas mine does. In retrospect, yours is more correct yet, sadly, neither will be spoken the way we are accustomed to hearing it.

20:05:00 will be rendered as either 8 5 PM (mine) or 8 05 PM (yours). Mine will sound truncated, “It’s eight five PM”, and yours will sound quasi-military “It’s eight zero five PM”.

Ideally the template shouldn’t zero-pad minutes less than 10 but prepend the letter O. So we’d have this: 8 O 5 PM. This would cause the speech engine to pronounce the letter O and say “It’s eight oh five PM”.

1 Like

Awesome, thanks so much, I did not realize I could remove the : from the timestamp_custom.
I can live with the occasional 8 zero 5 in my TTS’s

This was a great help!

I guess my last question is can I do something similar with an input_datetime?

edit:
OK, got it figured out. For Input_datetime, I just pulled the hour and minute attributes

ended up with this

Based on current traffic, you have 15 minutes to leave if you want to get to work by {{ states.input_datetime.work_time.attributes.hour }} {{ states.input_datetime.work_time.attributes.minute }}

Worked great, still have to figure out how to get it to speak leading 0’s better with the input_datetime

Right now, 8:30 speaks perfect,
8:05 says
8 5
8:00 says
8 0