Git Product home page Git Product logo

powerwall2pvoutput's Introduction

Powerwall2PVOutput

Send Tesla Powerwall 2 data to PVOutput

Note code has been updated to work with basic auth, firmware versions 20.49.0+

2 options
-Datalogger - Collects data on site and then send to PVO, allowing for internet outages or PVO outages
-Simple - No data collection, simply picks up the data and sends

Datalogger

2 processes
-PW_Datalogger - Hits your Powerwall 2 every 5 seconds and stores the data in a sqlite db.
-PW_PVOExport - Designed to be run every N minutes by a scheduler (e.g. Cron) will get your last update from PVOutput and send any outstanding data to it.
This can be run in 2 modes, either sending extended data or not. Just set the extData variable to False if you do not want the extended data sent.

Simple

For those people who do not care about losing solar data due to internet outages etc. I have created a simple script called
PW_Simple, this is designed to run all the time, will collect PW data every 5 seconds and send an average every 5 minutes.
This can also be run in 2 modes, either sending extended data or not. Just set the extData variable to False if you do not want the extended data sent.

If sending extended data, you will need a paid account in PVO for this to work properly

PVO Setup for extended data:

alt text alt text

powerwall2pvoutput's People

Contributors

aanker avatar ekul135 avatar fracai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerwall2pvoutput's Issues

Stormwatch mode consumption issue

storm watch mode activated for the first time for me today. i guess because under normal circumstances the PW can only charge from solar, the home load is the correct value to report as consumption to PVO.

however, if the battery charges from the grid, that energy just "disappears". to fix this, i think this script would need logic to add the battery flow to the reported consumption data when the battery flow is negative and exceeds the solar+home load value. here are some screenshots from my system running Powerwall2PVOutput, plus a screenshot from a dummy system i made to track net consumption. you can see that there's a huge load early in the morning that does not appear in the PW2PVO system, except on the extended data page.

Screen Shot 2020-12-06 at 10 52 07 AM

Screen Shot 2020-12-06 at 10 52 15 AM

Screen Shot 2020-12-06 at 10 52 27 AM

Database locked messages

Getting a number of database locked messages from PW_PVOExport. Data appears to be saved in the database, though.

Snippet from pvo.log:
2018-03-31 14:35:01,572 - Start PVOutput export
2018-03-31 14:35:11,347 - insertdb: database is locked
2018-03-31 14:35:21,410 - insertdb: database is locked
2018-03-31 14:35:31,468 - insertdb: database is locked
2018-03-31 14:35:41,536 - insertdb: database is locked
2018-03-31 14:35:49,687 - Date: 20180331, Time: 14:35, Watts: 3734.56, Load Power: 366.66, SOC: 100.0, Site Power: -3366.01, Load Voltage: 248.91, Battery Flow: -2.67, Temp: 0.0, Solar Voltage: 248.93, Consumption: 366.66
2018-03-31 14:35:49,690 - End PVOutput export
2018-03-31 14:40:02,029 - Start PVOutput export
2018-03-31 14:40:09,323 - insertdb: database is locked
2018-03-31 14:40:19,382 - insertdb: database is locked
2018-03-31 14:40:29,478 - insertdb: database is locked
2018-03-31 14:40:39,541 - insertdb: database is locked
2018-03-31 14:40:50,089 - Date: 20180331, Time: 14:40, Watts: 4041.13, Load Power: 876.43, SOC: 100.0, Site Power: -3167.61, Load Voltage: 248.86, Battery Flow: -2.33, Temp: 0.0, Solar Voltage: 248.87, Consumption: 876.43
2018-03-31 14:40:50,146 - End PVOutput export

Not reporting to PVOutput

Logger is running

root@piaware-dayna:~/Powerwall2PVOutput-master# ps -auxwww | grep PW
root 14356 0.7 1.7 20332 13252 pts/0 S 19:31 0:32 python /root/Powerwall2PVOutput-master/PW_Datalogger.py

Crontab is installed
root@piaware-dayna:/Powerwall2PVOutput-master# crontab -l | grep PW
*/5 * * * * python /root/Powerwall2PVOutput-master/PW_PVOExport.py
root@piaware-dayna:
/Powerwall2PVOutput-master#

root@piaware-dayna:/Powerwall2PVOutput-master# tail pvo.log
2018-05-24 19:30:13,161 - Start PVOutput datalogger
2018-05-24 19:31:00,815 - Start PVOutput datalogger
2018-05-24 20:26:23,400 - Start PVOutput export
2018-05-24 20:26:24,224 - No data returned
2018-05-24 20:26:24,229 - End PVOutput export
2018-05-24 20:27:47,693 - Start PVOutput export
2018-05-24 20:27:48,235 - No data returned
2018-05-24 20:27:48,241 - End PVOutput export
root@piaware-dayna:
/Powerwall2PVOutput-master#

Yet nothing showing up

root@piaware-dayna:~/Powerwall2PVOutput-master# cat PW_Config.py
#!/usr/bin/env python
pvo_host= "pvoutput.org"
pvo_key = "XYZ"
pvo_systemid = "55404"
PowerwallIP = "192.168.33.5"
extData = True
log_file = "pvo.log"

#only needed if using datalogger
sqlite_file = "pw.sqlite"
retain_days = "30" #days to retain data in db, use 0 to not delete

Any ideas?

Authentication token required since Powerwall 2 firmware version 20.49.0

Hi,

Great code. I have been using this code for a while on a Raspberry Pi.
It seems the an authentication token is required since Powerwall 2 firmware version 20.49.0.
Since the upgrade we cannot get the data to the pvoutput.org.
I would really appreciate if you could have a look, I have not been able to find any other half decent code that run on linux (Pi) and can upload to pvoutput.org. Sorry my coding skills are lacking to solve this bug.

curl -s -k https://powerwall/api/meters/aggregates |jq
{
"code": 403,
"error": "Unable to GET to resource",
"message": "User does not have adequate access rights"
}

Using an example from web

curl -s -k -i -c /home/pi/cookie.txt -X POST -H "Content-Type: application/json" -d '{"username":"customer","password":"<pw_password>", "email":"[email protected]","force_sm_off":false}' "https://powerwall/api/login/Basic"

HTTP/2 200
set-cookie: AuthCookie=5ugIDkXG6TjmsX6A39iprX7RVoRU8eFjcGxJS8rxcDpYP7XThgQW8NtXaxKySGnCwT_8XySv9WULlYAIt-jJNQ==; Path=/
set-cookie: UserRecord=eyJlbWFpbCI6ImplYW4uZHVtaW55QGdtYWlsLmNvbSIsImZpcnN0bmFtZSI6IlRlc2xhIiwibGFzdG5hbWUiOiJFbmVyZ3kiLCJyb2xlcyI6WyJIb21lX093bmVyIl0sInRva2VuIjoiNXVnSURrWEc2VGptc1g2QTM5aXByWDdSVm9SVThlRmpjR3hKUzhyeGNEcFlQN1hUaGdRVzhOdFhheEt5U0duQ3dUXzhYeVN2OVdVTGxZQUl0LWpKTlE9PSIsInByb3ZpZGVyIjoiQmFzaWMiLCJsb2dpblRpbWUiOiIyMDIxLTAyLTE3VDExOjIwOjA3LjEzMzA0MDUzNSsxMTowMCJ9; Path=/
content-type: text/plain; charset=utf-8
content-length: 264
date: Wed, 17 Feb 2021 00:20:07 GMT

{"email":"[email protected]","firstname":"Tesla","lastname":"Energy","roles":["Home_Owner"],"token":"5ugIDkXG6TjmsX6A39iprX7RVoRU8eFjcGxJS8rxcDpYP7XThgQW8NtXaxKySGnCwT_8XySv9WULlYAIt-jJNQ==","provider":"Basic","loginTime":"2021-02-17T11:20:07.133040535+11:00"}

This guy used your code and ported to a different db. This is his authentication to fix the issue

VirtualWolf/powerwall-to-pvoutput-uploader@42118bb

Much appreciate Jean

Python2 or Python3

I appreciate the updates to this script. I am getting errors but I think they may be related to the version of Python. Are these scripts Python2 or Python3 dependent? Thanks in advance!

new version 21.20.2 causing issues

My implementation stops sending data to pvoutput.org after about an hour after restart, because of the following errors:

2021-07-02 16:03:48,802 - getPowerwallData: HTTPSConnectionPool(host='192.168.178.60', port=443): Max retries exceeded with
url: /api/meters/aggregates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fded79
44190>: Failed to establish a new connection: [Errno 113] No route to host'))
2021-07-02 16:03:51,874 - getPowerwallSOCData: HTTPSConnectionPool(host='192.168.178.60', port=443): Max retries exceeded w
ith url: /api/system_status/soe (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fde
d7976220>: Failed to establish a new connection: [Errno 113] No route to host'))
2021-07-02 16:03:51,875 - No data received, retrying

[ERROR] object of type 'bool' has no len()

Hello,

I am struggling with the below error trying to run from cron. I am out of practice with Linux commands and cold use some help. I get the following error when trying to run PW_PVOExport.py from cron. I have tried to ran as local user and root. I am able to run form command line python PW_PVOExport.py and have successful uploaded PW2EG. I am running this form a NetGear ReadyNAS system.

Version
PowerWall 1.17.2
Python 2.7.9 (default, Aug 13 2016, 17:33:18) [GCC 4.9.2]
Linux 4.4.116.armada.1

Changes PW_Helper.py
Disable the HTTPS to HTTP From https://'+PowerwallIP+'/api/meters/aggregates to http://'+PowerwallIP+'/api/meters/aggregates as my Powerwall does not answer to HTTPS

ERROR

2018-08-05 14:04:02,232 - Start PVOutput export
2018-08-05 14:04:03,328 - get_sqlite_data: no such table: View_pw
2018-08-05 14:04:03,455 - [ERROR] object of type 'bool' has no len()
2018-08-05 14:04:03,460 - delete_sqlite_data: no such table: pw
2018-08-05 14:04:03,489 - End PVOutput export

crontab configuraiton

* * * * * /usr/bin/python /home/user/path/PW_PVOExport.py >/home/user/path/err.log 2>&1

Noticed that the directory above /home/user/path/ two additional files get created pvo.log & pw.sqlite the Working Directory has these files and being populated with data as I see the pw.sqlite being populated .

Additional Files

.
├── [4.0K]  Powerwall2PVOutput (Working Directory)
├── [9.4K]  pvo.log
├── [4.0K]  pw.sqlite

Working Directory

.
├── [4.0K]  Powerwall2PVOutput
│   ├── [4.0K]  BAK
│   │   ├── [ 311]  PW_Config.py
│   │   ├── [1.1K]  PW_Datalogger.py
│   │   ├── [5.4K]  PW_Helper.py
│   │   ├── [2.2K]  PW_PVOExport.py
│   │   └── [3.0K]  PW_Simple.py
│   ├── [9.4K]  err.log
│   ├── [ 60K]  ExtendedData7_8.png
│   ├── [ 95K]  ExtendedData9_12.png
│   ├── [ 22K]  pvo.log
│   ├── [ 311]  PW_Config.py
│   ├── [ 432]  PW_Config.pyc
│   ├── [1.1K]  PW_Datalogger.py
│   ├── [5.4K]  PW_Helper.py
│   ├── [6.3K]  PW_Helper.pyc
│   ├── [2.3K]  PW_PVOExport.py
│   ├── [3.0K]  PW_Simple.py
│   ├── [859K]  pw.sqlite
│   ├── [4.0K]  pyc
│   │   ├── [ 439]  PW_Config.pyc
│   │   └── [6.4K]  PW_Helper.pyc
│   └── [1.4K]  README.md

Thanks,

RN

Incorrect values

Do i need to perform any setup in the PVoutput page? (In addition to extended values)

My consumption and solar generation and export and import values are incorrect.

SSL Certificate Verification failed - Firmware 1.19.0

My powerwall2 was recently upgraded to firmware 1.19.0. After the upgrade, Powerwall2PVOutput could no longer export data from my PW2 due to SSL issues. Here's the error message:

2018-06-19 23:15:42,334 - getPowerwallData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

I managed to get it working again by using the following environment variable to disable the HTTPS verification check before running PW_DataLogger and PW_PVOExport:
PYTHONHTTPSVERIFY=0

It's a work around for now.

Assistance for a newby getting things running in Ubantu 14.04

I have unzipped download into a folder Powerwall2PVOutput in my Documents folder.
I then edited the PW_Config putting in the key, system ID and IP address of the Gateway.
I then used cd to get the files and used the command python PW_Datalogger.py in terminal. This shows the line "2018-10-18 15:33:09,572 Start PVOutput datalogger"
I the edited my crontab file adding the line
"*/5 * * * * python ~/Documents/Powerwall2PVOutput/PW_PVOExport.py >/dev/null2>&1"
hopefully to upload the data every 5 minutes.
Nothing seems to be happening!!! Any help would be greatly appreciated.

PW-PVExport

Hello,

I got this error when I try to start

Bad request 400: Invalid power value [-399]
I got a Powerwall 2 and more then 5Kw solar.

Kind regards,

Leo

MySQL Request

I would like to convert your script to use MySQL (or MariaDB) instead of SQLite. Your script works very well but I would like to save my data locally and use Grafana for data visualization. I figured out how to export the data from SQLite but the resulting SQL cannot be imported into MySQL due to syntax changes.

I was successful in getting the PW table and data into MySQL but I am really struggling converting the SQLite View-pw. This view would be more useful when using Grafana since it would have the 5 minute average data. There are many functions in the SQLite View_pw SQL that I am really struggling translating to MySQL syntax.

Any help, assistance or guidance is appreciated. Many thanks in advance. :)

Unable to export using PVOExport

I am successfully logging the data to the database.

When running PW_PVOExport.py, the script launches but errors with:
2018-07-01 16:08:38,925 - Start PVOutput export
2018-07-01 16:08:39,053 - [ERROR] Unauthorized 401: Missing, invalid or inactive api key information (X-Pvoutput-Apikey)
2018-07-01 16:08:39,062 - End PVOutput export

I have triple checked the system ID and API api. I have also generated a new API key. None have worked. Any suggestions? Thanks in advance.

PVOutput daily import/export are not matching powerwall grid daily numbers

I've setup Powerwall2PVOutput to get the data from powerwall and push them to pvoutput. But when I compare the aggregate daily numbers in pvoutput for the import and export, I see a large difference with what Powerwall app shows From/To Grid. This causes a large difference in the monthly net numbers as well.

Cronjob not updating PVO

If i run locally its fine...
root@piaware-dayna:~/Powerwall2PVOutput-master# /usr/bin/python2.7 /root/Powerwall2PVOutput-master/PW_PVOExport.py
2018-05-25 10:34:09,897 - Start PVOutput export
2018-05-25 10:34:11,261 - Date: 20180525 Time: 10:30 Watts: 1658.87 Load Power: 4172.88 SOC: 9.86 Site Power: 2514.72 Load Voltage: 236.03 Battery Flow: -0.34 Temp: 0.0 Solar Voltage: 236.02
2018-05-25 10:34:11,718 - Date: 20180525 Time: 10:35 Watts: 2237.39 Load Power: 4473.08 SOC: 9.86 Site Power: 2235.47 Load Voltage: 236.32 Battery Flow: 0.0 Temp: 0.0 Solar Voltage: 236.31
2018-05-25 10:34:11,734 - End PVOutput export

When running from cron, it sees the cron running, but obviously isn't referencing the file paths or something?

2018-05-24 21:50:01,822 - Start PVOutput export
2018-05-24 21:50:02,621 - No data returned
2018-05-24 21:50:02,626 - End PVOutput export
2018-05-24 21:55:02,161 - Start PVOutput export
2018-05-24 21:55:02,931 - No data returned
2018-05-24 21:55:02,937 - End PVOutput export
2018-05-24 22:00:01,489 - Start PVOutput export
2018-05-24 22:00:02,322 - No data returned
2018-05-24 22:00:02,329 - End PVOutput export
2018-05-24 22:05:01,875 - Start PVOutput export
2018-05-24 22:05:02,703 - No data returned
2018-05-24 22:05:02,709 - End PVOutput export
2018-05-24 22:10:02,240 - Start PVOutput export
2018-05-24 22:10:03,024 - No data returned

I even tried to make a bash script
*/5 * * * * /root/Powerwall2PVOutput-master/run.sh

root@piaware-dayna:~/Powerwall2PVOutput-master# cat run.sh
cd /root/Powerwall2PVOutput-master
/usr/bin/python2.7 /root/Powerwall2PVOutput-master/PW_PVOExport.py

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.