Better TRV control: Automation of Sonoff Zigbee TRV calibration using Sonoff room sensor

Hi all
I have been using Sonoff TRVs for some time and have generally been happy with them. The HA team have made things even better when using Zigbee2MQTT as they have nicely exposed the 7 day programming config.
The only downside for me was the fact the TRV uses its own temperature value. This is always prone to issues as the TRV is bolted to a radiator!! Tends to make it turn on and off too regularly.

I purchased the Sonoff zigbee room temperature sensors and contacted Sonoff support to see if they would consider enabling a remote sensor in the TRV configuration. No joy!

It turns out it’s really easy using HA automation, so I have shared my automation in the hope that others looking to do the same can simply copy mine. All we need to do is alter the TRVs calibration value automatically by comparing the TRV and room temperatures, using the room as the control value.

I am not very technical, so I am certain lots of you will have a much better solution, but this automation is really simple and works well.

I am using Zigbee2MQTT, a Zigbee USB dongle and the Sonoff TRVZB’s and SNZB-02P room temperature sensors.

The automation includes notifications for debug. These can be removed once running. The conditions are there purely to prevent a double trigger of the event once calibration has been set. Overuse of variables just so you can see what’s what!

So here is my automation YAML:

alias: MasterbedroomTRV_Calibration
description: >-
  When the TRV local temperature changes, reset the calibration based on the
  room stat temperature
trigger:
  - platform: state
    entity_id:
      - climate.masterbedroomtrv
    attribute: current_temperature
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: climate.masterbedroomtrv
        attribute: current_temperature
        above: sensor.masterbedroomsensor_temperature
      - condition: numeric_state
        entity_id: climate.masterbedroomtrv
        attribute: current_temperature
        below: sensor.masterbedroomsensor_temperature
action:
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: >-
        MasterbedroomTRV - radiator temp is {{
        state_attr('climate.masterbedroomtrv', 'current_temperature') }} and
        room temp is {{states('sensor.masterbedroomsensor_temperature') }}
      title: TRV Calibration
  - variables:
      trvtemp: "{{ state_attr('climate.masterbedroomtrv', 'current_temperature') }}"
      trvcalib: "{{ states('number.masterbedroomtrv_local_temperature_calibration') }}"
      roomtemp: "{{ states('sensor.masterbedroomsensor_temperature') }}"
      calibration: "{{ (trvcalib - (trvtemp - roomtemp)) | float | round(2) }}"
      vpayload: "{\"local_temperature_calibration\": {{ calibration }}}"
  - action: mqtt.publish
    metadata: {}
    data:
      retain: false
      topic: zigbee2mqtt/MasterBedroomTRV/set
      payload: "{{ vpayload }}"
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: MasterbedroomTRV calibration updated to {{calibration}}
      title: TRV Calibration
mode: single
4 Likes

This is a fantastic solution. Thank you very much, my long-standing problem has finally been solved:
The TRV was near closing before the room reached the desired temperature, as the TRV internal temperature was higher than the actual room temperature.
But with this solution, my automation now works super well.

I would suggest to add (at least for the sonoff TRV) a limit on the minimum and maximum calibration offset, since when a value lower than -7 or higher than 7 Celsius degrees is applied, the TRV returns an error which is not catched by the automation:

calibration: “{{ ([-7, (trvcalib - (trvtemp - roomtemp)) | float | round(2), 7]|sort)[1] }}”