Skip to the content.

pyPowerwall Proxy Server

Docker Pulls

This pyPowerwall Caching Proxy handles authentication to the Powerwall Gateway and will proxy API calls to /api/meters/aggregates (power metrics), /api/system_status/soe (battery level), and many others (see HELP for full list). With the instructions below, you can containerize this proxy and run it as an endpoint for tools like telegraf to pull metrics without needing to authenticate.

Cache: Because pyPowerwall is designed to cache the auth and high frequency API calls and use HTTP persistent connections. This will help reduce the load on the Gateway and prevent crash/restart issues that can happen if too many session are created on the Gateway. Logic in pypowerwall will also activate cooldown modes if the Gateway responds with errors indicating overload.

Local or Cloud: The proxy uses the built in abstraction of pypowerwall to operate in two modes: local mode and cloud mode. Local mode will connect directly with your Powerwall’s Tesla Energy Gateway (TEG) to pull realtime data. Cloud mode will connect to the Tesla cloud APIs to pull realtime data. Cloud mode has lower fidelity than local mode and does not include some data points available on the the local API.

Control Mode: An optional mode allows the proxy to send control commands to set backup reserve percentage and mode of the Powerwall. This requires that you set and use the PW_CONTROL_SECRET environmental variable. For safety reasons, this mode is disabled by default and should be used with caution.

Quick Start

  1. Run the Docker Container to listen on port 8675. Update the -e values for your Powerwall (see Environmental Settings for options). Below are multiple examples depending on your desired access method. The local TEDAPI “full mode” access is recommended and works for all Powerwall systems (2, +, 3) but requires access to the Powerwall 192.168.91.1 (see here). The “cloud” mode example works for all systems and is required for Solar Only systems.

     # Local Access - TEDAPI "full mode" - Requires route to Powerwall 192.168.91.1 endpoint
         docker run \
             -d \
             -p 8675:8675 \
             -e PW_PORT='8675' \
             -e PW_HOST='192.168.91.1' \
             -e PW_GW_PWD='Gateway_Password' \
             -e PW_TIMEZONE='America/Chicago' \
             -e TZ='America/Chicago' \
             -e PW_CACHE_EXPIRE='5' \
             -e PW_DEBUG='no' \
             -e PW_HTTPS='no' \
             -e PW_STYLE='clear' \
             --name pypowerwall \
             --restart unless-stopped \
             jasonacox/pypowerwall
    
     # Local Access (Legacy) - Basic Metrics for PW2 and Pw+ systems (does not work for PW3)
         docker run \
             -d \
             -p 8675:8675 \
             -e PW_PORT='8675' \
             -e PW_PASSWORD='password' \
             -e PW_EMAIL='email@example.com' \
             -e PW_HOST='LAN_IP_of_Powerwall_Gateway' \
             -e PW_GW_PWD='Optional_GW_Password_for_TEDAPI_hybrid_mode' \
             -e PW_TIMEZONE='America/Los_Angeles' \
             -e TZ='America/Los_Angeles' \
             -e PW_CACHE_EXPIRE='5' \
             -e PW_DEBUG='no' \
             -e PW_HTTPS='no' \
             -e PW_STYLE='clear' \
             --name pypowerwall \
             --restart unless-stopped \
             jasonacox/pypowerwall
    
         # Note for TEDAPI hybrid mode PW_HOST must be set to 192.168.91.1
    
     # Cloud Mode Setup - Basic Metrics for all Powerwall and Solar Only Systems
         docker run \
             -d \
             -p 8675:8675 \
             -e PW_PORT='8675' \
             -e PW_EMAIL='email@example.com' \
             -e PW_HOST='' \
             -e PW_TIMEZONE='America/Los_Angeles' \
             -e TZ='America/Los_Angeles' \
             -e PW_CACHE_EXPIRE='5' \
             -e PW_DEBUG='no' \
             -e PW_HTTPS='no' \
             -e PW_STYLE='clear' \
             --name pypowerwall \
             --restart unless-stopped \
             jasonacox/pypowerwall
            
         # Required login process for Cloud Mode
         docker exec -it pypowerwall python3 -m pypowerwall setup -email=email@example.com
         docker restart pypowerwall
    
  2. Test the Proxy

     # Get Powerwall Data
     curl -i http://localhost:8675/soe
     curl -i http://localhost:8675/aggregates
     curl -i http://localhost:8675/vitals
     curl -i http://localhost:8675/strings
    
     # Get Proxy Stats
     curl -i http://localhost:8675/stats
    
     # Clear Proxy Stats
     curl -i http://localhost:8675/stats/clear
    

Build Your Own

This folder contains the server.py script that runs a simple python based webserver that makes the pyPowerwall API calls.

The Dockerfile here will allow you to containerize the proxy server for clean installation and running.

  1. Build the Docker Container

     # Build for local architecture  
     docker build -t pypowerwall:latest .
    
     # Build for all architectures - requires Docker experimental 
     docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t pypowerwall:latest . 
    
    
  2. Setup the Docker Container to listen on port 8675.

     docker run \
         -d \
         -p 8675:8675 \
         --name pypowerwall \
         --restart unless-stopped \
         pypowerwall
    
  3. Test the Proxy

     curl -i http://localhost:8675/soe
     curl -i http://localhost:8675/aggregates
    

    Browse to http://localhost:8675/ to see Powerwall web interface.

Power Flow Animation - Passthrough

The Proxy will pass authenticated calls through to the Powerwall Web Interface allowing the display of the Power Flow Animation:

flow.png

This is available by directly accessing the proxy endpoint, https://localhost:8675 (replace localhost with the address of host running pyPowerwall Proxy). You can embed this animation within an iFrame. See web/example.html.

Browser Cache Control

By default resources sent for the power flow animation passthrough are not cached by the browser. This includes fairly large CSS, JavaScript and Image PNG files which are downloaded every time the browser reloads the animation. Performance can be improved by directing the web browser to cache these resources locally - only reloading if the data in the cache is old, a period known as max-age.

You can control this with an optional environment variable PW_BROWSER_CACHE which takes a value in seconds. For example,

If PW_BROWSER_CACHE is not set, or set to zero, then no caching takes place. If you need to force a reload of the browser cache before max-age then most browsers will do this if you hold down the shift key while reloading the page.

HTTPS Support (Experimental)

The Proxy now supports https protocol using the optional environmental variable PW_HTTPS. This is useful for placing data in secured iFrame, including the power flow animation available via the Powerwall portal (https://localhost:8675/).

There are three settings for PW_HTTPS:

Troubleshooting Help

If you see python errors, make sure you entered your credentials correctly in docker run.

# See the logs
docker logs pypowerwall

# Stop the server
docker stop pypowerwall

# Start the server
docker start pypowerwall

Content does not render in iFrame or prompts you for a login:

API Help

Documentation for using the API is located in HELP.md.

Environmental Settings

The pyPowerwall Proxy will react to the following environmental variables with (defaults):

Powerwall Settings

Proxy Settings

Control Mode

If the PW_CONTROL_SECRET environmental variable is set, the proxy will attempt to connect to the cloud in addition to local mode setup (if you are using local mode). The PW_EMAIL must match your Tesla account and you need to run cloud setup before using this mode.

WARNING: Activating control mode means that the proxy can make changes to your system. This will be available to anyone who can access the proxy. For safety reasons, this mode is disabled by default and should be used with caution.

# Run Proxy - Example using local TEDAPI full mode
docker run \
    -d \
    -p 8675:8675 \
    -e PW_PORT='8675' \
    -e PW_GW_PWD='Gateway_Password' \
    -e PW_HOST='192.168.91.1' \
    -e PW_TIMEZONE='America/Los_Angeles' \
    -e TZ='America/Los_Angeles' \
    -e PW_EMAIL='email@example.com' \
    -e PW_CONTROL_SECRET='YourSecretToken' \
    --name pypowerwall \
    --restart unless-stopped \
    jasonacox/pypowerwall

# Setup Cloud
docker exec -it pypowerwall python3 -m pypowerwall setup -email=email@example.com
docker restart pypowerwall

APIs

Examples

export MODE=self_consumption
export RESERVE=20
export PW_CONTROL_SECRET=YourSecretToken

# Set Mode
curl -X POST -d "value=$MODE&token=$PW_CONTROL_SECRET" http://localhost:8675/control/mode

# Set Reserve
curl -X POST -d "value=$RESERVE&token=$PW_CONTROL_SECRET" http://localhost:8675/control/reserve

# Read Settings
curl http://localhost:8675/control/mode
curl http://localhost:8675/control/reserve

```

Release Notes

Release notes are in the RELEASE.md file.