Heating automation translation!

Recently i made the move from openhab to HA. I am pretty much setup back to how i was when using openhab regarding automations and entities apart from my heating setup. Could anyone help me translate this rule to a HA Automation please?

rule "Living Room heating"
when
    Item Living_Room_Temp_Setpoint changed or
    Item Living_Room_Temperature changed
then
    var Number cur_temp = Living_Room_Temperature.state as Number
    var Number setpoint = Living_Room_Temp_Setpoint.state as Number
    val  Number hysteresis = 0.2

    if (cur_temp < (setpoint - hysteresis) ){
        if (Living_Room_Radiator_Valve.state != ON) {Living_Room_Radiator_Valve.sendCommand(ON)}
    }
    else if(cur_temp > setpoint + hysteresis) {
        if (Living_Room_Radiator_Valve.state != OFF) {Living_Room_Radiator_Valve.sendCommand(OFF)}
    }
end

Basically if anyone can’t tell the rule is triggered when the living room current temp or the setpoint changes. It then compares them and if current temp is 0.2 degrees over the setpoint it turns the radiator valve off. If the current temperature is 0.2 degrees below the setpoint it turns the radiator on. I looked into the threshold helper but you can’t set it to compare 2 entities. It just looks for upper and lower limits of a entity/sensor.

Any help is much appreciated.

The most basic version would be something like this.

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - climate.living
    attribute: temperature
  - platform: state
    entity_id:
      - sensor.living_temp
condition: []
action:
  - if:
      - condition: template
        value_template: >-
          {% set cur_temp = states('Living_Room_Temperature' | float(0)) %}
          {% set setpoint = state_attr('Living_Room_Temp_Setpoint', 'temperature' | float(0)) %}
          {% set hysteresis = 0.2 %}
          {{ cur_temp < (setpoint - hysteresis)  }}
    then:
      - service: climate.turn_on
        data: {}
        target:
          entity_id: Living_Room_Radiator_Valve
    else:
      - if:
          - condition: template
            value_template: >-
              {% set cur_temp = states('Living_Room_Temperature' | float(0)) %}
              {% set setpoint = state_attr('Living_Room_Temp_Setpoint', 'temperature' | float(0)) %}
              {% set hysteresis = 0.2 %}
              {{ cur_temp > (setpoint + hysteresis)  }}
        then:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: Living_Room_Radiator_Valve

I’ve used a mix of climate and switch entities as examples, not really sure what domain your entities are in HA

The state trigger without setting a specific state triggers any time the state changes. I gave an example of a state and a state attribute.

Then a basic if then else action which evaluates to true or false before calling the relevant service.

In Home Assistant, the Generic Thermostat integration is designed for controlling heating/cooling based on target and ambient temperatures. It also allows you to specify hysteresis (a.k.a.‘deadband’), plus it can easily be displayed in the UI using the Thermostat card.

This is how my entities are set up.
Current temperature sensor.living_room_temperature
Setpoint input_number.living_room_target_temperature
Radiator switch.living_room_radiator

?

Ive already tried this, the target temperature cant be linked to an entity, only a number that can be altered with the gauge on the thermostat card. Im planning to setup helpers that specify a different temperature for different times on the day, ie MORNING, DAY, EVENING and NIGHT. Send this data to the corresponding target temperature in each room, then the automation above will do the rest. If you know of a way i can link an entity to the target temperature in the generic_thermostat please let me know.

You’re approaching it in the opposite direction of how it’s normally done in Home Assistant. You don’t (and can’t) make the target temperature an entity. You set the target temperature with climate.set_temperature.

To set a different target temperature, based on time-of-day, you can use an automation with Time Triggers or a State Trigger monitoring the Schedule integration. You can even use Local Calendar for scheduling but it’s probably more scheduling flexibility than most people need for controlling heating.

Sorry I just had a light bulb moment and understand what you mean now. So I create time of day triggers with different temperatures for each room. Then use the climate.set_temperature to the send that temperature to the Living_Room_Thermostat entity and Bedroom_Thermostat entity etc which will in turn change the target temperature in the generic_thermostat?

That’s correct.