incub77 / solis2mqtt

Modbus RTU / RS485 to MQTT bridge for Solis Mini solar inverter.
GNU General Public License v3.0
53 stars 12 forks source link
ginlong homeassistant modbus mqtt raspberrypi rs485 solis

A MQTT bridge for Solis solar inverters.

Introduction

Solis solar inverters are equipped with an RS485 interface, through which telemetry values can be read and also control commands can be sent. The manufacturer offers LAN and WLAN sticks in combination with a software solution to access the interface. Unfortunately, this is always coupled with a connection to the manufacturer's cloud and integration into a home automation system is only possible in a detoured manner. This software acts as a bridge between the RS485 interface and a MQTT broker to allow easy integration into a home automation (with special support for Home Assistant), and furthermore without cloud constraints.

Hardware

  1. +5V
  2. GND
  3. DATA+
  4. DATA-

Installation

wget https://github.com/incub77/solis2mqtt/archive/main.tar.gz -O - | sudo tar -xvzf - --one-top-level=/opt/solis2mqtt --strip 1

sudo bash /opt/solis2mqtt/setup.sh

e.g. sudo vi /opt/solis2mqtt/config.yaml

sudo reboot

Usage

Solis2MQTT is intended to run as a system service. A log file is written to /opt/solis2mqtt/solis2mqtt.log. To control the service, the usual systemd commands are used:

To check if the service is running you can do a ps -efH | grep solis2mqtt. The output should look something like this:

solis2m+   460     1  0 22:53 ?        00:00:08   /usr/bin/python3 solis2mqtt.py -d
pi         559   501  0 23:13 pts/0    00:00:00           grep --color=auto solis2mqtt

If Solis2MQTT doesn't start up to a point where the log file is written you can check /var/log/syslog for clues.

For development/debugging Solis2MQTT can also be started directly. Make sure to change to the working directory before doing so.

cd /opt/solis2mqtt
python3 ./solis2mqtt.py

The following command line arguments are implemented:

Basic Configuration

Configuration is read from config.yaml, that has to contain at least these entries:

device: /dev/ttyUSB0
mqtt:
  url: hassio.local
  user: whoami
  passwd: secret

This is a complete config example:

device: /dev/ttyUSB0
slave_address: 1
poll_interval: 60
poll_interval_if_off: 600
inverter:
    name: solis2mqtt
    manufacturer: Ginlong Technologies
    model: solis2mqtt
mqtt:
    url: hassio.local
    port: 8883
    use_ssl: true
    validate_cert: true
    user: whoami
    passwd: secret

Inverter configuration

The file solis_modbus.yaml contains a list of entries, that describe the values to read from (and write to) the inverter.\ You can add your own entries if you want to read other metrics from the inverter. Especially if it comes to writing to the inverter - use at your own risk :-)\ This is an example of an entry:

- name: inverter_temp
  description: Inverter temperature
  unit: "°C"
  active: true
  modbus:
    register: 3041
    read_type: register
    function_code: 4
    number_of_decimals: 1
    signed: false
  homeassistant:
    device: sensor
    state_class: measurement
    device_class: temperature

The following options are available:

Special case for datetime

As the datetime information is stored in several registers, there is a special read_type to read this as one ISO datetime string.

- name: system_datetime
  description: System DateTime
  unit:
  active: true
  modbus:
    register: [3072, 3073, 3074, 3075, 3076, 3077] # [year, month, day, hour, minute, seconds]
    read_type: composed_datetime
    function_code: 4
  homeassistant:
    device: sensor
    state_class:
    device_class: timestamp

Screenshots

MQTT Explorer

Home Assistant