Stefan Allius 03aa0c5747 adapt tests
2023-10-15 23:13:43 +02:00
2023-10-15 23:13:43 +02:00
2023-10-12 22:39:24 +02:00
2023-10-12 22:39:24 +02:00
2023-10-15 15:50:20 +02:00
2023-09-25 20:29:37 +02:00
2023-09-25 21:39:01 +02:00
2023-09-24 21:54:37 +02:00
2023-10-10 21:54:12 +02:00
2023-09-25 23:31:20 +02:00

TSUN-Gen3-Proxy

A proxy for

TSUN Gen 3 Micro-Inverters

for easy

MQTT/Home-Assistant

integration

License: BSD-3-Clause Supported Python versions Supported aiomqtt versions Supported toml versions

Overview

This proxy enables a reliable connection between TSUN third generation inverters and an MQTT broker. With the proxy, you can easily retrieve real-time values such as power, current and daily energy and integrate the inverter into typical home automations. This works even without an internet connection. The optional connection to the TSUN Cloud can be disabled!

In detail, the inverter establishes a TCP connection to the TSUN cloud to transmit current measured values every 300 seconds. To be able to forward the measurement data to an MQTT broker, the proxy must be looped into this TCP connection.

Through this, the inverter then establishes a connection to the proxy and the proxy establishes another connection to the TSUN Cloud. The transmitted data is interpreted by the proxy and then passed on to both the TSUN Cloud and the MQTT broker. The connection to the TSUN Cloud is optional and can be switched off in the configuration (default is on). Then no more data is sent to the Internet, but no more remote updates of firmware and operating parameters (e.g. rated power, grid parameters) are possible.

By means of docker a simple installation and operation is possible. By using docker-composer, a complete stack of proxy, MQTT-brocker and home-assistant can be started easily.

This project is not related to the company TSUN. It is a private initiative that aims to connect TSUN inverters with an MQTT broker. There is no support and no warranty from TSUN.

❗An essential requirement is that the proxy can be looped into the connection
between the inverter and TSUN Cloud.

There are various ways to do this, for example via an DNS host entry or via firewall
rules (iptables) in your router. However, depending on the circumstances, not all
of them are possible.

If you use a Pi-hole, you can also store the host entry in the Pi-hole.

Features

  • MQTT support
  • Home-Assistant auto-discovery support
  • Self-sufficient island operation without internet
  • non-root Docker Container

Requirements

  • A running Docker engine to host the container
  • Ability to loop the proxy into the connection between the inverter and the TSUN cloud

Getting Started

To run the proxy, you first need to create the image. You can do this quite simply as follows:

docker build https://github.com/s-allius/tsun-gen3-proxy.git#main:app -t tsun-proxy

after that you can run the image:

docker run  --dns '8.8.8.8' --env 'UID=1000' -p '5005:5005'  -v ./config:/home/tsun-proxy/config -v ./log:/home/tsun-proxy/log tsun-proxy

You will surely see a message that the configuration file was not found. So that we can create this without admin rights, the uid must still be adapted. To do this, simply stop the proxy with ctrl-c and use the id command to determine your own UserId:

% id 
uid=1050(sallius) gid=20(staff) ...

With this information we can customize the `docker run`` statement:

docker run  --dns '8.8.8.8' --env 'UID=1050' -p '5005:5005'  -v ./config:/home/tsun-proxy/config -v ./log:/home/tsun-proxy/log tsun-proxy

Configuration

The Docker container does not require any special configuration. On the host, two directories (for log files and for config files) must be mapped. If necessary, the UID of the proxy process can be adjusted, which is also the owner of the log and configuration files.

The proxy can be configured via the file 'config.toml'. When the proxy is started, a file 'config.example.toml' is copied into the config directory. This file shows all possible parameters and their default values. Changes in the example file itself are not evaluated. To configure the proxy, the config.example.toml file should be renamed to config.toml. After that the corresponding values can be adjusted. To load the new configuration, the proxy must be restarted.

Proxy Configuration

The configration uses the TOML format, which aims to be easy to read due to obvious semantics. You find more details here: https://toml.io/en/v1.0.0

# configuration to reach tsun cloud
tsun.enabled = true   # false: disables connecting to the tsun cloud, and avoids updates
tsun.host    = 'logger.talent-monitoring.com'
tsun.port    = 5005


# mqtt broker configuration
mqtt.host    = 'mqtt'   # URL or IP address of the mqtt broker
mqtt.port    = 1883
mqtt.user    = ''
mqtt.passwd  = ''


# home-assistant
ha.auto_conf_prefix = 'homeassistant'       # MQTT prefix for subscribing for homeassistant status updates
ha.discovery_prefix = 'homeassistant'       # MQTT prefix for discovery topic 
ha.entity_prefix    = 'tsun'                # MQTT topic prefix for publishing inverter values


# microinverters
inverters.allow_all = false   # True: allow inverters, even if we have no inverter mapping

# inverter mapping, maps a `serial_no* to a `node_id` and defines an optional `suggested_area` for `home-assistant`
#
# for each inverter add a block starting with [inverters."<16-digit serial numbeer>"]
[inverters."R17xxxxxxxxxxxx1"]
node_id = 'inv1'              # Optional, MQTT replacement for inverters serial number  
suggested_area = 'roof'       # Optional, suggested installation area for home-assistant

[inverters."R17xxxxxxxxxxxx2"]
node_id = 'inv2'              # Optional, MQTT replacement for inverters serial number  
suggested_area = 'balcony'    # Optional, suggested installation area for home-assistant


License

This project is licensed under the BSD 3-clause License.

Note the aiomqtt library used is based on the paho-mqtt library, which has a dual license. One of the licenses is the so-called Eclipse Distribution License v1.0. It is almost word-for-word identical to the BSD 3-clause License. The only differences are:

  • One use of "COPYRIGHT OWNER" (EDL) instead of "COPYRIGHT HOLDER" (BSD)
  • One use of "Eclipse Foundation, Inc." (EDL) instead of "copyright holder" (BSD)

Versioning

This project adheres to Semantic Versioning. Breaking changes will only occur in major X.0.0 releases.

Contributing

We're very happy to receive contributions to this project! You can get started by reading CONTRIBUTING.md.

Changelog

The changelog lives in CHANGELOG.md. It follows the principles of Keep a Changelog.

Description
This proxy enables a reliable connection between TSUN inverters (eg. TSOL MS800, MS2000, MS3000), batteries (TSOL DC1000) and an MQTT broker in order to integrate them into typical home automation systems.
Readme 5.2 MiB
Languages
Python 92.3%
CSS 2.6%
Jinja 2.3%
Makefile 1.4%
HCL 0.6%
Other 0.8%