Sunned - A PVS Poller Script
This is a Python script that I used to poll the SunPower PVS6 to get data from the panels. It will then take this data polled, insert it into a database and can output the data into CSV files.
Note: This script does not get PAST history from SunPower. It can only save the data the is returned from polling the PVS.
- Gather JSON from the local PVS API (/cgi-bin/dl_cgi?Command=DeviceList), parse it by device, and then insert into a target DB to get history
- You can then use this DB with visualization tools like Grafana.
- Export the data into CSV files based on SQL queries in a given folder
- For those that like using CSV files and want to see the history without needing to query their DB
python Sunned.py --config ./config/config.ini
- Proxy setup to your PVS on your local network (https://github.com/MrStrabo/PVS5-6_Reverse_Proxy_Guide)
- Python 3.11+
- SQLite3 / PostreSQL 17
-
If you haven't already, install Python 3.11+.
-
Once complete, run the following to set up packages
pip install -r requirements.txt -
DB Setup
- By default, the script will create a sqlite3 database to use for itself.
- If you already have a postgreSQL database...
- Run ./config/create-solar_generation.sql to create the necessary table the script will be using.
- Be sure to grant the appropriate rights to the user you want the script to use
-
Modify the config file (./config/config.ini)
- DB_CONFIG section
- connection_string - connection string of DB to use. You can leave this alone for sqlite3.
- username - username to use for connecting to DB (PostgreSQL only)
- password - password to use for connecting to DB (PostgreSQL only)
- API_CONFIG section
- api_hostname - The IP address/hostname that is used to call the PVS api. This is the proxy that was setup or the wifi hotspot ip address.
- api_port - The port that is used to call the PVS api.
- deviceList_endpoint - The "famous" deviceList api call. Leave alone, but I left this configurable in case you have this pointed to something else
- POLLER_CONFIG section
- timezone - timezone that you want the reporting timestamps to use. Defaults to EST. For values to use, refer to the "TZ Identifiers" this list.
- output_response_to_console - set true if you want the script to output the api response to console
- output_response_to_file - set true to output api response to a file (will be yyyymmdd-hhmmss.json in root)
- export_sql_queries_results_to_file - set true to output results from sql queries in ./sqlQueries to a csv file
- sql_query_folder - directory where sql queries to run are located
- export_sql_query_results_folder - director to export sql query results
- DB_CONFIG section
If you are using sqlite3, all the solar data will be saved to the pvs_metrics.db file in the root folder.
You will want to backup this file as it will hold the data everytime you run this script.