Skip to content

Instantly share code, notes, and snippets.

@jfisbein
Last active December 1, 2024 14:45
Show Gist options
  • Save jfisbein/d7e0fb2e1501235479784179bff460fa to your computer and use it in GitHub Desktop.
Save jfisbein/d7e0fb2e1501235479784179bff460fa to your computer and use it in GitHub Desktop.
blueprint:
name: Calibrate TRV using external sensor
description: Calibrate radiator TRV temperature sensor using an external temperature sensor.
domain: automation
input:
external_temperature_sensor:
name: External Temperature Sensor
description: Temperature sensor with correct temperature, used to calibrate TRV one.
selector:
entity:
filter:
domain: sensor
device_class: temperature
trv_calibration_entity:
name: TRV calibration entity.
description: Calibration entity from the TRV.
selector:
entity:
filter:
domain: number
thermostat_entity:
name: TRV Thermostat entity
selector:
entity:
filter:
domain: climate
variables:
external_temperature_sensor_state: !input external_temperature_sensor
trv_calibration_entity_state: !input trv_calibration_entity
thermostat_entity_state: !input thermostat_entity
trigger:
- trigger: state
entity_id:
- !input external_temperature_sensor
action:
- if:
- condition: template
value_template: >-
{% set current_calibration = states(trv_calibration_entity_state) | int %}
{% set trv_calibrated = state_attr(thermostat_entity_state, 'current_temperature') |int %}
{% set th_real = states(external_temperature_sensor_state) | round(2) %}
{% set trv_real = trv_calibrated-current_calibration %}
{% set new_calibration = (th_real-trv_real) | round(0) %}
{% set min_calibration = state_attr(trv_calibration_entity_state, 'min') %}
{% set max_calibration = state_attr(trv_calibration_entity_state, 'max') %}
{% set new_calibration = max(new_calibration, min_calibration) %}
{% set new_calibration = min(new_calibration, max_calibration) %}
{{ new_calibration != current_calibration }}
then:
- action: number.set_value
target:
entity_id: !input trv_calibration_entity
data:
value: >-
{% set current_calibration = states(trv_calibration_entity_state) | int %}
{% set trv_calibrated = state_attr(thermostat_entity_state, 'current_temperature') |int %}
{% set th_real = states(external_temperature_sensor_state) | round(2) %}
{% set trv_real = trv_calibrated-current_calibration %}
{% set new_calibration = (th_real-trv_real) | round(0) %}
{% set min_calibration = state_attr(trv_calibration_entity_state, 'min') %}
{% set max_calibration = state_attr(trv_calibration_entity_state, 'max') %}
{% set new_calibration = max(new_calibration, min_calibration) %}
{% set new_calibration = min(new_calibration, max_calibration) %}
{{ new_calibration }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment