Open ttl74ls100 opened 4 weeks ago
Thanks @ttl74ls100 ! I made the update.
Starting with v0.10.0, you don't need to use this tool and can talk to tedapi via the library. I'll create an example and post it as well.
With pyPowerwall v0.10.0, you can now run the TEDAPI tool via the command line (CLI):
# First, upgrade if you haven't
pip install -U pypowerwall
# Run the tool
python3 -m pypowerwall.tedapi
It will prompt you for the Powerwall Gateway password (usually printed on the QR code on the gateway), and will then query the Powerwall for config and curren site data. It will display some and write entire payloads to config.json
and status.json
in the current directory. Example:
Tesla Powerwall Gateway TEDAPI Reader
Enter Powerwall Gateway Password: **********
Connecting to Powerwall Gateway 192.168.91.1
- Configuration:
- Site Name: Energy Gateway
- Battery Commission Date: 2021-09-25T16:05:08-07:00
- VIN: 123***-**-**-*--TG************
- Number of Powerwalls: 2
- Power Data:
- Battery Charge: 100.0% (25772Wh of 25772Wh)
- Battery: -10W
- Site: -337W
- Load: 1108W
- Solar: 1460W
- Solar_Rgm: 1447W
- Generator: 0W
- Conductor: 0W
- Configuration and Status saved to config.json and status.json
The following python script will connect to the gateway and display power data:
# Import Class
from pypowerwall.tedapi import TEDAPI
gw_pwd = "THEGWPASS"
# Connect to Gateway
gw = TEDAPI(gw_pwd)
# Grab the Config and Live Status
config = gw.get_config()
status = gw.get_status()
# Print
site_info = config.get('site_info', {})
site_name = site_info.get('site_name', 'Unknown')
print(f"My Site: {site_name}")
meterAggregates = status.get('control', {}).get('meterAggregates', [])
for meter in meterAggregates:
location = meter.get('location', 'Unknown').title()
realPowerW = int(meter.get('realPowerW', 0))
print(f" - {location}: {realPowerW}W")
Using a python:3.10-alpine container, I installed pypowerwall
and ran python3 -m pypowerwall.tedapi
with the following result:
Connecting to Powerwall Gateway 192.168.91.1
Failed to connect to Powerwall Gateway
Traceback (most recent call last):
File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/app/jctest-env/lib/python3.10/site-packages/pypowerwall/tedapi/__main__.py", line 27, in <module>
ted = TEDAPI(gw_pwd)
File "/app/jctest-env/lib/python3.10/site-packages/pypowerwall/tedapi/__init__.py", line 86, in __init__
raise ValueError("Failed to connect to Powerwall Gateway")
ValueError: Failed to connect to Powerwall Gateway
Here are the version numbers from the install:
(jctest-env) /app/jctest-env # pip install -U pypowerwall
Requirement already satisfied: pypowerwall in ./lib/python3.10/site-packages (0.10.2)
Requirement already satisfied: requests in ./lib/python3.10/site-packages (from pypowerwall) (2.32.3)
Requirement already satisfied: protobuf in ./lib/python3.10/site-packages (from pypowerwall) (5.27.1)
Requirement already satisfied: teslapy in ./lib/python3.10/site-packages (from pypowerwall) (2.9.0)
Requirement already satisfied: charset-normalizer<4,>=2 in ./lib/python3.10/site-packages (from requests->pypowerwall) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in ./lib/python3.10/site-packages (from requests->pypowerwall) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./lib/python3.10/site-packages (from requests->pypowerwall) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in ./lib/python3.10/site-packages (from requests->pypowerwall) (2024.6.2)
Requirement already satisfied: requests-oauthlib in ./lib/python3.10/site-packages (from teslapy->pypowerwall) (2.0.0)
Requirement already satisfied: websocket-client>=0.59.0 in ./lib/python3.10/site-packages (from teslapy->pypowerwall) (1.8.0)
Requirement already satisfied: oauthlib>=3.0.0 in ./lib/python3.10/site-packages (from requests-oauthlib->teslapy->pypowerwall) (3.2.2)
Thanks @ttl74ls100 - I can only replicate that if there is no route to the Gateway. I see where I need to adjust the code to help provide a clear message, but can you verify that you are able to ping / curl the Gateway (192.168.91.1) from that container host?
I believe the gateway is working. For example, after the patch to tedapi.py
in the tools folder, I am able get configuration a power data.
(jctest-env) /app/jctest-env # curl -k https://192.168.91.1
404 page not found
Could the issue be related to the 404 response?
I should also highlight I am connecting to a Powerwall 3
I should also highlight I am connecting to a Powerwall 3
@ttl74ls100 , I didn't expect this to work on the PW3! The fact that you got the first to work is a positive step. Thanks for helping test! 🙏
I updated the logic to give a bit more details to help diagnose:
# First install the dev version
pip install pypowerwall==0.10.3.dev0
# Run again
python3 -m pypowerwall.tedapi
# Run with debug
python3 -m pypowerwall.tedapi --debug
It worked.
(jctest-env) /app/jctest-env # python3 -m pypowerwall.tedapi
pyPowerwall - Powerwall Gateway TEDAPI Reader
- Connecting to https://192.168.91.1... SUCCESS
Enter Powerwall Gateway Password: <>
Connecting to Powerwall Gateway 192.168.91.1
- Configuration:
- Site Name: <>
- Battery Commission Date: 2024-01-31T15:36:12-05:00
- VIN: <>
- Number of Powerwalls: 2
- Power Data:
- Battery Charge: 49.32% (14210Wh of 28810Wh)
- Battery: 2058W
- Site: -5W
- Load: 3375W
- Solar: 1332W
- Solar_Rgm: 0W
- Generator: 0W
- Conductor: 0W
- Configuration and Status saved to config.json and status.json
Thanks for your help, Let me know if you need any PW3 testing.
Excellent! Thank you, @ttl74ls100 !
It seems that the PW3 responds with 404 for the /
URI which means we could use that to detect a PW3 and accommodate with some internal logic. Can you check to see if any of these work or the type of responses you get?
import pypowerwall
pypowerwall.set_debug()
# Set these
PW_HOST="192.168.91.1"
PW_GW_PWD="xxxxxxxx" # Your Gateway Password
pw = pypowerwall.Powerwall(PW_HOST, PW_GW_PWD ,gw_pwd=PW_GW_PWD)
# Get vitals - should work
pw.vitals()
# Get current power, level - likely will not work
pw.power()
pw.level()
# Get alerts - may partially work
pw.alerts()
pw.vitals()
DEBUG:Get Status from Powerwall
DEBUG:Starting new HTTPS connection (1): 192.168.91.1:443
DEBUG:https://192.168.91.1:443 "POST /tedapi/v1 HTTP/1.1" 200 1700
DEBUG:Response Code: 200
DEBUG:Status: {'control': {'alerts': {'active': ...
DEBUG:Get Configuration from Powerwall
DEBUG:Starting new HTTPS connection (1): 192.168.91.1:443
DEBUG:https://192.168.91.1:443 "POST /tedapi/v1 HTTP/1.1" 200 1310
DEBUG:Response Code: 200
DEBUG:Configuration: {'vin': '<>', 'meters': [{'location': 'site', 'type': 'synchrometerX', 'cts': [True, True, False, False] ...
{'VITALS': {'text': 'Device vitals generated from Tesla Powerwall Gateway TEDAPI', 'timestamp': 1717978179.1119115, 'gateway': '192.168.91.1', 'pyPowerwall': '0.10.3'},
...
pw.power()
DEBUG: -- local: Request Powerwall for /api/meters/aggregates
DEBUG:Starting new HTTPS connection (1): 192.168.91.1:443
DEBUG:https://192.168.91.1:443 "GET /api/meters/aggregates HTTP/1.1" 404 19
ERROR:404 Powerwall API not found at https://192.168.91.1/api/meters/aggregates
DEBUG:ERROR unable to parse payload 'None': 'NoneType' object is not subscriptable
{'site': 0.0, 'solar': 0.0, 'battery': 0.0, 'load': 0.0}
pw.level()
DEBUG: -- local: Request Powerwall for /api/system_status/soe
DEBUG:https://192.168.91.1:443 "GET /api/system_status/soe HTTP/1.1" 404 19
ERROR:404 Powerwall API not found at https://192.168.91.1/api/system_status/soe
pw.alerts()
DEBUG:Get Status from Powerwall
DEBUG:Starting new HTTPS connection (1): 192.168.91.1:443
DEBUG:https://192.168.91.1:443 "POST /tedapi/v1 HTTP/1.1" 200 1716
DEBUG:Response Code: 200
DEBUG:Status: {'control': {'alerts': {'active': ...
DEBUG:Using Cached Payload
DEBUG: -- local: Request Powerwall for /api/system_status/grid_status
DEBUG:https://192.168.91.1:443 "GET /api/system_status/grid_status HTTP/1.1" 404 19
ERROR:404 Powerwall API not found at https://192.168.91.1/api/system_status/grid_status
['SelfConsumptionReservedLimit', 'SystemConnectedToGrid', 'FWUpdateSucceeded']
Thanks, @ttl74ls100 ! This is very helpful. I suspected we would see 404 for those calls but needed to confirm. I can build mappings from the tedapi to most of those calls. I'll work on something for you to try soon.
Hi @ttl74ls100 - something for you to try:
# First install the dev version
pip install pypowerwall==0.10.4.dev0
Simple Python test:
import pypowerwall
PW_GW_PWD="GWPASSWD"
pw = pypowerwall.Powerwall("192.168.91.1", gw_pwd=PW_GW_PWD)
pw.power()
pw.level()
pw.battery_blocks()
You can also try the pypowerwall proxy:
docker run \
-p 8675:8675 \
-e PW_PORT='8675' \
-e PW_HOST='192.168.91.1' \
-e PW_GW_PWD="GWPASSWD" \
--name pypowerwall \
--restart unless-stopped \
jasonacox/pypowerwall:0.10.4t61-beta
Try these URLs:
All the calls executed without error. I can post results if you want, I am leaving them out for brevity in case the actual values are not relevant.
:tada:
Fantastic!!! Thanks for testing! 🙏
PS - if you want to test this with Powerwall-Dashboard, the manual steps:
1) Edit powerwall.yml
and replace the pypowerwall image with jasonacox/pypowerwall:0.10.4t61-beta
2) Edit pypowerwall.env
and ensure it has this:
#PW_EMAIL=
#PW_PASSWORD=
PW_HOST=192.168.91.1
PW_GW_PWD=GWPASSWD
3) Restart with ./compose-dash.sh up -d
Updated: the Powerwall-Dashboard will now provide an option to install for Powerwall 3 using the local gateway option. If you install and run setup.sh
it will walk you through the process (hopefully) :) .
I have a static route setup in the gateway/router (UniFi UDM) to the primary PW. The production Powerwall-Dashboard instance is running on a Proxmox VM and currently the curl -k https://192.168.91.1
test is timing out... Need to dig into the networking configs to see what is up there.
I am using WSL on a Windows machine for pypowerwall
to PW3 testing.
I'll stand-up another instance of Powerwall-Dashboard using local access and let you know how it goes.
Powerwall Dashboard is working with local PW3 w00t! Powerwall Capacity panel in Powerwall Vitals has no data. Energy Usage, Grid Status, Frequency, Voltages and Alerts working.
Looks great @ttl74ls100 !!
The Powerwall Capacity graph is puzzling. Can you show the results of http://localhost:8675/api/system_status ? It should have the capacity data. If it does check: http://localhost:8675/pod which is what the Dashboard is polling. It should list the different PW data points like PW2_POD_nom_full_pack_energy
.
/api/system_status
{
"command_source": "Configuration",
"battery_target_power": 0,
"battery_target_reactive_power": 0,
"nominal_full_pack_energy": 28840,
"nominal_energy_remaining": 10570,
"max_power_energy_remaining": 0,
"max_power_energy_to_be_charged": 0,
"max_charge_power": null,
"max_discharge_power": null,
"max_apparent_power": null,
"instantaneous_max_discharge_power": 0,
"instantaneous_max_charge_power": 0,
"instantaneous_max_apparent_power": 0,
"hardware_capability_charge_power": 0,
"hardware_capability_discharge_power": 0,
"grid_services_power": null,
"system_island_state": "SystemGridConnected",
"available_blocks": 0,
"available_charger_blocks": 0,
"battery_blocks": [],
"ffr_power_availability_high": 0,
"ffr_power_availability_low": 0,
"load_charge_constraint": 0,
"max_sustained_ramp_rate": 0,
"grid_faults": [],
"can_reboot": "Yes",
"smart_inv_delta_p": 0,
"smart_inv_delta_q": 0,
"last_toggle_timestamp": "2023-10-13T04:08:05.957195-07:00",
"solar_real_power_limit": null,
"score": 10000,
"blocks_controlled": 0,
"primary": true,
"auxiliary_load": 0,
"all_enable_lines_high": true,
"inverter_nominal_usable_power": 0,
"expected_energy_remaining": 0
}
/pod
{
"time_remaining_hours": 11.0975932293044,
"backup_reserve_percent": 33.5
}
Thanks @ttl74ls100 !
"battery_blocks": [],
Ugh, there is the problem. For previous Powerwalls, we have an entry there for each Powerwall. Can you look at http://localhost:8675/tedapi/status and see if you have entries for 'esCan' -> 'bus' -> 'THC'? That is what builds the battery_block data. I wonder if it is missing data or a code problem.
Also, the latest beta release I'm testing adds api locking which should help with overloading the /teadpi:
jasonacox/pypowerwall:0.10.5t61-beta8
It may also be good to see what you have in your logs:
docker logs pypowerwall
Status has a batteryBlocks
array:
"batteryBlocks": [
{
"din": "1707000-25-G--TG1232151234VR",
"disableReasons": null
},
{
"din": "1707000-25-G--TG1232151234RL",
"disableReasons": null
}
]
Here is esCan.bus.THC
:
"THC": [
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
},
{
"THC_InfoMsg": {
"THC_appGitHash": [0, 0, 0, 0, 0, 0, 0],
"isComplete": false,
"isMIA": true
},
"THC_Logging": {
"THC_LOG_PW_2_0_EnableLineState": "ENABLE_LINE_LOW"
},
"packagePartNumber": "",
"packageSerialNumber": ""
}
]
docker logs pypowerwall
06/13/2024 06:54:04 PM [proxy] [INFO] pyPowerwall [0.10.5] Proxy Server [t61] - HTTP Port 8675
06/13/2024 06:54:04 PM [proxy] [INFO] pyPowerwall Proxy Started
06/13/2024 06:54:04 PM [proxy] [INFO] pyPowerwall Proxy Server - Local Mode
06/13/2024 06:54:04 PM [proxy] [INFO] Connected to Energy Gateway 192.168.91.1 (JC)
06/13/2024 06:54:04 PM [proxy] [INFO] TEDAPI Mode Enabled for Device Vitals (full)
Thank you @ttl74ls100 - Sadly that is what I feared. The energy levels are not showing for Powerwall 3s. However, I can pull the aggregates and include them in the /pod API. Update to:
jasonacox/pypowerwall:0.10.5t62-beta
Edit the "Powerwall Capacity" graph you can add the total battery capacity and remaining metrics, you can create these queries:
If you have a chance to try it, let me know how it work. Thanks again for all your help!
Hi @ttl74ls100 - One thing we are missing for PW3 is the Firmware Version. It is not included in the TEDAPI payloads. Could you run this test for us? I suspect it is still a 404, but I would like to verify.
curl -ki https://192.168.91.1/api/status
If anyone else finds an API to get the firmware version of a PW3, let us us know.
404
404
Thanks @ttl74ls100 ! Bummer, but as I expected. I'll keep hunting... :)
Just throwing my hat into the ring here as well, I have 4 PW3's (1 leader, 3 followers) and a AC Coupled Solar (Enphase) system, if any different requests are of use. Also happy to setup a shell if you want to get access to poke about.
Thanks @welbymcroberts - There is also a discussion here where a new API has been found: https://github.com/jasonacox/Powerwall-Dashboard/discussions/392#discussioncomment-9864364
I'm traveling this week so limited on what I can explore but it does look promising if we can find a way to unlock it.
@welbymcroberts If you are interested in helping test, we are exploring a query that may give more PW3 data mentioned in the link above. You can test the script: https://github.com/jasonacox/pypowerwall/blob/main/tools/tedapi/ComponentsQuery.py (also requires downloading tedapi_pb2.py )
Hi @ttl74ls100 - One thing we are missing for PW3 is the Firmware Version. It is not included in the TEDAPI payloads. Could you run this test for us? I suspect it is still a 404, but I would like to verify.
curl -ki https://192.168.91.1/api/status
If anyone else finds an API to get the firmware version of a PW3, let us us know.
Found the PW3 firmware version! It is returned with the following pb (raw) request to /tedapi/v1.
1 { 1: 1 2 { 3: 1 } 3 { 1: "1707000-00-J--TG9999999999XP" } 4 { 2: "" } } 2 { 1: 1 }
Sample response.
1 {
1: 1
2 {
1: "1707000-00-J--TG9999999999XP"
}
3 {
3: 1
}
4 {
3 {
1 {
1: "1707000-00-J"
2: "TG9999999999XP"
}
2: "1707000-00-J--TG9999999999XP"
3 {
1: "24.12.6-PW3-AFCI 008bf6ff" <--- PW3 firmware version
2: "\000\213\366\...Redacted..."
}
5 {
2: 1
}
6: 4
7 {
1 {
1 {
1: "Quectel"
}
2 {
1: "BG95-M2"
}
3 {
1: "XMR2020BG95M2"
}
4 {
1: "10224A-2020BG95M2"
}
}
1 {
1 {
1: "Texas Instruments"
}
2 {
1: "WL18MODGI"
}
3 {
1: "Z64-WL18DBMOD"
}
4 {
1: "451I-WL18DBMOD"
}
}
}
8: "\370!s\306\212...Redacted..."
9: "\373U\353\322...Redacted..."
}
}
}
2 {
1: 1
}
This is awesome @geptto ! Thank you! 🙏
I created a test to get the firmware version:
git clone https://github.com/jasonacox/pypowerwall.git
cd pypowerwall/tools/tedapi
# or git pull if you have it already
python3 ComponentsQuery.py GW_PASSWD
My Powerwall 2/+ doesn't have some of the PW3 elements so I will be missing (404) some items, but I am getting the Firmware version:
Tesla Powerwall Gateway API Decoder
- Testing Connection to Powerwall Gateway...
- Using Powerwall Gateway Password: GATEWAY_PWD
- Fetching DIN from Powerwall...
- Connected: Powerwall Gateway DIN: 1232100-00-E--REDACTED
- Fetching Configuration from Powerwall...
- Config Written to config.json
- Battery Blocks:
- Battery Block: 2012170-25-E--REDACTED (SolarPowerwall)
- Battery Block: 3012170-05-B--REDACTED (ACPW)
- Fetching /tedapi/v1 PW3 Firmware from Powerwall (1232100-00-E--REDACTED)...
Response Code: 200
- Firmware Written to firmware.raw
Firmware version (len=15): 24.4.0 0fe780c9
- Fetching /tedapi/v1 PW3 ComponentsQuery from Powerwall (1232100-00-E--REDACTED)...
Response Code: 200
Payload (len=128): {"components":{"baggr":[],"bms":[],"hvp":[],"pch":[],"pws":[]},"pw3Can":{"firmwareUpdate":{"isUpdating":false,"progress":null}}}
- Components Written to components.json
- Fetching /tedapi/device/<din>/v1 PW3 ComponentsQuery from Powerwall (2012170-25-E--REDACTED SolarPowerwall)...
Response Code: 404
- No Components Found
- Fetching /tedapi/device/<din>/v1 PW3 ComponentsQuery from Powerwall (3012170-05-B--REDACTED ACPW)...
Response Code: 404
- No Components Found
https://github.com/jasonacox/pypowerwall/blob/706afaf5f042913c86637a28f78c78dd899bd889/tools/tedapi/tedapi.py#L111
Ubuntu, python3, Powerwall 3 x 2, using static route to PW
command line
python3 tedapi.py
Enter passwordResult:
Request returns 404, which is expected.
Added line with comment
# no exception, so the request was successful
and script ran successfully.