Announcing the time on an Echo device (tts)

I want an Amazon Echo device to say the time once an hour on the hour during the day. I have been able to get it to “say” a message, but not the time. This code works perfectly.

alias: Notification - Time announce
description: ""
trigger:
  - platform: time_pattern
    minutes: "0"
    seconds: "0"
condition:
  - condition: time
    after: "07:58:00"
    before: "19:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: tts.cloud_say
    metadata: {}
    data:
      cache: true
      entity_id: media_player.sitting_room_echo
      message: "hi di hi"

I do have default_config: in my config.yaml file. I have created a helper (see below), but if I replace the last line above with …

    message: "The time is {{input_datetime.time_announce}} o'clock"

… then I get a trace error

Error rendering data template: UndefinedError. 'input_datetime' is undefined

Where am I going wrong? Many thanks!

message: "The time is {{ states('input_datetime.time_announce') }} o'clock"

Or you could just lose the helper:

message: "The time is {{ now().strftime('%-I') }} o'clock"
2 Likes

Many thanks!

another option:

ias: "# Time is 8 am "
description: ""
trigger:
  - platform: time
    at: "08:00:00"
condition:
action:
  - service: script.1703612400211
    data:
      devices:
        - 36c49xxxxxxxxxxxxxxx50
        - 44a4yyyyyyyyyyyyyyyyyy75
        - d37bzzzzzzzzzzzzzzzzzz5d
      message: Time is 8 am
      type: announce
mode: single

.
or action
.

service: media_player.play_media
target:
  entity_id: media_player.zeide_bedroom
data:
  media_content_id: time
  media_content_type: custom