Automation that Announces Time at which Timer will end thru TTS

Is this automaton/script that Announces Time at which Timer will end possible? Has anyone tried?

Can you help me with sample code or how to approach?

Example:
Would like to accomplish an Automation/Script something like follow below
1: Turn ON smart socket A (To charge any Dumb Device say water dispenser pump)
2: start a Timer for 2 Hours once the Smart Socket A is turned ON
3. Announce in Google home speaker every 10 mins “Your water dispense pump is charging now & will be complete full charge by XX:XX AM/PM (XX:XX time is real time based on the timer triggered in Step 2 above)”

Say if Smart Socket is triggred to ON state at 9AM Google home speaker should say every 10 mins "Your water dispense pump is charging now & will be complete full charge by 11AM)

Say if Smart Socket is triggred to ON state at 10 AM Google home speaker should say every 10 mins "Your water dispense pump is charging now & will be complete full charge by 12 PM) & So on

Please help

Thanks in advance.

I suspect you’re going to ultimately want something a bit more involved, but if you just want to announce the time that is two hours after the time an automation or script turns on a switch, you could use the following template to capture that time into, say, an input_text:

{{ (now().timestamp()+2*60*60)|timestamp_custom('%H:%M') }}
1 Like

Thanks looks excatly what i need.
but how do i use this values in automation?

Well, like anything, there’s probably several ways to do this. And now that you ask, I would probably use an input_datetime instead of an input_text:

input_datetime:
  announce_done:
    name: Datetime when announcement should stop
    has_date: true
    has_time: true

And then for the automation, one automation to start the announcements:

automation:
  - alias: Start announcement
    trigger:
      platform: state
      entity_id: SMART_SOCKET_ENTITY_ID
      to: 'on'
    action:
      service: intput_datetime.set_datetime
      entity_id: input_datetime.announce_done
      data_template:
        date: "{{ (now().timestamp()+2*60*60)|timestamp_custom('%Y-%d-%m') }}"
        time: "{{ (now().timestamp()+2*60*60)|timestamp_custom('%H:%M:%S') }}"

And another that does the announcements until the two hours are past:

  - alias: Announce if time not done
    trigger:
      platform: time
      minutes: '/10'
      seconds: 0
    condition:
      condition: template
      value_template: >
        {{ now().timestamp() < state_attr('input_datetime.announce_done', 'timestamp') }}
    action:
      service: tts.google_say
      data_template:
        message: >
          Your water dispense pump is charging now & will be complete full charge by {{
            state_attr('input_datetime.announce_done', 'timestamp')
            |timestamp_custom('%I:%M %p') }}

This isn’t perfect, but hopefully it’s a start. The one major flaw it has is setting the date & time of an input_datetime cannot be done in one template, so it has to set the date and time each in its own template. So, grabbing the time will happen twice. If these two events happened just before and just after midnight then the input_datetime would get set incorrectly. This can be solved one of two ways. The first would be for the input_datetime component to be enhanced to allow setting both the date and time with one template. (At some point I’ll get around to opening an Issue against this component to ask to have this added as a new feature.) The other would be to first save now().timestamp() to an input_number, and then use that to set the input_datetime.

1 Like

Thanks I will give it a try