{"id":757,"date":"2018-12-09T23:31:15","date_gmt":"2018-12-10T05:31:15","guid":{"rendered":"https:\/\/blog.escarra.org\/?p=757"},"modified":"2020-06-23T07:40:48","modified_gmt":"2020-06-23T13:40:48","slug":"tesla-smart-meters-and-automation-via-apis","status":"publish","type":"post","link":"https:\/\/blog.escarra.org\/?p=757","title":{"rendered":"Tesla, Smart Meters and Automation via APIs"},"content":{"rendered":"\n<p>A couple of months ago I took delivery on my Tesla Model 3 &#8220;Speedy&#8221;. 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&#8217;s always-connected API and how to use it, and also signed up for off-peak billing from my local utility ComEd.<\/p>\n\n\n\n<p>Then I decided to take things to a new level by combining two API&#8217;s and making some triggers for charging, so this is the whole point of my post.<\/p>\n\n\n\n<p class=\"has-background has-very-light-gray-background-color\"><strong>Early TL;DR:<\/strong> Using ComEd&#8217;s <a href=\"https:\/\/hourlypricing.comed.com\/hp-api\/\">Hourly Pricing&#8217;s API<\/a>, Tesla&#8217;s <a href=\"https:\/\/tesla-api.timdorr.com\/\">API<\/a>, <a href=\"https:\/\/homeseer.com\/home-automation-software\/\">HomeSeer&#8217;s <\/a>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.<\/p>\n\n\n\n<p>Initially I wanted to see if there was a way to tie the car to my home automation software, HomeSeer, and turns out there&#8217;s an awesome plugin called <a href=\"https:\/\/forums.homeseer.com\/forum\/homeseer-products-services\/general-discussion-area\/108679-teslaseer-plugin-using-tesla-motors-api\">teslaSeer<\/a>. It uses Tesla&#8217;s API to create objects within HomeSeer&#8217;s interface, so now you can schedule actions or create triggers, like have the car to heat up based on a time or what&#8217;s on my calendar for the day. One of the options is to start or stop charging.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-attachment-id=\"761\" data-permalink=\"https:\/\/blog.escarra.org\/?attachment_id=761\" data-orig-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard.png\" data-orig-size=\"1007,702\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2018-12-09 22_15_02-Clipboard\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard-300x209.png\" data-large-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard.png\" decoding=\"async\" loading=\"lazy\" width=\"1007\" height=\"702\" src=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard.png\" alt=\"\" class=\"wp-image-761\" srcset=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard.png 1007w, https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard-300x209.png 300w, https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-22_15_02-Clipboard-768x535.png 768w\" sizes=\"(max-width: 1007px) 100vw, 1007px\" \/><figcaption>teslaSeer plugin on HomeSeer<\/figcaption><\/figure>\n\n\n\n<p>Right after putting in the order for the Model 3, I signed up for ComEd&#8217;s <a href=\"https:\/\/hourlypricing.comed.com\/\">Hourly Pricing<\/a> 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&#8230; turns out ComEd&#8217;s Hourly Pricing program ALSO has an API, just like the car, which is AWESOME and far better than just simple off-peak. The <a href=\"https:\/\/hourlypricing.comed.com\/hp-api\/\">API<\/a> gives you an output of either JSON or XML with 5-minute average or hourly average.<\/p>\n\n\n\n<p>What&#8217;s even more interesting is that anyone can see the &#8220;Dashboard&#8221; off ComEd&#8217;s program, and sometimes it dips BELOW 0c, meaning you&#8217;re getting credited for consuming electricity as an hourly customer.<\/p>\n\n\n\n<p>So I thought&#8230; if there&#8217;s a chance that price could dip below say&#8230; a penny per kWh&#8230; could I automate a charge then? And stop it if the price is too high?<\/p>\n\n\n\n<p>OF COURSE, it just took some sweat and hacks. My way of doing this isn&#8217;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&#8217;s called, but it&#8217;s not quick enough for what I need&#8221;<\/p>\n\n\n\n<p>Here&#8217;s what I ended up doing&#8230;<\/p>\n\n\n\n<ol><li>Using <a href=\"https:\/\/forums.homeseer.com\/forum\/3rd-party-developer-area\/general-developer-discussion\/jon00\/88801-jon00-datascraper-script\">Jon00&#8217;s DataScraper<\/a> script, created a trigger on price dips and jumps from ComEd every minute. Basically &#8220;If price is below 1&#8221;<\/li><li>With teslaSeer, wake then update the car to get it ready to take in the next couple of commands. The event won&#8217;t continue until the car is awake which takes anywhere between 30 seconds and 2 minutes<\/li><li>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<\/li><li>If the event gets triggered, send me a notification<\/li><\/ol>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>That&#8217;s about it. There&#8217;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&#8217;t wake up to a car that didn&#8217;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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-attachment-id=\"763\" data-permalink=\"https:\/\/blog.escarra.org\/?attachment_id=763\" data-orig-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events.png\" data-orig-size=\"875,784\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2018-12-09 23_16_56-HomeSeer Web Control &#8211; Events\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events-300x269.png\" data-large-file=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events.png\" decoding=\"async\" loading=\"lazy\" width=\"875\" height=\"784\" src=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events.png\" alt=\"\" class=\"wp-image-763\" srcset=\"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events.png 875w, https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events-300x269.png 300w, https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events-768x688.png 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><figcaption>HomeSeer&#8217;s &#8220;Events&#8221; page on the Tesla group<\/figcaption><\/figure>\n\n\n\n<p>To the smart folks out there I&#8217;m sure there&#8217;s a better way to trigger these things to happen, maybe using AWS Lambda or Azure Functions instead of HomeSeer, after all it&#8217;s just HTTP calls that we&#8217;re making and some basic parameters passed. If you have something similar working, I would absolutely love to hear it.<\/p>\n\n\n\n<p>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&#8217;s my referral code:&nbsp;<br><a href=\"https:\/\/ts.la\/gonzalo13311\">https:\/\/ts.la\/gonzalo13311<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of months ago I took delivery on my Tesla Model 3 &#8220;Speedy&#8221;. 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&#8217;s always-connected API and how to use it, and also signed up for off-peak [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":763,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false,"jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/blog.escarra.org\/wp-content\/uploads\/2018\/12\/2018-12-09-23_16_56-HomeSeer-Web-Control-Events.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/posts\/757"}],"collection":[{"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=757"}],"version-history":[{"count":4,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":770,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions\/770"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=\/wp\/v2\/media\/763"}],"wp:attachment":[{"href":"https:\/\/blog.escarra.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.escarra.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}