Compute heating temperature

I’m quite new to automation/scripting in home-assistant. I’m trying to migrate my fhem installation to home assistant.

However, there is 1 major automation in my heating system that i don’ t know how to migrate.

In each room of the house, there is a thermostat; On each thermostat, I have the target temperature and the % opening of the valve.
these one are defined as climate entities and work fine.

The automation/script I need must take the target temp and %valve opening and return the max target temp for which the valve is at least open for 15%.
if there sat least 1 open valve to 15%, the climate of my gas boiler will pass from auto to manual and this target temp will set the climate target temp of my gas boiler.

if all valve are closed, then climate state will go to auto.

That’s quite complex, but I have this today done in Perl in fhem and works very well with my heating system.
Could you give me hints, links about how to do that, how I should do ? also, possibly some examples : tutos.

I have a rather good knowledge of python, but I lack knowledge about how to work with home-assistant