Integrate heating system in homeassistant

Hello
I’m fairly new around here and I would need someone to point me in the right direction to go.
I am thinking of integrating my current heating system into homeassistant.
The system is based on an urban hot water network that through a motorized valve (which is the one I must control) passes to a heat exchanger which is also connected to my radiators in the secondary circuit.
The current system is programmed by me in a PLC and uses three temperature sensors: interior, exterior and water flow in the radiators.
The indoor and outdoor temperature sensors are factors in a formula based on the heating curve which calculates the target value of the flow temperature and in this way is compared with the flow sensor reading to open or close the valve with two relays.
The interior temperature and water flow sensors of the radiators as well as the valve relays are already implemented in an esp8266 via esphome and are already homeassistant entities that is installed in a raspberrypi 4; for the outdoor temperature sensor I want to use the whether platform.

How can I do this? I have tried a generic thermostat but I don’t know how to make the target temperature the result of the formula and vary in real time.

I know this is a very ambiguous question, but I would appreciate any help.
Thanks
image

You need to create a template sensor that calculates your desired temperature, something like:

sensor:
  - platform: template
    sensors:
      target_temperature:
        friendly_name: "Target Temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        value_template: "{{ your template to calculate the target temp) }}"

And then use this sensor as the target_sensor in the generic thermostat.

Great!
I will investigate in this direction over the weekend.
Thanks

Is there a solution to calculate the target temperature?