So in the last 2 weeks I have been put to the test of patience and road rage.

giphy

Last week there was a guy that decided to take his dog for a walk on the over pass and decided to stop and contemplate jumping.  This closed down a 3 lane highway and the 2 joining lanes completely in morning rush hour.  Diverted traffic was diverted to a 1 lane exit.  I sat in traffic for 3.5 hours!!!! At that point I called the office and said “i’m working from home, it will take me hours to get there and 30 minutes to get home.”

That was pretty rough.

This past week was obviously not as bad.  But 4 out of 5 days this week my normally 45-50 minute commute was 90 minutes.

So normally I spend 4hrs 10min on the road commuting in the morning and roughly 5 hours in the evenings (traffic gets worse)

But this week was almost 7 hours in the morning and 5 in the evening.

12 hours……

I don’t think you heard…. 12 HOURS!!!!! Just driving!!! It’s stupid.

traffic-zzz

 

Man I could get a lot of work done driving a tesla!

 

 

 

So I had this dream this week, very strange I know, and some of the details I am omitting here because well… some of it was quite sexy…. but that’s not the part I am hiding.  There was another device in my dream that I have thought about making before and in my dream I had it done.  But it had a new feature…. it told me if my drive to work was going to be longer than usual……

I know I know.  “Just watch the news you jackass!”  I can hear you all saying that.  However I cut the cable many many many moons ago.  I don’t get the news.  Two.  Well, my past brain problems have led me to a life where I don’t watch the news often because the news is generally bad and I find myself a much happier well adjusted member of society if I don’t watch the news in the morning.  But I got side tracked.

So after the wife telling me
Untitled

I decided to look into this thing that my brain was hinting at.  So I spent some time looking for mapping/navigation api’s.  I found out that TomTom has one.  Pretty good to, you can tell it what kind of vehicle you have, and if you want traffic to be taken in to account and all kinds of stuff.  So I got an api key and started coding against it.  Pretty neat.  68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f343034323534372f746f6d746f6d2e706e67

But then I found this.  This turned out to be pretty interesting by itself since I currently use a dashing dashboard for a few things internally.

I set it up for myself in dashing and it works nicely.  So we are close, but not quite what I am looking for.

So I decided to keep working, and thinking, and eating chips.

Wait.  No chips.  Just working and thinking.

I decided what I needed was 2 fold.

  1.  Traffic time must be in my Home Automation system so I can create rules based on the time.
  2. The times must be stored somewhere so I can get a new idea of “average” drive time.

I got it.  Create an item in Openhab.  Update said item periodically.  I already have openhab mysql persistance enabled.  This will work.  I will be able to run data reports based on time of day (aka MORNING during the week) and see what the average/no accident drive time is and over time even see how much time an accident add’s to my trip on average.

So now in my openhab I have the following ITEM configured in my home.items file.

1Number WorkDriveTime "Drive Time [%s minutes]"

and in my home.sitemap file

1 Text item=WorkDriveTime

I have a cronjob that runs every 5 minutes that just fires off a php file to get the tomtom info, convert seconds to minutes, round it off and update openhab.

My simple php file is here.

 1<?php
 2$string = file_get_contents("https://api.tomtom.com/routing/1/calculateRoute/28.3852,-81.5639:33.8121,-117.9190/json?routeType=fastest&traffic=true&travelMode=car&key=YOURAPIKEY");
 3$json = json_decode($string, true);
 4
 5
 6$DriveTime = round($json["routes"][0]["summary"]["travelTimeInSeconds"]/60);
 7
 8if ($DriveTime != 0) {
 9sendOpenHabUpdate("WorkDriveTime",$DriveTime);
10}
11
12
13function sendOpenHabUpdate($item, $data) {
14 $openhabserver = "http://192.168.2.90:8080/rest/items/" . $item;
15$options = array(
16'http' =&gt; array(
17'header' =&gt; "Content-type: text/plain\r\n",
18'method' =&gt; 'POST',
19'content' =&gt; (string)$data,
20),
21);
22
23$context = stream_context_create($options);
24$result = file_get_contents($openhabserver, false, $context);
25
26return $result;
27}

So with this now running in my crontab I have my database slowly updating with drive times.

Oh. If you want to get a key for TomTom yourself just go to http://developer.tomtom.com/

So what do I have in store for this. Well, there is another value that comes back in this specifically related to “delay from traffic” so I may add this in as another number item to track. But the plan is to know before I leave the house if I should take a regular coffee or a giant coffee to get me through the morning commute. download