I am having trouble with the automation and script listed below. I wanted the automation and script to fire every hour between time x and time time y and it does that as expected. However, when speaking the time it always announces it as 59 minutes past the hour as opposed to on the hour. If it fires at 5:00 pm it will announce the time as 4:59, at 6:00 as 5:59 etc. My questions are - can I round the time up to the nearest hour without minutes or seconds, can I format the time to a 12 hour clock instead of 24 hour, and can I include a.m. or p.m.? Thank you all for any/all assistance. Here is the yaml I have -
You’re experiencing something I accidentally discovered and that there’s a small discrepancy between what sensor.time reports and the time used by Time Triggers like time and time_pattern (as well as the now() function).
Within your script’s template I suggest you use the now() function instead of sensor.time.
Replace this:
{{states.sensor.time.state}}
with this:
{{now().timestamp() | timestamp_custom('%H:%m')}}
Here’s the resulting final line of the script:
It's currently {{states.weather.woodland_hills_north.state}} in San Antonio on {{states.sensor.date.state}} at {{now().timestamp() | timestamp_custom('%H:%m')}}
You can also streamline it like this:
- service: tts.google_translate_say
data_template:
entity_id: media_player.office
message: >
{% set t = now().hour %}
{% set m = 'Morning' if t < 12 else 'Afternoon' if t < 18 else 'Evening' %}
Good {{m}} Stephen.
It's currently {{states.weather.woodland_hills_north.state}} in San Antonio on {{states.sensor.date.state}} at {{states.sensor.time.state}}
It displays two times and I compared both to the server’s system clock.
The first displayed time, using now(), was perfectly in sync with the system clock (to the second).
The second one, using sensor.time, lagged by one minute because it was actually a second or two late (i.e. if sensor.time could show seconds it would show 16:16:58 when now() reports 16:17:00).
You can try it for yourself and confirm that when the notification appears, it occurs the moment the system clock advances to the next minute (and now() shows the correct current time, not early nor late).
Thanks again … I will test it out on my end … been having terrible troubles with Netatmo and TTS so I think I’m going to load an old backup and try to get success from there. Thank you for taking the time to look at this for me; very kind of you.
it worked … 16:00 on the nose. is there a place where I can look up format time rules? Instead of the announcement saying 14:00 I would prefer 4:00 pm. Anyway, the main issue is addressed Taras.
There’s one final thing you can do to close out this topic. Please mark my post (the one above) with the Solution tag. Only you, the author of this topic, can do that.
It will automatically place a check-mark next to the topic’s title which signals to others that this topic has an accepted solution. It will also place a link below your first post that leads to the solution. All of this helps other users find answers to similar questions. Thank you.