A Python script to read memory register(s) from Sol-Ark Inverters and insert them into a database.
This script was written in order to maintain local control of your Sol-Ark Inverter.
It is known to work with Model Sol-Ark 12k-P, COMM 142a-0717, MCU Ver6983.
-
Your Sol-Ark Inverter likely came with a Wi-Fi dongle that allows for remote monitoring, troubleshooting and software updates of your inverter. I have a few issues with Sol-Ark's implementation of these remote capabilities:
- The Wi-Fi dongle allows for unprotected access via HTTP. Any individual on the same Wi-Fi network can alter the firmware of the dongle, change its Wi-Fi AP association, use it to scan for nearby access points and who knows what else. I prefer to unplug it unless in need of support, but I'd also like to monitor my inverter's activity without standing in front of it too.
- The same data I'm collecting via MODBUS protocol from the inverter is being sent overseas to China. I prefer my data not be collected by unknown parties in a different country.**
- The application/website (PowerView) used by Sol-Ark is also developed and maintained in China. This application allows you to remotely alter the configuration of your inverter. This same application also allows anyone to view the Operational Data of other Customers simply by providing their serial number, so I don't trust the possibility that a determined individual with the correct scripting skills may not be able to alter the configuration of my inverter without my knowledge OR consent.**
** Sol-Ark allegedly moved their remote capabilities to the United States. Browse diysolarforum.com for details.
-
Other vendors already have well-established products in this space. Victron Energy's Venu OS and Solar Assistant come to mind. But I want a database with my own data to play with. I also like to build my own dashboards and home automation/monitoring solutions.
-
Because I can. I enjoy writing code and learning new technology.
- I'm only working with Read-Only memory registers here.
- solar_modbus. 8D6E py was created to contain what I knew about the Sol-Ark's memory registers; I later included the range values as a sanity check. (What I previously thought were incorrect values by my inverter were actually being decoded incorrectly.)
- MySQL: I went with what I know. I would have liked to try a time-series database (like InfluxDB). Perhaps in a new release?
- Script variables are picked up from the environment (see config.py).
- I have a Raspberry Pi connected to my inverter.
- I use mbusd to make the Modbus details available
via TCP so they can be consumed by multiple sources.
- HA-solark-PV Home Assistant integration collects Modbus details via TCP.
- This script, which runs on another VM collects Modbus data and inserts it into a database.
- You could just as easily run this script on the PC connected to your Inverter without the need to make the inverter's Modbus details available via TCP. I just prefer all my solutions to be over-engineered. :)
- A computer located near your inverter to make the Modbus calls to the inverter. (I'm using a Raspberry Pi 3 Model B v1.2.)
- Python v3.11+
- Python's Poetry package manager
- A specially-crafted cable to connect your computer to your inverter. The MODBUS/RJ45 Application Note in your manual has some info. I'm using a JBtek USB to RS485 Converter Adapter as mentioned by Solardad's first post in this thread on the Solar DIY Forums.
- See pyproject.toml
- Install Poetry
- Clone the repository:
git clone https://github.com/aaronmelton/solark_monitor.git
- Change directory into the newly cloned repository:
cd solark_monitor
- Invoke Poetry shell:
poetry shell
- Install Python dependencies:
poetry update
- Test run script:
python3 solark_monitor.py solark --help
- Set the following environment variables (or modify
config.py
to hard-code them):- SOLARK_INV_HOSTNAME: Hostname or IP Address of the device providing RTU data.
- SOLARK_DB_HOSTNAME: Hostname or IP Address of the database server.
- SOLARK_DB_USERNAME: Database username with write permissions.
- SOLARK_DB_PASSWORD: Database username's password
- SOLARK_DB_SCHEMA: Name of the database schema.
- SOLARK_DB_TABLE: Name of the database table.
- If you encounter an issue installing the Python mysqlclient library, visit the library project for more information.
python3 solark_monitor.py solark --help
for help.
python3 solark_monitor.py solark --pull --serial
to pull Modbus values via Serial and display to screen.
python3 solark_monitor.py solark --pull --tcp
to pull Modbus values via TCP and display to screen.
python3 solark_monitor.py solark --pullpush --serial
to pull Modbus values via Serial and store them in a database.
python3 solark_monitor.py solark --pullpush --tcp
to pull Modbus values via TCP and store them in a database.
- Solardad's Sol-Ark - Inverter Monitoring thread on DIY Solar Power Forum.
- offthehook for sharing his code illustrating how to read memory registers via pymodbus.
- Borrowed some techniques from Home Assistant integration for the SolArk PV Inverter.
- Aaron Melton - Author - Aaron Melton aaron@aaronmelton.com