Complex automations

I am wondering how I should implement a complex automation:
I have a python script that reads the power values of multiple solar inverters(OpenDTU) and the grid from mqtt and then sets the target power for the inverters based on some nontrivial calculations. The calculation is about 30 lines of python if I remember right.

The problem: It is not integrated in Home Assistant OS, I have to run it on a separate computer.

What I have tried already:

  • Use the pyscript integration. I can not even find it in the integration store??
  • There is also some other python script support integrated where I put my scripts into config/python_scripts. But I did not find out how I can get/set states from there.
  • AddDaemon: I think that could work in theory. I did not get it running properly yet. My callbacks are somehow never executed. But I can just get/set states from there if understand that right?
  • REST API using the python package homeassistant_api: When I set the power of an inverter it deletes all attributes(like friendly_name) from the entity. Thats not good. Also it is not integrated into HAOS.
  • Creating a debian container in docker in HAOS and running my old script works. But thats also not nicely integrated and requires manual starting.
  • Using just normal templates, scripts and automations: That gets really extremely complex. In python I need datatypes like lists and operations on them. While I do think it is theoretically possible to implement it that way, it is at least too hard for me.

So my questions:

  • Did I miss another way to do it?
  • Is there a example which demonstrates how to do something like that?
  • Am I the only one with this problem?:slight_smile:

My ideal solution would be a python script that is periodically executed every few seconds or runs continously and does the following(pseudo code):

inverter_current_powers = [get_state("inverter1.power",get_state("inverter2.power",...]
target_powers = complexcalculation(grid_power, inverter_current_powers)
for p in target_powers:
  set_state(inverter[i].power_limit, p)