s-allius / tsun-gen3-proxy

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.
https://s-allius.github.io/tsun-gen3-proxy/
BSD 3-Clause "New" or "Revised" License
53 stars 6 forks source link

tsun proxy as home-assistant add-on #206

Open mime24 opened 1 week ago

mime24 commented 1 week ago

Thank you for this inspiring work! since some weeks I'm curious how this project develops and whether there is an alternative way to install. For users like me who are running HA OS a home assistant add-on would be great. it seems super close to the development of containers but are easier to use for the majority of HA users. I'm not a developer, so I have no idea about the milestones to achieve for running the proxy as an add-on. It would be just the proxy as HA is obviously already there. the broker is also not needed as there is an existing add-on.

have you thought about this option? do you think this is achievable?

s-allius commented 1 week ago

Hello mime24,

the aim of this project is to create a solution that is as universal as possible. This means that the proxy only takes care of the data processing and provides it via a standard protocol such as MQTT. This enables the proxy to be used for various automation systems. Home Assistant is just one possibility.

It may well be that it is not that difficult to integrate the proxy into HA. But I'm not familiar with the internals of HA. For me it is important that dependencies to other software parts are well isolated. An intermediate layer would therefore have to be created that adapts the Ethernet and MQTT interface. I can't say whether this makes sense. If someone would like to take on this, I would be happy to help. But I don't have the resources myself. Setting up a Docker is not that difficult either...

mime24 commented 1 week ago

understood your motivation/concerns. let me check whether I can observe the required steps, try something and maybe also find someone else who could support.

you're right that setting up docker is not so difficult. But for most of the home assistant users (>77% running on Home Assistant OS) the docker cannot/shouldn't executed on the host where HA is running. You would not be able to update your HA installation anymore due to compliance issues. "If you run Home Assistant, please be aware that running additional containers is not a supported use-case and will trigger your system to be flagged as unsupported as well."

s-allius commented 1 week ago

OK, my approach is a little bit different. I rund HA, mosquito and my proxy as a docker container in docker compose on my NAS. There I have no problems with update and HA didn't see the other containers. And you are properly right that most of the HA user run HA on a dedicate machine like raspberry.

When the proxy runs in an own docker container, everything is like I want. So I don't have to think about the python version, or a version of any other modul. If my code runs as a HA add-on, I must accept that HA dictates with version is running. At the moment I only run tests with python 3.12.6 and I can use any new python feature. After releasing version 3.13, I will move forward and must noch care about version 3.12 anymore.

HA requires requires-python = ">=3.11.0" and "aiohttp==3.9.1"

My proxy runs on python==3.12.6 and uses aiohttp==3.10.5

I don't know what are the differences. And with a dedicated docker container, the proxy runs at each user in exact one configuration.

But if you find some documentation about migrating code as add-on, I will give it a try. Maybe it's not so hard to support a second hw-layer...

mime24 commented 5 days ago

Hi @s-allius, yesterday I did some research. I quickly discovered that add-ons are also created using Dockerfiles. It took me a while to understand how it all works. It quickly became clear to me that, in theory, no major changes were needed to get it up and running. In practice, I was stumped for a very long time. I just hadn't managed to install the necessary libraries via pip. apparently, the libraries either have to be available in the host system or you have to use a virtual python environment. In the end it worked. The server is running and shoveling diligently for Homeassistant. Due to my lack of knowledge, I had to improvise a bit. The solution is therefore not yet particularly attractive.

ToDo's would still be among others:

s-allius commented 5 days ago

Hey, that's sounds good.

To harmonize some file structure shouldn't be a problem for me. Maybe we can reach in the MQTT user setup via an environment setting. That would be the typical way for containers.

If you have a description, or more details which values we have to pass, I can add it.

mime24 commented 2 days ago

I'm currently trying to clean up the add-on, create some info and comments to the code. How shall I handle the add-on on Github. I'm not familiar with all that stuff, so I'm asking you whether I shall create an own Projekt or is it better to add it somehow to yours?

s-allius commented 1 day ago

If you think, that we can bring the code together, then you should make a fork from my project and add you modification. The next step would be a pull request, and then we can bring both together.

I'm not sure if there are other ways. I'm also not familiar with this stuff.

If you make an own project and want to get the coming improvements from my project, you have to merge it with every new version. So I think to bring you improvements back into this project is nicer.