Commute Time Tracker suggestions/help

Looking for ideas for a commute tracker. I’m moved from smartthings recently and am slowly working on recreating some of my automations and routines.

I had one that more for fun, but I enjoyed.

When I leave home, work, or any map location I’ve set up (pretty much work and home, haha) I marked a left time and an arrival time. Then did the math, and sent the data to a google spreadsheet using IFTTT.

So I sent three bits of info to the spreadsheet

Total time, starting location, and ending location

So I know that my tracking device knows when I’m home and when I’m at work, so it seems pretty easy, just don’t know where to look for history

So it would be something like when I arrive at a marked location, Get the following info and do some math, and send it to IFTTT.
So the trigger would be arriving at a marked location
What I would want to know is what was my last “marked” map location, and what time was I at that location, and what time is it now. Subtract those times. There’s my commute time.
Then send last location, current location, and commute time to IFTTT.

Any tips to get started on how to get history from a device

Here is another one I had, that was actually even more useful. Set a light to a color based on how long it looked like it would take to get to work

I had a scheduled get request go google maps api

https://maps.googleapis.com/maps/api/distancematrix/json?departure_time=now&origins={origin_address}&destinations={destination_address}&key={api_key}

I then pulled two bits on info
$response.rows[0].elements[0].duration_in_traffic.text which is current commute time
$response.rows[0].elements[0].duration.value which is the typical commute time

Then I did some math and compared the two times. I ran this every 5 minutes starting about 30 minutes before I usually left work.
If the normal commute and the current commute were close I turned a hue light on and set color to green
If the commute was 25% longer than normal I set it to orange
if the commute was 50% or more, I set the color to red, and I also set myself a notification saying “Traffic sucks, get going”

This seems like it would not be too hard, I just don’t know how to make these calls with home assistant