Adjust multiple thermostats offsets with external temp sensors

I installed around 25 inexpensive Zigbee GTZ06 thermostats.

I wanted to group the radiators, but the solutions I found didn’t work well for me. I also wanted the thermostats to use an external temperature sensor. After trying a few existing addons without success, I decided to create a simple automation.

This automation, which can run every minute (or at any interval you prefer), checks each radiator’s internal temperature and the temperature from its assigned external sensor. It then adjusts the offset (calibration value) to align them.

I set up the Scheduler to handle desired temperature changes. After testing the whole setup for 48 hours, it works effectively.

You can use one external sensor for multiple thermostats without needing to group them.

alias: Adjust thermostats offsets with external temp sensors
description: >-
  Version 1.1

  thermostat - thermostat entity 
  calibration - thermostat's offset value
  sensor_exte - external sensor's temperature value

  New offset is calculated as: external_sensor_temp - thermostat_actual_temp.
  Since the thermostat's actual temperature (before offset) is not available as an
  attribute, it must be calculated (current_temp - current_offset). Therefore, 
  the equation for the new offset is: external_sensor_temp - (current_temp -
  current_offset).

  If the external sensor returns an unknown value, the script sets the offset to 0
  (using the internal temp sensor). The default float value for
  external_sensor_temp is set to float(current_temp - current_offset), so in that
  case, the equation is: (current_temp - current_offset) - (current_temp -
  current_offset) = 0.

  The offset must be rounded to 1 decimal place.

trigger:
  - platform: time_pattern
    minutes: /1
action:
  - repeat:
      for_each:
        - thermostat: climate.termostat1
          calibration: number.termostat1_local_temperature_calibration
          sensor_exte: sensor.room1_temperature
        - thermostat: climate.termostat2
          calibration: number.termostat2_local_temperature_calibration
          sensor_exte: sensor.room1_temperature
        - thermostat: climate.termostat3
          calibration: number.termostat3_local_temperature_calibration
          sensor_exte: sensor.room2_temperature
      sequence:
        - service: number.set_value
          data:
            entity_id: "{{ repeat.item.calibration }}"
            value: >
              {{ (states(repeat.item.sensor_exte) |
              float((state_attr(repeat.item.thermostat, 'current_temperature') |
              float - 
                  states(repeat.item.calibration) | float)) - 
                 (state_attr(repeat.item.thermostat, 'current_temperature') | float - 
                  states(repeat.item.calibration) | float)) | round(1) }}

To monitor each thermostat’s performance, I added a template sensor in YAML (which is faster to add in batch than using a helper).

template:
  - sensor:
      - name: "thermostat1 External Sensor Diff"
        unit_of_measurement: "°C"
        state: >
          {{ ( state_attr('climate.termostat1', 'current_temperature') | float - states('sensor.temp_sensor') | float ) | round(1) }}

Then, you can set a filtered view to show only devices that are off by 0.2 degrees or more, which could signal a problem or just an open window/door. This will be corrected after the next repeat. Setting show_empty to false will hide the card if all entities are within range.

type: entity-filter
entities:
  - sensor.thermostat1_external_sensor_diff
  - sensor.thermostat2_external_sensor_diff
  - sensor.thermostat3_external_sensor_diff
  - sensor.thermostat4_external_sensor_diff
state_filter:
  - operator: '>='
    value: 0.2
  - operator: <=
    value: -0.2
card:
  type: entities
  title: Thermostats off by more than 0.2 degree
show_empty: false

Additionally, you can track the differences over time to identify any potential issues. I created a history view with all of them, including 1-hour and 24-hour views.

1 Like

This is awesome, thank you very much! Two things:

  1. How did you manage to make Scheduler work? :wink: I cannot get rid of the schedule stored within the device’s memory and it always override settings from Scheduler.

  1. Are you sure that writing the offset every minute is a good idea? I’ve read that the number of temperature offset recordings depends on the specific smart TRV model, but most manufacturers declare that we’re looking at around 100,000 recordings.

You have to set every thermostat to manual :smiley:
image

To be honest, I’m not entirely sure. After an extended period, some thermostats randomly lock up and stop accepting offset changes. I’ve found that rebooting them (by reconnecting the battery) seems to resolve the issue, as they start functioning correctly again. I plan to reboot all of them and see if that provides a more lasting solution.