Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tesla Cloud Option #59

Merged
merged 58 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d94e8f2
TeslaCloud class
jasonacox Dec 17, 2023
b272827
Placeholder TeslaCloud class
jasonacox Dec 17, 2023
d2c8a67
Unpack API dictionary
jasonacox Dec 17, 2023
d066e1a
Add functions and tests
jasonacox Dec 17, 2023
d686a4c
Add cache and setup
jasonacox Dec 18, 2023
13dddcb
Remove TODOs
jasonacox Dec 18, 2023
741945a
Add cloud setup to CLI
jasonacox Dec 18, 2023
34c5247
Fix log bug
jasonacox Dec 18, 2023
aac4b7f
Add teslapy to tests
jasonacox Dec 18, 2023
67f1789
CI test remove py 3.5
jasonacox Dec 18, 2023
f41c69b
Remove sample data
jasonacox Dec 19, 2023
1108f0b
Add file types
jasonacox Dec 19, 2023
73dd0fa
Add cloud mode
jasonacox Dec 19, 2023
3f6bcea
Add missing data
jasonacox Dec 19, 2023
31fe40e
Fix bug for sites without inverters
mcbirse Dec 20, 2023
f56386f
Add test proxy using cloud and local
jasonacox Dec 20, 2023
6c5a17f
Fix hash issue
jasonacox Dec 20, 2023
e8c71b2
Build t31
jasonacox Dec 20, 2023
4d4d649
Fix style
mcbirse Dec 20, 2023
9a4d007
Fix grid services data mapping which relates to VPP events
mcbirse Dec 20, 2023
f4b5022
Build t32
mcbirse Dec 20, 2023
b87af65
Unpin pypowerwall library
jasonacox Dec 21, 2023
f52dc37
Merge branch 'main' into teslacloud
jasonacox Dec 22, 2023
c06ae23
Fix backup reserve percent scaling
mcbirse Dec 22, 2023
86a3efd
Fix API mismatch
jasonacox Dec 22, 2023
974f793
Fix percentage_charged
jasonacox Dec 22, 2023
8a0d002
Prep for v0.7.0
jasonacox Dec 22, 2023
6b5baad
Minor fixes for consistency
mcbirse Dec 22, 2023
1116b9a
Fix exception when vitals is None
mcbirse Dec 22, 2023
f75855e
Add get_time_remaining()
jasonacox Dec 23, 2023
2854665
Remove vitals mock data
jasonacox Dec 23, 2023
cc0f5da
Fix vitals response
jasonacox Dec 23, 2023
d57fdc5
Add siteid selection to setup
jasonacox Dec 24, 2023
d86000a
Update setup install_requires
jasonacox Dec 24, 2023
30a5009
Fix duplicate line
jasonacox Dec 24, 2023
a1298ca
Remove test servers
jasonacox Dec 24, 2023
7476351
Update docs for v0.7.0
jasonacox Dec 24, 2023
d50660d
Add simulated vitals
jasonacox Dec 24, 2023
8d95fd0
Remove poll() cache
jasonacox Dec 24, 2023
4ba4e98
Add counter param to SITE_DATA call
jasonacox Dec 25, 2023
54a7fa5
Revise handling of siteid selection
mcbirse Dec 25, 2023
f18b6fe
Stagger TTL to reduce rate limit
jasonacox Dec 26, 2023
86a8f84
Merge branch 'teslacloud' of https://github.com/jasonacox/pypowerwall…
jasonacox Dec 26, 2023
36a08ac
Infinite loop to keep container running
jasonacox Dec 26, 2023
0bce44e
Allow no cache option with pwcacheexpire = 0
jasonacox Dec 26, 2023
2564d2f
Add stats for cloud mode
jasonacox Dec 27, 2023
56bd573
Startup details logging
jasonacox Dec 27, 2023
e9af8cf
Fix local log details
jasonacox Dec 27, 2023
c862f79
Limit cloud API requests to single thread
mcbirse Dec 29, 2023
236906e
Reduce http timeout and remove retries
mcbirse Dec 29, 2023
9cfd58d
Change elapsed time measurements to monotonic clock
mcbirse Dec 29, 2023
41cff9a
Fix exceptions and invalid return data
mcbirse Dec 29, 2023
238708a
Merge branch 'teslacloud' of https://github.com/jasonacox/pypowerwall…
jasonacox Dec 29, 2023
49c1fab
Add _site_api() to broker calls
jasonacox Dec 29, 2023
637bb29
Revise debug log order, fix sites exception
mcbirse Dec 29, 2023
6f7752e
Updates to documentation and error logging
jasonacox Dec 29, 2023
ee03be5
Proxy t35
jasonacox Dec 29, 2023
2f88fbb
Counter param starts at 1
jasonacox Dec 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/simtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]

services:
simulator:
Expand All @@ -33,7 +33,7 @@ jobs:
python -VV
python -m site
python -m pip install --upgrade pip setuptools wheel
pip install --upgrade requests protobuf
pip install --upgrade requests protobuf teslapy

- name: "Run test.py on ${{ matrix.python-version }}"
run: "python example.py"
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: "actions/checkout@v2"
Expand All @@ -27,7 +27,7 @@ jobs:
python -VV
python -m site
python -m pip install --upgrade pip setuptools wheel
pip install --upgrade requests protobuf
pip install --upgrade requests protobuf teslapy

- name: "Run test.py on ${{ matrix.python-version }}"
run: "python test.py"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ tools/set-mode.auth
tools/set-mode.conf
tools/tedapi/request.bin
tools/tedapi/app*
.pypowerwall.auth
.pypowerwall.site
proxy/pypowerwall
proxy/teslapy
48 changes: 32 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Python Version](https://img.shields.io/pypi/pyversions/pypowerwall)](https://img.shields.io/pypi/pyversions/pypowerwall)
[![PyPI Downloads](https://static.pepy.tech/badge/pypowerwall/month)](https://static.pepy.tech/badge/pypowerwall/month)

Python module to interface with Tesla Energy Gateways for Powerwall and solar power data. Currently supporting Powerwall, Powerwall 2 and Powerwall+ systems.
Python module to interface with Tesla Energy Gateways for Powerwall and solar power data. Currently supporting local access to Powerwall, Powerwall 2 and Powerwall+ systems and Tesla Owner cloud API for all systems including Solar Only and Powerwall 3 systems.

## Description

Expand All @@ -33,10 +33,13 @@ You can clone this repo or install the package with pip. Once installed, pyPowe

```bash
# Install pyPowerwall
python -m pip install pypowerwall
python3 -m pip install pypowerwall

# Scan Network for Powerwalls
python -m pypowerwall scan
python3 -m pypowerwall scan

# (optional) Setup to use Tesla Owners cloud API
python3 -m pypowerwall setup
```

FreeBSD users can install from ports or pkg [FreshPorts](https://www.freshports.org/net-mgmt/py-pypowerwall):
Expand All @@ -51,7 +54,7 @@ Via ports:
# cd /usr/ports/net-mgmt/py-pypowerwall/ && make install clean
```

Note: pyPowerwall installation will attempt to install these required python packages: _requests_ and _protobuf_.
Note: pyPowerwall installation will attempt to install these required python packages: _requests_, _protobuf_ and _teslapy_.

## Programming with pyPowerwall

Expand All @@ -64,11 +67,17 @@ and call function to poll data. Here is an example:
# Optional: Turn on Debug Mode
# pypowerwall.set_debug(True)

# Credentials for your Powerwall - Customer Login Data
# Local Mode - Credentials for your Powerwall - Customer Login
password='password'
email='email@example.com'
host = "10.0.1.123" # Address of your Powerwall Gateway
timezone = "America/Los_Angeles" # Your local timezone

# (Optional) Cloud Mode - Requires Setup
password = ""
email='email@example.com'
host = ""
timezone = "America/Los_Angeles" # Your local timezone

# Connect to Powerwall
pw = pypowerwall.Powerwall(host,password,email,timezone)
Expand Down Expand Up @@ -114,6 +123,17 @@ and call function to poll data. Here is an example:
Classes
Powerwall(host, password, email, timezone, pwcacheexpire, timeout, poolmaxsize)

Parameters
host # Hostname or IP of the Tesla gateway
password # Customer password for gateway
email # (required) Customer email for gateway / cloud
timezone # Desired timezone
pwcacheexpire = 5 # Set API cache timeout in seconds
timeout = 5 # Timeout for HTTPS calls in seconds
poolmaxsize = 10 # Pool max size for http connection re-use (persistent
connections disabled if zero)
cloudmode = False # If True, use Tesla cloud for data (default is False)

Functions
poll(api, json, force) # Return data from Powerwall api (dict if json=True, bypass cache force=True)
level() # Return battery power level percentage
Expand All @@ -134,20 +154,16 @@ and call function to poll data. Here is an example:
temps() # Return Powerwall Temperatures
alerts() # Return array of Alerts from devices
system_status(json) # Returns the system status
battery_blocks(json) # Returns battery specific information merged from system_status() and vitals()
grid_status(type) # Return the power grid status, type ="string" (default), "json", or "numeric"
battery_blocks(json) # Returns battery specific information merged from
# system_status() and vitals()
grid_status(type) # Return the power grid status, type ="string" (default),
# "json", or "numeric":
# - "string": "UP", "DOWN", "SYNCING"
# - "numeric": -1 (Syncing), 0 (DOWN), 1 (UP)
is_connected() # Returns True if able to connect and login to Powerwall
is_connected() # Returns True if able to connect to Powerwall
get_reserve(scale) # Get Battery Reserve Percentage
get_time_remaining() # Get the backup time remaining on the battery

Parameters
host # (required) hostname or IP of the Tesla gateway
password # (required) password for logging into the gateway
email # (required) email used for logging into the gateway
timezone # (required) desired timezone
pwcacheexpire = 5 # Set API cache timeout in seconds
timeout = 10 # Timeout for HTTPS calls in seconds
poolmaxsize = 10 # Pool max size for http connection re-use (persistent connections disabled if zero)
```

## Tools
Expand Down
27 changes: 26 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
# RELEASE NOTES

## v0.7.1 - Tesla Cloud Mode

* Simulate Powerwall Energy Gateway via Tesla Cloud API calls. In `cloudmode` API calls to pypowerwall APIs will result in calls made to the Tesla API to fetch the data.

Cloud Mode Setup - Use pypowerwall to fetch your Tesla Owners API Token

```bash
python3 -m pypowerwall setup

# Token and site information stored in .pypowerwall.auth and .pypowerwall.site
```

Cloud Mode Code Example

```python
import pypowerwall
pw = pypowerwall.Powerwall(email="email@example.com",cloudmode=True)
pw.power()
# Output: {'site': 2977, 'solar': 1820, 'battery': -3860, 'load': 937}
pw.poll('/api/system_status/soe')
# Output: '{"percentage": 26.403205103271222}'
```

* Added new API function to compute estimated backup time remaining on the battery: `get_time_remaining()`

## v0.6.4 - Power Flow Animation

Proxy t29 Updates
* Default page rendered by proxy (http://pypowerwall/) will render Powerflow Animation
* Default page rendered by proxy (http://pypowerwall:8675/) will render Powerflow Animation
* Animation assets (html, css, js, images, fonts, svg) will render from local filesystem instead of pulling from Powerwall TEG portal.
* Start prep for possible API removals from Powerwall TEG portal (see NOAPI settings)

Expand Down
2 changes: 1 addition & 1 deletion proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.10-alpine
WORKDIR /app
RUN pip3 install pypowerwall==0.6.4 bs4
RUN pip3 install pypowerwall==0.7.1 bs4
COPY . .
CMD ["python3", "server.py"]
EXPOSE 8675
8 changes: 8 additions & 0 deletions proxy/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## pyPowerwall Proxy Release Notes

### Proxy t35 (29 Dec 2023)

* Add `cloudmode` support for pypowerwall v0.7.1.

### Proxy t32 (20 Dec 2023)

* Fix "flashing animation" problem by matching `hash` variable in index.html to firmware version `git_hash`.

### Proxy t29 (16 Dec 2023)

* Default page rendered by proxy (http://pypowerwall/) will render Powerflow Animation
Expand Down
Loading
Loading