I’ve got an automation where I’m trying to take the travel time to home from a named zone and create an ETA in a notification. Is there a way to add the minutes for travel to the current time?
alias: Erin Left Swim Lessons
description: ""
trigger:
- platform: zone
entity_id: person.erin
zone: zone.oak_city_swim
event: leave
condition: []
action:
- service: notify.mobile_app_pixel_5
data:
message: Erin Left the Swim Lessons, ETA - {{ ((now().strftime('%I:%M')) + ((state_attr('sensor.erin_travel_time_to_home','duration'))|int|timestamp_custom('%',false)) ) }}
mode: single
This sends a notification but the time is the current time not the ETA.
I was just sending the travel time but I wouldn’t always see the notification right away and then I’d have to do math in my head to figure out when time was to expect them.
What am I doing wrong here?
I’m getting travel time from Waze in minutes (9.45346 minutes).
I’m surprised you are seeing anything as your template is not quoted.
What format is the duration attribute in?
If it is a time datetime object you can do this:
message: Erin Left the Swim Lessons, ETA - "{{ ( now() + state_attr('sensor.erin_travel_time_to_home','duration') ).strftime('%-I:%M') }}"
If it is not a datetime object:
message: Erin Left the Swim Lessons, ETA - "{{ ( now() + state_attr('sensor.erin_travel_time_to_home','duration')|as_timedelta ).strftime('%-I:%M') }}"
hey @tom_l , thanks for the response and your help. The template was just putting quotes in my message when I quoted it so I took them out and it still worked. I was puzzled by that as well.
The format seems to be a fixed decimal
so I would guess that I’m not dealing with a datetime object but when I use the suggest code you provided it throws this error:
Error rendering data template: TypeError: expected string or bytes-like object
Running it with the datetime code gives me this error:
Error rendering data template: TypeError: unsupported operand type(s) for +: ‘datetime.datetime’ and ‘float’
I feel like I just need to be able to take the duration and convert it to a datetime object then add it to the current time but I’m stuck on how to do that.