Coder Social home page Coder Social logo

s-allius / tsun-gen3-proxy Goto Github PK

View Code? Open in Web Editor NEW
32.0 32.0 4.0 749 KB

This proxy enables a reliable connection between TSUN third generation inverters (eg. TSOL MS600, MS800, MS2000) and an MQTT broker to integrate the inverter into typical home automations.

Home Page: https://s-allius.github.io/tsun-gen3-proxy/

License: BSD 3-Clause "New" or "Revised" License

Dockerfile 0.88% Python 97.67% Shell 1.45%
docker home-assistant inverter-monitor mqtt python3 tsun

tsun-gen3-proxy's Issues

Reset the daily generation values at midnight

The measured values for daily energy production increase continuously and start from zero again with the new day. Since the proxy only sends values to the MQTT broker and the Home Assistant when it receives values from the inverter, the meters are only reset at the start of solar production and not at midnight.
We should send an MQTT update packet at least at midnight so that the meters are reset at the start of a new day. See the red arrow in the picture

Bild 10 12 23 um 19 25

send autoconfig on HA restart

If the Home Assistant Service has restarted, the proxy should send his autoconfig MQTT topics again. This assures that both are in sync.

Handle connection timeouts to TSUN cloud

In forwarding mode, we wait for the responses from the TSUN cloud.

For GEN3 inverters we need the timestamp in the proper timezone. Since TSUN don't handle the summertime change correct and there is no time shift allowed between the inverter and the cloud, we want the proper timestamp from the cloud.
However, if there is a configuration problem or the cloud is unavailable, we will no longer receive a response with the correct timestamp from the cloud.

In this situation we want an error handling wich sends the local time to the inverter. Otherwise the logging on Home Assistant will also stop.

Send internal proxy states to Home-Assistant

For getting a better view on the proxy, we should add the proxy as a device to Home-Assistant:

possible data to show:

  • Proxy version
  • number of connection
  • connection time
  • events like connection errors, establishments, ...

also wishful:

  • a switch to disable the connections to the internet

Running Proxy with host UID and GUID

The container runs in non-root mode. It is important that the proxy has the correct UID. Otherwise, reading and writing files on the host volumes is not possible.

Needed:

  1. better documentation
    Even better:
  2. an automatic mode, so that images can run in any environment, without reconfiguring the UID.

'Inverter Connection Count' don't decrease after connection lost

With Version 0.4.0

The new counter 'Inverter Connection Count' is not counted down after sunset. Presumably, the updated counter is no longer transmitted to the MQTT broker after the connection is terminated by the inverter and therefore remains incorrect until sunrise.

Handle catch-up data

Today my inverter was offline for many hours (9:00-18:00) and I noticed some interesting behavior:

When the connection is re-established, the inverter not only sends its current data every 5 minutes. It has been sending 10 additional packets every 5 minutes for ~1 hour. These additional data packets appear to contain data from the time the inverter was offline.

This 'catch-up' data is then used at talent-monitoring.com to fill the gap in the graph for the time the inverter was offline.

Screenshot of 18:30, where data up to 12:30 was subsequently filled.
Screenshot_20240514_183038

Screenshot of 19:50, data was subsequently filled completely.
Screenshot_20240514_195032

The proxy doesn't distinguish between normal data packets and these catch-up data packets. So all packages are handled as current data, so the chart in Home Assistant looks like this.
image

I don't know if it will be possible to process this 'catch-up' data with the correct time stamp and then fill in the data in the Home Assistant. At least it would be good to ignore this data if it cannot be handled appropriately.

data_type 76 not supported

Thank you for sharing your TSUN proxy with us.

In the log file I see the following error

ERROR | root | Infos.parse: data_type: 76 not supported

Is this the intended behavior or do I need to change some setting to get rid of this error?

Auto Discovery does not connect to Home Assistant

Sorry if I miss something obvious. I'm new to this tool and Home Assistant in general.

Problem

With my current configuration I am not able to find any hint of the proxy or the inverter (MS800) in Home Assistant, using docker.

Setup

I've deployed the stack according to the provided compose file here. I've adjusted the network name and the volumes, but nothing major.
All three containers do start and dont report any error. The proxy is able to connect to mosquitto. I tried my best to configure the config.toml file:

# 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    = 'Mosquitto'   # URL or IP address of the mqtt broker
mqtt.port    = 1883
mqtt.user    = 'secure_username'
mqtt.passwd  = 'secure_password'

# 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
ha.proxy_node_id    = 'proxy'               # MQTT node id, for the proxy_node_id
ha.proxy_unique_id  = 'P170000000000001'    # MQTT unique id, to identify a proxy instance

# microinverters
inverters.allow_all = true   # allow inverters, even if we have no inverter mapping

# inverter mapping, maps a `serial_no* to a `mqtt_id` and defines an optional `suggested_place` for `home-assistant`
#
# for each inverter add a block starting with [inverters."<16-digit serial numbeer>"]
[inverters."inverter_id"]
node_id = 'wechselrichter'                 # Optional, MQTT replacement for inverters serial number
suggested_area = 'balkon'          # Optional, suggested installation area for home-assistant
pv1 = {type = 'PiE AIR superLIGHT Half-Cut 200+', manufacturer = 'PiE'}   # Optional, PV module descr
pv2 = {type = 'PiE AIR superLIGHT Half-Cut 200+', manufacturer = 'PiE'}   # Optional, PV module descr

I've removed any sensitive data like username and password aswell as the inverter id.

Also I have configured mosquitto with a config file, activating per_listener_settings and providing a password_file.

In the Home Assistant Web Interface I cant connect to the Proxy. Am I missing something or missconfigured anything?

Thank you in advance for the tool in general and any advise. If you need any furthor information, please let me know.

Due to the proxy, the TSUN cloud always shows the inverter status as offline

Observed with all versions since version 0.5:

For some time now, the TSUN apps and the TSUN website have always shown the inverter as offline, although status data and measured values are displayed correctly.
This may be due to an interruption in the connection to the TSUN Cloud, especially if the connection to the inverter is maintained

Since Home Assistant Core Update and TSUN Update no Data Transfer

Aktuell funktioniert bei mir die Übertragung nicht mehr ordnungsgemäß.
Sowohl nach TSUN noch an Home Assistant.
Im MQTT sehe ich, dass die Config übertragen wird, jedoch die Werte werden nicht übermittelt.
Im Proxy Home Assistant Eintrag wird ein Internal SW Error hoch gezählt und die Verbundenen Controller zählen auf 300 und höher nach Oben.

support for sub devices

Home Assistant supports configuration of devices to which the individual sensors are assigned. For devices that contain multiple logical units, sub devices are also supported.
For the TSUN inverters, this concept is suitable and the following devices should be created:

  • Inverter
  • Controller with Wifi/WWAN
  • 1 to 4 inputs for solar modules

This means that not all sensors are assigned directly to the inverter and you can use the individual sub-devices on the dashboards as required.

Proxy counters don't work after restart properly

With version 0.4.3:
Proxy counters do not work properly after restart.

  1. After a proxy restart or update, the proxy counters are registered by establishing the first inverter connection. The expectation is that this happens directly at proxy start.

  2. The counter values are in the status 'unknown' until the first sunset. here is the expectation, that the counter will be synchronized directly after the proxy start.

Self-sufficient island operation for GEN3PLUS inverters

In version 0.6.0 GEN3 Plus Inverters only works if solarman.enabledin the 'confidence-toml' file is set to 'true'

In addition to this proxy mode, island mode is also to be implemented so that the GEN3 Plus inverters can also be monitored via MQTT without an Internet connection to the TSUN Cloud

Exception during parsing the contact info message

The following exceptions occur with the current main branch:

'2023-12-24 11:03:15 ERROR | conn | Exception for ('logger.talent-monitoring.com', 5005):
Traceback (most recent call last):
  File "/home/tsun-proxy/async_stream.py", line 31, in loop
    await self.__async_read()
  File "/home/tsun-proxy/async_stream.py", line 72, in __async_read
    self.read()                # call read in parent class
    ^^^^^^^^^^^
  File "/home/tsun-proxy/messages.py", line 164, in read
    self.__dispatch_msg()
  File "/home/tsun-proxy/messages.py", line 271, in __dispatch_msg
�
)
  File "/home/tsun-proxy/messages.py", line 288, in msg_contact_info
    self.__process_contact_info()
  File "/home/tsun-proxy/messages.py", line 302, in __process_contact_info
    result = struct.unpack_from(f'!{name_len+1}pB', self._recv_buffer,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack_from requires a buffer of at least 26 bytes for unpacking 3 bytes at offset 23 (actual buffer size is 24)
'
'2023-12-24 11:03:15 DEBUG | conn | in AsyncStream.close() l('172.28.1.32', 40620) | r('47.254.132.252', 5005)'

Do not register non-existent inverter inputs in HA

The TSOL MS-600 software sends values from 4 inputs, and the proxy registers them all with the home assistant. However, the inverter has only 2 inputs, so unhelpful values appear on the Home Assistant dashboard.

Only existing inputs should be registered

GEN3PLUS: Consideration of subsequently delivered data records

The GEN3PLUS inverters sends after a connection setup or reestablishment, the missing data together with the realtime data. In the Power on Timegraph we will see glitches in that moment:
Bild 20 04 24 um 01 53

We want to handle this situation and send the non realtime data with a proper timestamp to home assistant, so that they will be inserted in the database at the proper place. Then we should see a permanent growing Power on Timegraph.

Modbus Pipeline needed

There is an experimental Modbus implementation in the dev-0.8.0 development branch.

Since only one request may be sent to the inverter at a time, but these can come from several independent sources (TSUN Cloud, MQTT and internal timers), a pipe with a timeout handler is required. Without this, requests can always be lost or the responses forwarded incorrectly.

This is not acceptable for a release version of the proxy

Problem to start the container

Hi,

first, thank you for this amazing promising project!
I am looking forward to use this in my home setup...

Unfortunately I am not able to start the container as you described the startup process.
I build the image and tried to start the container by running:
docker run --dns '192.168.212.20' --env 'UID=1000' -p '5005:5005' -p '10000:10000' -v /srv/tsun-proxy/config:/home/tsun-proxy/config -v /srv/tsun-proxy/log:/home/tsun-proxy/log tsun-proxy

And I get the following:

######################################################
# prepare: 'tsun-proxy' Version:
# for running with UserID:1000, GroupID:1000
#
# create user
######################################################
#
'2024-04-08 20:20:23  INFO | root | Server "tsun-proxy - " will be started'
'2024-04-08 20:20:23  INFO | root | Initialize proxy statistics'
Traceback (most recent call last):
  File "/home/tsun-proxy/./server.py", line 83, in <module>
    Inverter.class_init()
  File "/home/tsun-proxy/inverter.py", line 21, in class_init
    cls.entity_prfx = ha['entity_prefix'] + '/'
                      ~~^^^^^^^^^^^^^^^^^
KeyError: 'entity_prefix'

Is this an error in the code or on my side?

Background:
I tried to use a lxc container and a debian vm under proxmox virtualization.

Btw: Do you have a donation option?

Version 0.8: Proxy does not respond to Modbus commands from TSUN

As there is no address in the Modbus responses, the proxy analyzes the requests and responses to obtain the required information, which is then forwarded to the MQTT broker.

The proxy itself regularly sends requests to the inverter. These responses should not be sent to the TSUN cloud. We have a filter for this.

However, there is a bug so that the responses to the requests from the TSUN cloud are also filtered and not answered.

Detect loop in the DNS setup

If the DNS name logger.talent-monitoring.com is resolved to itself by the proxy, then countless connections are established through this loop until the system crashes.
This is a misconfiguration of the DNS setup and should be recognized by the proxy and the outgoing connection should not be established. The proxy then runs and at least delivers the data to the MQTT broker.

Frequent data gaps with MS600 (GEN3) inverter

With an MS600 (GEN3) inverter with DSP version 5.1.09, I regularly see gaps in the data transmission. An initial analysis has shown that the TCP connection is stable and TCP keep-alive packets are also being answered.

We may be able to get the inverter out of this state by reestablishing the connection. I am not aware of a way to restart the DSP using a magic packet.
I will try to recognize the situation by time monitoring and then close the TCP connection from the proxy side (sending a FIN packet) in the hope that the inverter will then send data again immediately.

Bild 10 05 24 um 20 23

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.