Skip to content

Instantly share code, notes, and snippets.

@EMAKASS
Last active August 29, 2025 13:29
Show Gist options
  • Select an option

  • Save EMAKASS/9c7a5a19949bddd98c6813d00629ec2f to your computer and use it in GitHub Desktop.

Select an option

Save EMAKASS/9c7a5a19949bddd98c6813d00629ec2f to your computer and use it in GitHub Desktop.
Sonoff TRVZB Calibration v4 - AI
blueprint:
name: Sonoff TRVZB Calibration
author: Niklas Vlach (правка: GPT-5)
description: >
Когда температура TRV или внешнего датчика изменяется, обновлять калибровку
с использованием внешнего датчика температуры.
**Version**: 0.0.6 (добавлен порог tolerance)
source_url: https://gist.github.com/NiklasZeroZero/80a5d880660b127b7fe461ebfac9ddf0
domain: automation
input:
climate_entity:
name: Climate Entity
description: The climate entity published by the Sonoff TRVZB
selector:
entity:
filter:
- domain: climate
multiple: false
local_temperature_calibration_entity:
name: Local Temperature Calibration Entity
description: The temperature calibration entity published by the Sonoff TRVZB
selector:
entity:
filter:
- domain: number
multiple: false
temperature_sensor_entity:
name: Temperature Sensor Entity
description: The external room temperature sensor entity.
selector:
entity:
filter:
- domain: sensor
multiple: false
tolerance:
name: Temperature difference tolerance
description: >
Минимальная разница между TRV и датчиком (в °C), при которой
будет выполняться калибровка.
default: 0.2
selector:
number:
min: 0.1
max: 2.0
step: 0.1
unit_of_measurement: °C
mode: single
max_exceeded: silent
trigger:
# Срабатывает если обновился TRV
- platform: state
entity_id: !input climate_entity
attribute: current_temperature
# Срабатывает если обновился внешний датчик
- platform: state
entity_id: !input temperature_sensor_entity
condition:
# Только если разница больше tolerance
- condition: template
value_template: >
{% set trv = state_attr(climate_entity, 'current_temperature') | float(0) %}
{% set room = states(temperature_sensor_entity) | float(0) %}
{% set tol = (tolerance | float(0)) %}
{{ (trv - room) | abs > tol }}
action:
- variables:
climate_entity: !input climate_entity
local_temperature_calibration_entity: !input local_temperature_calibration_entity
temperature_sensor_entity: !input temperature_sensor_entity
trvtemp: "{{ state_attr(climate_entity, 'current_temperature') | float(0) }}"
trvcalib: "{{ states(local_temperature_calibration_entity) | float(0) }}"
roomtemp: "{{ states(temperature_sensor_entity) | float(0) }}"
calibration: >-
{{
([-7,
(trvcalib - (trvtemp - roomtemp)) | float | round(2),
7] | sort)[1]
}}
- service: number.set_value
target:
entity_id: !input local_temperature_calibration_entity
data:
value: "{{ calibration }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment