netzero-labs / tesla-solar-download

Download Tesla solar data using the API
Apache License 2.0
17 stars 3 forks source link

Fails for the scenario with multiple installations including older solarcity ones #3

Closed bparruck closed 11 months ago

bparruck commented 11 months ago

I get this error while running Downloading energy data for solar site ***9431 to download/energy/ Traceback (most recent call last): File "./tesla_solar_download.py", line 274, in main() File "./tesla_solar_download.py", line 263, in main _download_energy_data(tesla, site_id, debug=args.debug) File "./tesla_solar_download.py", line 93, in _download_energy_data timezone = site_config['installation_time_zone'] KeyError: 'installation_time_zone'

zigam commented 11 months ago

Thanks for the report, I just pushed a change that will deduce the timezone from installation_date if installation_time_zone is not available.

Please pull and give it another try.

bparruck commented 11 months ago

I'm still getting another error: Traceback (most recent call last): File "./tesla_solar_download.py", line 289, in main() File "./tesla_solar_download.py", line 285, in main _download_power_data(tesla, site_id, debug=args.debug) File "./tesla_solar_download.py", line 229, in _download_power_data _download_power_day(tesla, site_id, timezone, date, partial_day=partial_day) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/retry/api.py", line 74, in retry_decorator logger) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/retry/api.py", line 33, in __retry_internal return f() File "./tesla_solar_download.py", line 207, in _download_power_day _write_power_csv(response['time_series'], date, site_id, partial_day=partial_day) File "./tesla_solar_download.py", line 163, in _write_power_csv raise ValueError(f'No timeseries for {date}') ValueError: No timeseries for 2023-09-10 00:00:00-07:00

What's happening is that it is pulling my older Solarcity install which doesn't have the timezone definition. However, because of th failure it is not pulling the second site, which is the Tesla installation. If I manually set the siteid to be Tesla site, it works.

zigam commented 11 months ago

Does it download any data for the older install? I pushed a change to keep going when there's an exception, so I'm curious if it's just some days that are missing data, or if there's a broader issue. Please try with this new version and if no data is downloaded I'll add some more debug logging so figure out how the data is different for the older install.

Thanks for your help in debugging this!

bparruck commented 11 months ago

Yes, it was downloading but bailing out on the error. It should work, unfortunately it has a different problem: File "./tesla_solar_download.py", line 51 return f'download/{site_id}/energy/{str_date}{suffix}' ^ SyntaxError: invalid syntax

I should have some time tomorrow to debug it.

zigam commented 11 months ago

return f'download/{site_id}/energy/{str_date}{suffix}' ^ SyntaxError: invalid syntax

This looks like you might be running an older python version, can you try upgrading to 3.8 or later?

bparruck commented 11 months ago

Look at this: python --version Python 2.7.14

python3 --version Python 3.7.3

My MacBook Pro uses python3 for newer version and keeps older python 2.7 around. I'll try later with python3.

bparruck commented 11 months ago

@zigam It now runs, ignoring them missing data: 2023-06-03.csv Traceback (most recent call last): File "./tesla_solar_download.py", line 234, in _download_power_data _download_power_day(tesla, site_id, timezone, date, partial_day=partial_day) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/retry/api.py", line 74, in retry_decorator logger) File "/Users/bparruck/code/tesla-solar-download/venv/lib/python3.7/site-packages/retry/api.py", line 33, in __retry_internal return f() File "./tesla_solar_download.py", line 211, in _download_power_day _write_power_csv(response['time_series'], date, site_id, partial_day=partial_day) File "./tesla_solar_download.py", line 167, in _write_power_csv raise ValueError(f'No timeseries for {date}') ValueError: No timeseries for 2023-06-03 00:00:00-07:00

It would be good if it just showed the warning "No timeseries for 2023-06-03 00:00:00-07:00" instead of the entire stack.

Also, perhaps you can clarify the installation documentation.

For installations where python refers to Python 2.7, use the following: python3 -m venv venv source venv/bin/activate pip3 install --upgrade pip pip3 install -r requirements.txt python3 ./tesla_solar_download.py --email my_tesla_email@gmail.com

zigam commented 11 months ago

Thanks, I updated the readme. Virtualenv usually updates the python path to make sure python3 is used, but it doesn't harm to be explicit.