This is a plugin to support the Automatic OBD-II device. This is a device that connects to your car's OBD-II port and allows you to gather all kinds of neat information about your car, including when the car starts, when the car is turned off, the current location of the car, even things like if hard acceleration or breaking occur, check engine light notification and information, and even crash detection. It's an amazing device! While the native mobile apps for it do a fantastic job of keeping me aware of what's going on with my cars, I wanted to be able to tie actions from my car into my home automation system. Automatic does have [url=htp://www.ifttt.com]IFTTT[/url] support, but I wanted to be able to hook directly into Indigo.
Some usage ideas:
- If it's between 7am and 8am, Monday to Friday, and the car starts, then send a message to my carpoolers letting them know I'm on my way.
- If it's after 2pm, the car is currently on Enterprise Drive, and the car starts, then let my wife know I'm on my way home from work.
- As the car approaches home, announce what street the car is on.
- And of course, things like changing the lights, the temperature of the house, locking the front door when the car leaves the house, etc.
Dependencies
I have updated the plugin to include all of the dependencies within the plugin itself, so you should not need to install anything other than the plugin itself.
The old info:
This plugin has a dependency on socketIO-client, as well as some other modules. One way to install this is to bring up a Terminal, and type:
sudo -H pip install -U socketIO-client --ignore-installed six
sudo -H pip install -U requests[security] --ignore-installed six
sudo -H pip install --ignore-installed pyOpenSSL --upgrade
sudo -H pip install ndg-httpsclient
If you have both python 2.7 and 3.x installed, then you will need to explicitly install into 2.7 like this:
sudo -H pip2.7 install -U socketIO-client --ignore-installed six
It may make sense to just do both pip and pip2.7 for each of the modules.
I'm not sure if you need to reboot your whole computer or just quit out of Indigo and re-launch it, but one or the other is definitely required in order to get things working.
Automatic API Access
In order to use this plugin, you will need to have API access to Automatic to be able to access your device's data.
Create a developer account at Automatic. Once you have your account, click on Create a New Application. Give it a Name and Description - it really doesn't matter what you put here as you will never be requesting to move "your app" to production mode, but you may want to make it sound official.
You will want to capture your Client ID and your Secret. Those both will need to be entered in the plugin configuration screen.
Change the Event Delivery option to WEBSOCKET. The plugin will make a request to Automatic's API, and will remain connected. When your device has updates, they will be sent to this socket for the plugin to process.
By default, they don't give you access to your current location information, so you need to ask for that access. Click on Request Changes to Scopes. Read the info and click Continue. In the Tell Us About Your App section, tell them something like you are working on a home-automation plugin to be able to do neat things based on the car's current location. Then check off the Access heartbeat location updates in realtime during a drive. (scope:current_location) checkbox, and click on Submit Request.
NOTE: It took them four days to give me access to the current_location information.
Google API Access
In order to use this plugin, you will need to have API access to Google Maps to be able to convert the Automatic location data to human-usable information.
Go to Google Developers Google Maps APIs. Click on Get Started. You will need access to Google Maps Distance Matrix API, as well as Google Maps Geocoding API. You will have one API key to access both of these services, but I think you need to request access to each of them. (maybe not?) For each of them, click on Get a Key, and capture the Google Maps API Key that they give you. You will need this key to configure the Automatic plugin.
Indigo Automatic OBD-II Plugin
You can get the plugin here: https://github.com/dgarozzo/indigo-auto ... -ii-plugin. To install it, you should be able to double-click it, and Indigo will take care of the rest.
Plugin Configuration
Once you have installed the plugin, the first thing you will want to do is navigate to menu option Plugins -> Automatic OBD-II -> Configure...
This dialog box is where you will enter in your Client ID and Secret for the Automatic API. After you enter that information, click the Click to Authorize Go button. Assuming you are on the box that you have Indigo running on (and not connected to it remotely), a browser window should appear, prompting you to log in to your Automatic account.
IMPORTANT NOTE: If you haven't yet received approval for access to current_location, leave the current location access checkbox unchecked. After you get the access, re-do the authentication with the checkbox checked so you start receiving current_location information. If you check off this box before you have access, you will get an error.
Once you log in, Automatic will redirect you to another page that will likely be some kind of Page Not Found. The url will start with http://localhost. Copy that entire url and go back to your Indigo Configure Automatic OBD-II dialog box, and paste it in to the Callback URL box. Then click the Go button to obtain your Access Token. You should see a success message appear.
At the bottom of the dialog box is where you need to enter in your Google Maps API Key, as well as your home address.
If you want to fill up your Indigo logs with lots of neat info, check off the Enable Debug Logging checkbox.
Click Save.
Create a Device
From Indigo, create a New Device. Select Type: Automatic OBD-II. Select Model: Automatic OBD-II. The Device Settings dialog box should appear. On this screen, you will be able to choose which Vehicle you want the device to represent. Click Save.
Once you have saved your device, the plugin will retrieve some additional data for that vehicle, and will save that data in it's device states. You can see that info in Indigo on the bottom half of the screen when you select the device.
States include:
ETA - A formatted string containing the time, distance, and estimated time of arrival to home.
currentMilesFromHome - the number of miles from home
location - the street the vehicle is on
previousMilesFromHome - a way to keep track of where the vehicle was when it started a trip; used to determine if the vehicle is approaching home; resets to zero every time it gets "half-way home"
tag - the JSON response from the Automatic API for tag info
trip - the JSON response from the Automatic API for trip info
user - the JSON response from the Automatic API for user info
vehicle - the JSON response from the Automatic API for vehicle info
Triggers
You can create a trigger based on events that are received from Automatic. Click on Create New Trigger, and choose Type: Automatic OBD-II Event.
Choose the Event you want to trigger on: Trip Finished, Ignition On, Ignition Off, Speeding, Hard Break, Hard Acceleration, Check Engine Light On, Check Engine Light Off, Location Updated, Approaching Home.
Once you choose an Event, you will be presented a dialog box asking for which vehicle you want this trigger to be for.
After you set your trigger, you can then invoke the actions that you wish to take.
For example, I have a trigger for when my car's ignition turns ok. The action that I set is of Type: Execute Script, and I have Embedded Python with the following code:
Code: Select all
car = indigo.devices["Automatic OBD Audi"]
indigo.server.speak("The car has started on " + car.states["location"])
Device Actions
I created one device action - it's to refresh the device's states. The states get updated automatically based on information received by the Automatic device, so I don't think this action will be used by anybody. I left it in there for debugging, I guess.