How to compose speach messages?

I have been looking around, but cannot seem to find the right key words for my search. I want to broadcast a message “Good night, the alarm is set to XX hours and XX minutes.” when my state turns to “sleeping”. Now I need to process the XX for hours and minutes from what the android companion delivers. In another thread I already got the hint how to get this information:

{% set t = strptime(state_attr('sensor.sabbelknecht_nachster_wecker', 'Local Time'), '%a %b %d %H:%M:%S %Z%z %Y') %}

{{ t.hour }} {{ t.minute }}

But I really don’t know how to integrate this into an automation and am unable to find examples that I could play around with. Can I do all this in an automation? Will I need a script? Or sensors for hour and minute? I am really thankful for any hints leading me into the right direction!

You haven’t specified which service you’re using to broadcast, so here’s an example:

action:
  - service: marytts.say
    data:
      message: >
        {% set t = strptime(state_attr('sensor.sabbelknecht_nachster_wecker', 'Local Time'), '%a %b %d %H:%M:%S %Z%z %Y') %}
        Good night, the alarm is set to {{ t.hour }} hours and {{ t.minute }} minutes.
1 Like

I think you should also add entity_id of the device to this.

action:
  - service: marytts.say
    entity_id: media_player.bedroom_speaker
    data:
      message: >
        {% set t = strptime(state_attr('sensor.sabbelknecht_nachster_wecker', 'Local Time'), '%a %b %d %H:%M:%S %Z%z %Y') %}
        Good night, the alarm is set to {{ t.hour }} hours and {{ t.minute }} minutes.
1 Like

Oh yeah, that’s correct. :crazy_face:

Thanks a lot, will try tonight

Thanks a lot, it works like expected!