Hacking the Tesla Powerwall for bad weather management, Observability, and Fun

Who’s this for: Anyone considering an IOT-driven technology or an overall tech enthusiast

Depiction of a typical Solar and Tesla-driven home (disclaimer: not my home :)

Recently due to bad weather, Melbourne experienced power cuts from several hours to more than a week in some suburbs. Despite several trees falling over and extensive power cuts, the Tesla storm watcher didn’t activate even once. This inspired me to think of a smarter and autonomous approach for my Tesla Powerwall management. Currently, Tesla provides you a limiting all or nothing scenario (full back-up or manual back-up configs).

I am a technologist who lives in Eltham, Victoria (Australia). During the pandemic and city lockdowns, I began investigating sustainable products. This affected the way I shop, consume, and recycle.

To do the “proverbial” right thing, my better half and I purchased a solar solution especially due to the guilt of consuming 15–18 kilowatts a day. More specifically, we purchased Canadian solar panels, Fronius inverter, and a Tesla Powerwall and gateway system.

The resulting outcome has been a surprise. Even in winter months, we have been offsetting roughly 50 percent of our daily electricity consumption through solar. Let’s get into the meat of things — the technical solution. But first, let’s get on the same page by agreeing to the WHY part (needs for this solution).

Since Tesla Powerwall storm watcher mechanism didn’t kick in proactively for the bad weather recently experienced in Melbourne, I thought I’ll create something that works more accurately and predictably. Furthermore, existing metrics shown in the Tesla iOS and Android App don’t answer a lot of key questions that the resulting Dynatrace Dashboard can answer more specifically. By leveraging these key metrics, I can also execute auto remediation (powered by Keptn) and actions like increasing back up capacity or charging battery from the grid (if weather isn’t sunny). This works as a pre-emptive measure to mitigate the after-effects of power cuts & service disruptions.

By filtering, parsing and pushing metrics into Dynatrace Metrics API v2, I was able to answer these vital questions with the anew visibility:

  1. Is there a total system failure? (both grid down and battery depleted situation)
  2. What’s the current consumption load and what’s supporting the load (solar, grid, battery backup)? I call this conscience checker.
  3. What’s my current electricity consumption pattern (peak vs non peak)? Am I rationalising compared to historical consumption or utilising more (baselining consumption)?
  4. Is the battery charging in real-time via solar (yay) or am I consuming grid supplied power (nay)?
  5. Is there a need to perform a 75% — 100% back up in the next few days (due to bad weather system)?

The answers to the above questions are the found capabilities backed by the power of automation, intelligence, and openness atop Dynatrace Platform.

Now, let’s look at the HOW part of the solution.

Simple solution architecture at play

The diagram above shares the technical workings of my experiment. It flows right wards and is bi-directional between some entities. Simply put, I created a token within “Auth App for Tesla” that acts as an access key to the Powerwall. To save you pain, the Tesla unofficial API documentation can be found here. Though, there are better explanations available on some Github repos and Python package index website. Repo 1 | PYPI.

Huge thanks to @Kim Hansen and his Auth App for Tesla. Once you have grasped these resources, you’ll need to setup an account on Openweathermap.org. I used two sets of APIsdaily — 16 days and current weather. This is your enhanced storm watcher service that provides you the decision link for intelligent backup reserve percentage configuration. To bring it all together, I wrote a Python program as the orchestrator. Will post it on Github soon and update here. This program runs as a container on a Minikube cluster.

What part: A simple Pseudocode for the program is straight forward:

  • Step 1: Poll weather APIs for storm detection (all distinct weather patterns prescribed here)
  • Step 2: Establish a secure connection with the Powerwall
  • Step 3: Extract vital health and consumption metrics via Tesla APIs.
  • Step 4: Parse them into key metrics — total energy %, system down condition, boolean values — gridUsed, batteryUsed, load in kilowatts, battery %, outage detection, consumption pattern and more.
  • Step 5: If storm detected, set reserve back up % to 85%.
  • Step 6: Potentially the most critical step — begin rationing, recline your couch, put on Netflix, and brace for a storm :)

Aside the smart management of Tesla Powerwall, enhanced trackability, dashboarding, and proactive alerting were the most rewarding outcomes.

Dynatrace Dashboard that tracks the Tesla Powerwall

What this means for Powerwall owners like me?

Current Storm watcher service by Tesla only activates in ice storm and hurricane-like conditions. I enhanced the implemented storm watcher for a lot more patterns — Thunderstorm, high-speed winds, heavy rains, etc. Also, through the demonstrated solution, I can prepare for a potential future outage way in advance (3–4 days). The checker runs every 5 minutes and auto-updates the reserve % to 85–100%.

It is my suspicion that Tesla designed the Powerwall for USA and EU only. I could be wrong. Also, for those of you who feel inspired to play with your hybrid or EV vehicle APIs — Volvo Connect (link provided below) is a good case in point. There’s some exciting functions available over their APIs. Tesla is no where close to Volvo in terms of universal and secured data access readiness and programmability. Sometimes, we all jump aboard the cool aid train. That’s ok, as long as we learn. Also, to clarify this post isn’t about bashing Tesla. I am vested (literally) in the company and its mission, and a huge Elon fan.

FYI — I have ordered 12 more LG panels and two more Tesla Powerwalls batteries on the Tesla app to go off the grid (target to achieve this goal by the end of 2021). Will do an update video post on Medium on how it pans out when I get there.

To improve existing market leading solutions is easy. To summarise, my autonomous solution for “dooms day prep” (ok I lie, more for bad weather) leverages Open weather APIs, Dynatrace Metrics v2.0, Dynatrace software intelligence platform, reverse-engineered Tesla APIs, Minikube K8s host, and latest Python.

The solution also provides full observability surrounding our energy consumption, grid vs battery use, detects power outages, battery charge events, and many more.

To get started — If you don’t have a battery, look at your inverter or solar panels manual or Google the brand & model number, you can use them as a data source. Also, you’ll need to connect this device to internet to make it accessible. Most data sources are OAuth protected, so not to worry.

This solution provides a peeking window into the art of possible for advanced & futuristic utility sector programs, some named below:

  1. Smart homes
  2. Bi-directional grid connectivity
  3. Smart billing and on-the-go consumption reports
  4. Field operations assistance
  5. Operational expenditure optimisation for utility companies.

Anticipated challenge: Imagine the observability needs when you multiply and extend this use-case to smart homes and you literally have to manage, support, and monitor millions of homes and billions/trillions of IOT devices. You need a platform that supports automation, intelligence, freedom to experiment, openness, scale, high cardinality, and at least a 3 9s (99.9% uptime) reliability. BTW, Dynatrace is ready to take you on the journey (shameless plug).

This is just one example how modern technology (even appliance systems) can provide the power back in the hands of the consumers like you and me.

  • Own a Volvo — try this!
  • Own a Tesla — explore this!
  • Own a Fronius Inverter — read this!

If you’re still with me, please hit the clap icon. That’s what keeps me going and motivates me to share my learnings and experiences. Also, if you have any comments, feedback, or want to collaborate on a project — please leave a comment or connect with me on LinkedIn. Happy hacking!

Sales Engineering Leader | SRE and Dev advocate | Tech enthusiast | Dad