Month: December 2018

Tesla, Smart Meters and Automation via APIs

A couple of months ago I took delivery on my Tesla Model 3 “Speedy”. In the time between placing the order and actually getting the car, aside from being beyond excited, I took a bit of time to learn about the car’s always-connected API and how to use it, and also signed up for off-peak billing from my local utility ComEd.

Then I decided to take things to a new level by combining two API’s and making some triggers for charging, so this is the whole point of my post.

Early TL;DR: Using ComEd’s Hourly Pricing’s API, Tesla’s API, HomeSeer’s software and a couple of plugins, I am now triggering charges when electricity prices are super low, so I can charge the car for a couple pennies per kWh or even for free or get money back.

Initially I wanted to see if there was a way to tie the car to my home automation software, HomeSeer, and turns out there’s an awesome plugin called teslaSeer. It uses Tesla’s API to create objects within HomeSeer’s interface, so now you can schedule actions or create triggers, like have the car to heat up based on a time or what’s on my calendar for the day. One of the options is to start or stop charging.

teslaSeer plugin on HomeSeer

Right after putting in the order for the Model 3, I signed up for ComEd’s Hourly Pricing program which takes about a month to really kick in. My thought was just to use the off-peak pricing and schedule my charges from the Tesla directly, say at 2am every night. But… turns out ComEd’s Hourly Pricing program ALSO has an API, just like the car, which is AWESOME and far better than just simple off-peak. The API gives you an output of either JSON or XML with 5-minute average or hourly average.

What’s even more interesting is that anyone can see the “Dashboard” off ComEd’s program, and sometimes it dips BELOW 0c, meaning you’re getting credited for consuming electricity as an hourly customer.

So I thought… if there’s a chance that price could dip below say… a penny per kWh… could I automate a charge then? And stop it if the price is too high?

OF COURSE, it just took some sweat and hacks. My way of doing this isn’t particularly elegant or friendly, but it works for me. Think of IFTTT but with a lot more duct-tape to make it all work. (sidenote, ComEd Hourly Pricing has an IFTTT trigger or whatever it’s called, but it’s not quick enough for what I need”

Here’s what I ended up doing…

  1. Using Jon00’s DataScraper script, created a trigger on price dips and jumps from ComEd every minute. Basically “If price is below 1”
  2. With teslaSeer, wake then update the car to get it ready to take in the next couple of commands. The event won’t continue until the car is awake which takes anywhere between 30 seconds and 2 minutes
  3. Once the Tesla is awake, set SoC to 90% (I usually leave this set to 70%) and then trigger a charge. That gives me at least 16kWh of juice I can consume, more if the car has been discharged
  4. If the event gets triggered, send me a notification

My electric bill was actually lower in price by about 15% with this going, but was about 30% higher in kWh consumed. Go figure :). My Tesla seems to be running on free electricity.

That’s about it. There’s another event that stops the charge if the price goes above a certain value and also the battery is over 70% SoC. That way I don’t wake up to a car that didn’t charge because it was stopped because of some price fluctuation. Below is what the whole thing looks like right now. Again, not pretty, but completely functional and reliable.

HomeSeer’s “Events” page on the Tesla group

To the smart folks out there I’m sure there’s a better way to trigger these things to happen, maybe using AWS Lambda or Azure Functions instead of HomeSeer, after all it’s just HTTP calls that we’re making and some basic parameters passed. If you have something similar working, I would absolutely love to hear it.

Also, If what I just wrote pushed you over the edge to get a Tesla and want to get 6 months of free Supercharging with it, here’s my referral code: