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

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?

@Neil_Brownlee, awesome, thanks! There were just few small problems, temperature and climate_device were used, instead of temp_sensor and valve. :slight_smile:

Fixed it here: https://gist.github.com/mmackowiak/84092d0863d3b7f6330b96bd64fcb267

none of the version above are working here also using the Tuya ts0601. and a Xiaomi WSDCGQ11LM. temp sensor, but I down see the temperature of the valve changing after creating an automaton with this blueprints, I’ve tried all versions above.

I don’t understand. You are saying it’s not working but you can see temperature changing? So which is it?
Check if your “local temperature calibration” attribute is changing

I think it was a typo I don’t see the temperature changing on the ts0601 neither on Lovelace ,

also the attribute is not changing

this is in my automations.yaml

use_blueprint:
path: test2.yaml
input:
external_temp: sensor.kitchen_temperature
climate_name: climate.heater_kitchen
ieeeaddressoftrv: ‘0x60a423fffe9f3990’