Tuya radiator valve (TS0601) calibration from external sensor (via zigbee2mqtt)

TuYa radiator valves measure temperate on themself, which gives inaccurate results.
TS0601_thermostat
This blueprint allow to calibrate them to have same (± ~0.5C) temperature, as external temperature sensor using MQTT message

blueprint:
  name: Temperature Calibration
  description: Temperature calibration for Zigbee valve TS0601, according to external temperature sensor
  domain: automation
  input:
    valve:
      name: Smart Valve
      selector:
        entity:
          domain: climate
    temp_sensor:
      name: Temperature Sensor
      selector:
        entity:
          domain: sensor
          device_class: temperature
          
variables:
  valve: !input "valve"
  temp_sensor: !input "temp_sensor"

trigger: 
  - platform: time_pattern
    minutes: "/10"
  - platform: template
    value_template: "{{ ( state_attr(valve, 'current_temperature')|float - states(temp_sensor)|float)|abs > 0.25 }}"
    for: '00:00:02'
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unavailable' }}"
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unknown' }}"
action:
  - service: mqtt.publish
    data_template:
      topic: "zigbee2mqtt/{{state_attr(valve,'friendly_name')}}/set/local_temperature_calibration"
      payload_template: >-
        {{(state_attr(valve,'local_temperature_calibration')|float -
             state_attr(valve, 'current_temperature')|float +
            states(temp_sensor)|float + 128)|round(1,'half')}}

Tested on TS0601 radiator valve with thermostat, but most probably will work on similar products from TuYa

9 Likes

Is it posible to use number of valves on the same automation?

Since every valve will have its own difference with temperature sensor, you will need to create automation for each valve separately.

I got it, thanks.

Sync TRV with external tempature sensor this is the same

1 Like

Yes, looks like that

Hi,

Getting my logs filled with this?

Logger: homeassistant.helpers.template
Source: helpers/template.py:1624
First occurred: 09:50:51 (20 occurrences)
Last logged: 09:53:51

Template variable error: 'valve' is undefined when rendering '{{ ( state_attr(valve, 'current_temperature')|float - states(temp_sensor)|float)|abs > 0.25 }}'

I have the same issue. What is funny - the automation itself is working.

I am not sure if that’s the issue, but I think there shouldn’t be “” around names in variable definition (at least there are none in official docs). So the code should be:

variables:
  valve: !input valve
  temp_sensor: !input temp_sensor

I wasn’t able to test if that fixes things, as I currently have some major database problems and am focused on resolving them.

Hi,

That made no difference. It’s very odd. Warnings are great but … they fill the logs! :frowning:

Taking out the “” and also making this change seems to have made it quieter :slight_smile:

value_template: "{{ ( state_attr('valve', 'current_temperature')|float - states('temp_sensor')|float)|abs > 0.25 }}"
1 Like

Did this happened after update? What version of HA are you using?
Did you tried this version of same blueprint?
Sync TRV with external tempature sensor

I also revised the logic - works better for me :slight_smile:

{{states(temp_sensor)|float(0) | round(1,'half') - (state_attr(valve,'current_temperature')|float(0) | round(1, 'half') - state_attr(valve,'local_temperature_calibration')|float(0) | round(1, 'half'))}}

I don’t like the logic on that one. If I read it correctly it only triggers whenever the external sensor keeps its state for 15 minutes straight. My sensors tend to oscilate +/- 0.1C sometimes. And it will also prevent it from triggering when the room is beeing heated, it will only calibrate once the temperature is stable.

I’m using 2021.10.3, can’t tell how it was before the update since I’ve only just starting using this blueprint.

I gave up on 0.1 tbh. It kept over triggering the TRV and battery life suffered. I have one I wrote based on the bruvv one. I have mixed them together with my own logic and now it seems much better. No moaning about already running automation and now I have also fixed the errors with this one :slight_smile:

I can share my complete blueprint if anyone is interested.

1 Like

This one will react to a change that stays for 30’s

blueprint:
  name: Sync TRV tempature
  description: Sync external tempature sensor with TRV tempature
  domain: automation
  input:
    ieeeaddressoftrv:
      name: IEEE Address
      description: This is the address of the TRV found in your zigbee database example 0x459877fffe1f2e83
    external_temp:
      name: Select the external temp sensor
      description: This will be your external temp sensor
      selector:
        entity:
          domain: sensor
          device_class: temperature
    climate_name:
      name: Climate entry
      description: This will be the TRV it self in home assistant
      selector:
        entity:
          domain: climate 
alias: Calibrate badkamer_thermostat
description: ''

variables:
  target_device: !input 'ieeeaddressoftrv'
  climate_device: !input 'climate_name'
  temperature: !input 'external_temp'
  adjust: "{{state_attr(climate_device, 'current_temperature')}}"
trigger:
  - platform: state
    entity_id: !input 'external_temp'
    for: '00:00:30'
condition: []
action:
  - service: mqtt.publish
    data_template:
      topic: zigbee2mqtt/{{ target_device }}/set/local_temperature_calibration
      payload_template: >-
        {{states(temperature)|float(0) | round(1,'half') - (state_attr(climate_device,'current_temperature')|float(0) | round(1, 'half') - state_attr(climate_device,'local_temperature_calibration')|float(0) | round(1, 'half'))}}
mode: single
1 Like

This one will check every 10 minutes

blueprint:
  name: Temperature Calibration
  description: Temperature calibration for Zigbee valve TS0601, according to external temperature sensor
  domain: automation
  input:
    valve:
      name: Smart Valve
      selector:
        entity:
          domain: climate
    temp_sensor:
      name: Temperature Sensor
      selector:
        entity:
          domain: sensor
          device_class: temperature
          
variables:
  valve: !input valve
  temp_sensor: !input temp_sensor

trigger: 
  - platform: time_pattern
    minutes: "/10"
  - platform: template
    value_template: "{{ ( state_attr('valve', 'current_temperature')|float(0) - states('temp_sensor')|float(0))|abs > 0.25 }}"
    for: '00:00:02'
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unavailable' }}"
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unknown' }}"
action:
  - service: mqtt.publish
    data_template:
      topic: "zigbee2mqtt/{{state_attr(valve,'friendly_name')}}/set/local_temperature_calibration"
      payload_template: >-
        {{states(temp_sensor)|float(0) | round(1,'half') - (state_attr(valve,'current_temperature')|float(0) | round(1, 'half') - state_attr(valve,'local_temperature_calibration')|float(0) | round(1, 'half'))}}
1 Like

Just my 5cts, though I did it with node-red, I can share the idea here: to avoid useless updates of calibrations which drawn battery, I also trigger action on both internal and external temperature changes (no matter if 0.1C difference), but I do compare newly calculated calibration (rounded as well to closest 0.5) with current calibration value, if same then I just skip the update… not more than 15 updates per day in my case, and all fully justified…

You are probably be able to add this to your condition

1 Like

Can you share your code please?

Revised with check for change (i.e. don’t send if difference is still 0) - but still uses the timer.

blueprint:
  name: Temperature Calibration
  description: Temperature calibration for Zigbee valve TS0601, according to external temperature sensor
  domain: automation
  input:
    valve:
      name: Smart Valve
      selector:
        entity:
          domain: climate
    temp_sensor:
      name: Temperature Sensor
      selector:
        entity:
          domain: sensor
          device_class: temperature
          
variables:
  valve: !input valve
  temp_sensor: !input temp_sensor

trigger: 
  - platform: time_pattern
    minutes: "/10"
  - platform: template
    value_template: "{{ ( state_attr('valve', 'current_temperature')|float(0) - states('temp_sensor')|float(0))|abs > 0.25 }}"
    for: '00:00:02'
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unavailable' }}"
    - condition: template
      value_template: "{{ states(temp_sensor) != 'unknown' }}"
    - condition: template
      value_template: "{{states(temperature)|float(0) | round(1,'half') - (state_attr(climate_device,'current_temperature')|float(0) | round(1, 'half') - state_attr(climate_device,'local_temperature_calibration')|float(0) | round(1, 'half')) != state_attr(climate_device, 'local_temperature_calibration')|float(0) | round(1, 'half')}}"
action:
  - service: mqtt.publish
    data_template:
      topic: "zigbee2mqtt/{{state_attr(valve,'friendly_name')}}/set/local_temperature_calibration"
      payload_template: >-
        {{states(temp_sensor)|float(0) | round(1,'half') - (state_attr(valve,'current_temperature')|float(0) | round(1, 'half') - state_attr(valve,'local_temperature_calibration')|float(0) | round(1, 'half'))}}

A version that checks when the external sensor changes state can be found here : Sync TRV with external tempature sensor

2 Likes

looks quite nice.
not a fan of events?