Calculating correct wakeup timer from google maps travel time

Hello!

I have my work schedule in google calendar with correct time and place, with some hass component i can read that and calculate actual driving time to that workplace.

This is how it looks now:

Im so close to be done, but before i can share my project with the community, i got stuck in a problem… It cannot calculate the time when the travel time more than 60mins.

So if the travel time is less than 60mins:
states.sensor.google_travel_time__driving.attributes.duration.split(" ")[0] ← means minutes

‘{{states.calendar.work.attributes.start_time.split(" “)[0]}} {{ ((as_timestamp(states.calendar.work.attributes.start_time) - states.sensor.google_travel_time__driving.attributes.duration.split(” “)[0] | int *60) | timestamp_utc).split(” ")[1]}}’

But if the traveltime exceeds 60mins, it needs this:

states.sensor.google_travel_time__driving.attributes.duration.split(" ")[0] ← means minutes
states.sensor.google_travel_time__driving.attributes.duration.split(" ")[2] ← means hours

‘{{states.calendar.work.attributes.start_time.split(" “)[0]}} {{ (((as_timestamp(states.calendar.work.attributes.start_time) - states.sensor.google_travel_time__driving.attributes.duration.split(” “)[0] | int *3600 + states.sensor.google_travel_time__driving.attributes.duration.split(” “)[2] | int *60 | int) | timestamp_utc).split(” “)[1].split(”:“)[0]) | int -1}}:{{ ((as_timestamp(states.calendar.work.attributes.start_time) - states.sensor.google_travel_time__driving.attributes.duration.split(” “)[0] | int *3600 + states.sensor.google_travel_time__driving.attributes.duration.split(” “)[2] | int *60 | int) | timestamp_utc).split(” “)[1].split(”:")[1]}}’

Its a lot of mumbojumbo i know… Is there anyone who know a sh*tton about templating?

It would be useful to know what the sensor attribute you are parsing looks like to see if there may be a different approach (an example for >60 min and one for <60 mins)

1 Like

@dale3h Is a template master…

1 Like

This is how it looks like:

Im currently using the duration attribute which is using a “XXhour XXmins” format. Maybe calculate the time from State? Thats seems like using a XX(mins) format. (like 85(mins))

Edit: Yeah… just using the sensor state fixes it. No idea why i was using the duration attribute.

{{ ((as_timestamp(states.calendar.work.attributes.start_time) - states.sensor.google_travel_time__driving.state | int *60 +3600) | timestamp_utc)}}

1 Like

Ok cool, I was going to say just to check the number of values after splitting the duration string, and if there is 4 of them then you know its using hours and minutes. Then you could have calculated the total minutes from there and used that. But since the sensor state itself already provides that, no point!

Thanks tho! :slight_smile:

Excuse me if i missed this but do you have the finished product posted?

Nope.

Got stuck at the finish line with Tasker. I dont think Tasker can set alarms based on variables. I might be wrong tho.

Do you have the YAML for HA config? I would be interested in using the wakeup time for other automations.