How to make HA annouce the current time

Hi there, I’m fairly new to HA and so far I have only implemented automations via the visual editor.
I basically would like to create an automation that when motion is detected, HA is announcing the current time or on a smart speaker. I’ve been reading for hours through all kind of HA community sites but I’m stuck.
Where do I start ? Do I need to create a script, a template ? Do I need to create a sensor ? Add something to the configuration.yaml ?
I saw that I need to add somewhere: It’s {{ now().strftime(’%-I:%M’) }} but where?

So far I have added the following to the configuration.yaml

Text to speech

tts:

  • platform: google_translate

Example configuration.yaml entry

sensor:

  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘date_time_utc’
    • ‘date_time_iso’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’

But what is next ? I’m lost here.

Besides, the tts service is running fine, for instance I’m running an automation to announce the time when it’s 8 o’clock and my homepod plays it

action:

  • service: media_player.play_media
    target:
    entity_id: media_player.homepod_white
    data:
    media_content_id: media-source://tts/google_translate?message=it%27s+8+o%27clock
    media_content_type: provider
    metadata:
    title: it’s 8 o’clock
    thumbnail: https://brands.home-assistant.io/_/google_translate/logo.png
    media_class: app
    children_media_class: null
    navigateIds:
    - {}
    - media_content_type: app
    media_content_id: media-source://tts
    - media_content_type: provider
    media_content_id: media-source://tts/google_translate?message=it%27s+8+o%27clock
    enabled: true

I would be really grateful if someone could guide me (for dummies) which steps I have to take to make HA announce the current time. Many thanks

 It is {{  now().strftime("%H:%M:%S") }}
1 Like

Thanks Blackway, much appreciate your swift response but where to I need to enter this, in a script, a template or straight into an automation ? A full code would really help

In the automation when working in YAML-Code. I use a different service-call, I use Text-to-Speech (TTS): Say a TTS message with google_translate

  - service: tts.google_say
    data:
      entity_id: media_player.homepod_white
      language: en
      message: >-
        Good morning! It is {{ now().strftime("%d/%m/%Y") }}.
1 Like

That worked, thanks so much

I just spent an hour or two making this work. Unfortunately, the visual editor for the Text to Speech action does not properly escape/quote/unquote Python snippets enclosed with double braces. To make it work, you have to switch to the YAML editor and change the entity encodings for the braces back to the actual brace characters.

It would be really nice if the visual editor could be fixed to handle this use case.