Sync TRV with external tempature sensor

I had some issues with my MOES TRV Zigbee thermostat and this will fix the tempeture missmatch:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Source code:

Have fun!

(I have moved on to better_thermostat so I am not updating nor using this myself anymore. Feel free to improve. I will try and maintain it!)

3 Likes

Hi,
after creating automatization I got error:
Zigbee2MQTT:error 2021-04-16 16:46:21: Entity ‘!input ieeeaddressoftrv’ is unknown

My automatization after creation from blueprint:
alias: Sync TRV tempature - radiator_living_room_1
description: Living room temperature Sync
use_blueprint:
path: bruvv/sync_trv_with_external_temp_sensor.yaml
input:
climate_name: climate.radiator_living_room_1
external_temp: sensor.broadlink_living_room_temperature
ieeeaddressoftrv: ‘0x847127fffe1f2f92’

Do you have any idea how to fix it?

I have no idea why I didn’t receive a notification, sorry for the uber late reply. But you should not use the ' in your ieee address. Remove it and it will work.

Hi,

I made some revisions to the blueprint. Only calls the device when the temp change actually requires it - instead of calling it for no reason. I also changed the calculation logic. Hope this is ok.

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 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:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ states(temperature) != 'unavailable' }}"
    - condition: template
      value_template: "{{ states(temperature) != '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/{{ 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'))}}
  - delay: 5
mode: single
max_exceeded: silent
3 Likes

Thanks Neil!

I do not see a change in the trigger part only that you made the time shorter that it triggers. So it will call it more often now. Other than that you also removed the reset that resets the local calibration to 0. This was needed because sometimes it was adding the numbers instead of calculating it from 0… Could you adjust it ? Than I can merge it. I will also change to GitHub so people can do pull requests.
I do really like the added condition check btw ! So if you can adjust it I can merge it :slight_smile:

Hi,

Although it will trigger on a state change it won’t do anything else if there’s nothing to do. My maths doesn’t do the reset to 0 as if you look there’s no way it can be “out” :slight_smile:

Basically I’m taking the (current external temp - zigbee temp) and then taking off the current adjustment. As it’s always using a set starting point it doesn’t ever need zeroing.

Added a 15 second “hold” on the state so it doesn’t trigger multiple times (because it was!)

2 Likes

Thanks Neil for the explanation. Last time I debugged this the firmware itself did the weird calculation but since I didn’t change much since April I am unsure if anything has changed. I will check it later this week!

Updated with your fixes @Neil_Brownlee thanks again

@Neil_Brownlee Hi, I have a problem with the resulting temperature. Stores as cores, but the value is high compared to an external sensor.

Payload1

Why do you have Local Temperature Calibration set to 87? That adds 87 to the curent temperature. You should set that to 0.

Your calibration needs to be set to 0 or close at the start.

The temperature is recorded from an external sensor, but the temperature is of course other than 87. And it should mainly be the difference between the external sensor and temperature measured by TRV.

I have the same or at least similar issue with my saswell trvs and an external temperature sensor. when running the automation, the offset gets set to something like 4294967285 degrees celsius - which the produces the error

2021-11-19 22:01:20 ERROR (MainThread) [homeassistant.components.mqtt.number] Invalid value for number.thermostat_arbeitszimmer_local_temperature_calibration: 4294967285 (range -6.0 - 6.0)

I dont really know what the issue is here and hope someone can help …

@Lukacs_Attila the problem could be the variable name “current_temperature”. In you setting is named “local_temperature”. I suggest to change the blue print from “current_temperature” to “local_temperature” and try again.

Hi Neil,
i foud that there is the need to trigger the action not only when the remote sensor change temp. but also the TRV internal temp change. For istance due to the radiator heating up while the remote sensor still does not read any change. I tried adding in the trigger the climate.trv but it is not working.

trigger:

  • platform: state
    entity_id:
    • !input ‘external_temp’
    • !input ‘climate_name’

Any ideas?
thanks and best regards.

I made some corrections to avoid ‘not found converter for local_temperature_calibration’ error.

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 Thermostat
description: ''

variables:
  target_device: !input 'ieeeaddressoftrv'
  climate_device: !input 'climate_name'
  external_temperature: !input 'external_temp'
  adjust: "{{state_attr(climate_device, 'current_temperature')}}"
trigger:
  - platform: state
    entity_id: !input 'external_temp'
    for:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - platform: state
    entity_id: !input 'climate_name'
    for:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ states(temperature) != 'unavailable' }}"
    - condition: template
      value_template: "{{ states(temperature) != 'unknown' }}"
action:      
  - service: mqtt.publish
    data_template:
      topic: zigbee2mqtt/{{ target_device }}/set/local_temperature_calibration
      payload_template: >-
        {{states(external_temperature)|float(0) | round(1,'half') - state_attr(climate_device,'local_temperature')|float(0) | round(1, 'half') }}
  - delay: 5
mode: single
max_exceeded: silent

Am I right to assume this would not be possible when using deconz?

You are right. It is not possible to change local_temperature_calibration over deconz.

awesome addition(s)! some nice edits I have pushed them all. Thanks

1 Like