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
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:
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.