Entire project for multi area/zone heating, cooling, open window control

Hello everyone.
Lately I have managed to connect an esp to an OT shield from https://diyless.com/ / http://ihormelnyk.com/opentherm_adapter .
Because of this, I decided to concentrate some of my time to trying to make a smarter than your average hvac system. After finishing, this will be moved probably to projects section.
My heating project looks like this at the moment:

I can control my boiler now based on the temperature from a sensor in my house. Any of them, but only one at a time.
What I want to do is, a lot more complicated. I want to have control over the temperature in any of my 3 rooms, turn off heating of in a certain room if the window is opened, and maybe have a vacation button to set temp to a very low value.
Now, I am writing here because, of course, I am missing all the config needed for the automation. :slight_smile:
What needs to be done:
automation temp room1

- alias: room1-temp
  trigger:
    - platform: state
      entity_id: sensor.0x00158d000465809a_temperature
  action:
    service: mqtt.publish
    data: 
      payload: "{{ states('sensor.0x00158d000465809a_temperature') }}"
      topic: "dummy-current-temp-room-1"
      qos: 0
      retain: 0

0x00158d000465809a : entity id of zigbee aqara temperature sensor

automation window room1

- alias: window-sensor-room1
  trigger:
    - platform: state
      entity_id: binary_sensor.entity-of-window-sensor
    - platform: state
      entity_id: sensor.dummy-t1-r1
  action:
    - delay: '00:00:02'
    - choose:
      - conditions:
        - condition: state
          entity_id: binary_sensor.entity-of-window-sensor
          state: 'on'
          for:
            minutes: 2
        sequence:
          - service: mqtt.publish
            data:
              payload: "10"
              topic: "dummy-eco-set-temp-room1"
              qos: 0
              retain: 0
    default:
      - service: mqtt.publish
        data:
          payload: "{{ states('sensor.dummy-t1-r1') }}"
          topic: "dummy-eco-set-temp-room1"
          qos: 0
          retain: 0

This should publish a value of 10 (as in degrees) to dummy-eco-set-temp-room1 if the window is open for more than 2 minutes, or the value on sensor dummy-t1-r1 if the window is closed. The automation should get triggered whenever the window is opened, closed, or the set value from thermostat gets changed.
This topic will get registered back as a new sensor:

sensor:
  - platform: mqtt
    name: "dummy-t2-r1"
    state_topic: "dummy-eco-set-temp-room1"

automation TRV room1

- alias: TRV-command-room1
  trigger:
    - platform: state
      entity_id: binary_sensor.entity-of-window-sensor
      to: 'on'
    - platform: state
      entity_id: binary_sensor.entity-of-window-sensor
      to: 'off'
    - platform: state
      entity_id: sensor.dummy-t2-r1
    - platform: state
      entity_id: sensor.0x00158d000465809a_temperature
  action:
    - choose:
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.entity-of-window-sensor
            state: 'on'
            for:
              minutes: 2
          - condition: template
            - value_template: "{{ states('sensor.0x00158d000465809a_temperature')|float > states('sensor.dummy-t2-r1')|float + 0.5}}"
        sequence:
          - service: mqtt.publish
            data:
              payload: {"window_detection": "ON"}
              topic: "zigbee2mqtt/FRIENDLY_NAME/set"
              qos: 0
              retain: 0
    default:
      - service: mqtt.publish
        data:
          payload: {"window_detection": "OFF"}
          topic: "zigbee2mqtt/FRIENDLY_NAME/set"
          qos: 0
          retain: 0

This automation should run either when the window is open for 2 minutes, window closes, there is a change in set temp or a change in room temperature. It closes the radiator in case room temperature is +0,5 degrees or higher than set temp or if window is open for more than 2 minutes, otherwise it opens the radiator.

automation mode

- alias: boiler-mode
  trigger:
    - platform: mqtt
      topic: "dummy-mode-room1"
    - platform: mqtt
      topic: "dummy-mode-room2"
#  ...
  action:
    - delay: '00:00:02'
    - choose:
      - condition: or
        conditions:
          - condition: state
            state: 'on'
            entity_id: binary_sensor.dummy-mode-room1
          - condition: state
            state: 'on'
            entity_id: binary_sensor.dummy-mode-room2
#        ...
        sequence:
          - service: mqtt.publish
            data:
              payload: heat
              topic: "opentherm-thermostat/mode/set"
              qos: 0
              retain: 0
    default:
      - service: mqtt.publish
        data:
          payload: off
          topic: "opentherm-thermostat/mode/set"
          qos: 0
          retain: 0

This should send heat payload to the topic opentherm-thermostat/mode/set if any of the rooms has the thermostat set to heating, otherwise send off to the same topic.

automation algorithm room1

- alias: alg room1
  trigger: 
    - platform: state
      entity_id: sensor.0x00158d000465809a_temperature
    - platform: state
      entity_id: sensor.dummy-eco-set-temp-room1
  action:
    - choose:
      - conditions:
        - condition: template
          value_template: "{{ (states('sensor.dummy-eco-set-temp-room1')|float > states('sensor.0x00158d000465809a_temperature')|float) }}"
        sequence:
          - service: mqtt.publish
            payload: "{{ states('sensor.0x00158d000465809a_temperature') }}"
            topic: "dummy-current2-room-1"
          - service: mqtt.publish
            payload: "{{ states('sensor.dummy-eco-set-temp-room1') }}"
            topic: "dummy-eco-final-room-1"
      default:
        - service: mqtt.publish
          payload: "50"
          topic: "dummy-current2-room-1"
        - service: mqtt.publish
          payload: "10"
          topic: "dummy-eco-final-room-1"

automation algorithm room2

- alias: alg room2
  trigger: 
    - platform: state
      entity_id: sensor.entity_of_temp_sensor_room2
    - platform: state
      entity_id: sensor.dummy-eco-set-temp-room2
  action:
    - choose:
      - conditions:
        - condition: template
          value_template: "{{ (states('sensor.dummy-eco-set-temp-room2')|float > states('sensor.entity_of_temp_sensor_room2')|float) }}"
        sequence:
          - service: mqtt.publish
            payload: "{{ states('sensor.entity_of_temp_sensor_room2') }}"
            topic: "dummy-current2-room-2"
          - service: mqtt.publish
            payload: "{{ states('sensor.dummy-eco-set-temp-room2') }}"
            topic: "dummy-eco-final-room-2"
      default:
        - service: mqtt.publish
          payload: "50"
          topic: "dummy-current2-room-2"
        - service: mqtt.publish
          payload: "10"
          topic: "dummy-eco-final-room-2"

These topics get translated to sensors:

sensor:
  - platform: mqtt
    name: "dummy-current-r1"
    state_topic: "dummy-current2-room-1"
sensor:
  - platform: mqtt
    name: "dummy-t3-r1"
    state_topic: "dummy-eco-final-room-1"
sensor:
  - platform: mqtt
    name: "dummy-current-r2"
    state_topic: "dummy-current2-room-2"
sensor:
  - platform: mqtt
    name: "dummy-t3-r2"
    state_topic: "dummy-eco-final-room-2"
#  ...

automation send data to OT

- alias: temp to ot
  trigger: 
    - platform: time_pattern
      seconds: "/20"
  action: 
    - service: mqtt.publish
      data:
        topic: "opentherm-thermostat/current-temperature/set"
        payload: template
        value_template: "{{ (states('"dummy-current2-room-1"')|float, states('dummy-current2-room-2')|float, states(...)|float)|min }}"
    - service: mqtt.publish
      data:
        topic: "opentherm-thermostat/setpoint-temperature/set"
        payload: template
        value_template: "{{ (states('"dummy-eco-final-room-1"')|float, states('dummy-eco-final-room-2')|float, states(...)|float)|max }}"

mqtt climate config in configuration.yaml:

  - platform: mqtt
    modes:
      - "off"
      - "heat"
    name: Boiler
    current_temperature_topic: "dummy-current-temp-room-1"
    mode_command_topic: "dummy-mode-room1"
    mode_state_topic: "loop-mode-room1"
    temperature_command_topic: "dummy-set-temp-room1"
    temperature_state_topic: "loop-setpoint-room1"
    min_temp: 12
    max_temp: 28
    value_template: "{{ value }}"
    temp_step: 0.2

Mode_command_topic will transform into a binary sensor:

sensor:
  - platform: mqtt
    state_topic: "dummy-mode-room1"
    name: "dummy-mode-room1"
    payload_on: "heat"
    payload_off: "off"

Temperature_command_topic goes into sensor:

sensor:
  - platform: mqtt
    name: "dummy-t1-r1"
    state_topic: "dummy-set-temp-room1"

why aren’t you using the generic climate?

or the mqtt version:

Hi @elRadix,

If you see, the last code is for the mqtt hvac integration. That is for one room out of the 3 i will control. That will send the first set temp, which will get intercepted by the window sensor, and the general algorithm.
That config is only for the ha thermostat bubble on my drawing.

Or did you have something else in mind?

then have a look on schedy for your algoritm part
https://hass-apps.readthedocs.io/en/stable/apps/schedy/tutorial.html

Yes. Schedy was one of the sugestions. But the best way to do it is still through automations. And schedy is more of a planner. I am not sure it can do what the algorith automation will. Monitor 3 pairs of temperatures, take into account only the ones with positive delta and out of those send the minimum and maximum to other topics.