This is a TypeScript/PostgreSQL version of Powerwall2PVOutput, written partially for learning and also because I found the SQLite file from that repository kept getting corrupted.
The application requires a file called config.json
in the root level of the repository with the following contents:
{
"database": {
"host": "localhost",
"port": 5432,
"user": "username",
"password": "password",
"database": "pvoutput"
},
"timezone": "Australia/Sydney",
"powerwallUrl": "https://powerwall",
"powerwallEmail": "[email protected]",
"powerwallPassword": "local-powerwall-api-password",
"pvoApiKey": "abc123",
"pvoSystemId": "12345",
"sendExtendedData": true
}
- The
powerwallEmail
andpowerwallPassword
fields are required since Powerwall 2 firmware version 20.49.0. If you don't have them set already, follow the instructions on Tesla's site to configure them. - The
timezone
option can be omitted if the script is running natively on your machine rather than inside a Docker container (inside a Docker container, the timezone is always UTC which will throw off the times it's sending to PVOutput). - The
pvoApiKey
can be generated in account settings at PVOutput, and thepvoSystemId
is listed under Registered Systems on the same page. - If
sendExtendedData
is set tofalse
, only solar generation, home consumption, and solar voltage will be sent.
To send extended data to PVOutput, you need a PVOutput account with an active donation and the sendExtendedData
option in config.json
set to true
. To set up the extended data, use the following setup on your Edit System page on PVOutput:
- To run it in a Docker container, start it with
docker-compose up -d
. If the image doesn't exist, it will be built. If you need to build it again after pulling new changes from this repository, rundocker-compose build
beforedocker-compose up -d
. - To run it locally on your machine, compile it with
npm run build
, prepare the database withnpm run db:migrate
and start it withnpm start
, then use something like PM2 or Forever to keep it up.
To enable debug logging to see what's going on under the covers, set the DEBUG
environment variable to true
.
You can optionally add the following to your config.json
to enable sending of the Powerwall data to a local MQTT broker:
{
[...]
"mqtt": {
"host": "localhost",
"port": 1883,
"topic": "home/power"
}
}
The port
field is optional and defaults to 1883 if not specified. It will publish data to the specified topic in a similar fashion to what's sent to PVOutput:
{
"timestamp": number,
"solar_generation": number,
"solar_voltage": number,
"home_usage": number,
"home_voltage": number,
"grid_flow": number,
"battery_flow": number,
"battery_charge_percentage": number
}