Skip to content

Instantly share code, notes, and snippets.

@niklaszerozero
Last active November 27, 2024 09:16
Show Gist options
  • Save niklaszerozero/80a5d880660b127b7fe461ebfac9ddf0 to your computer and use it in GitHub Desktop.
Save niklaszerozero/80a5d880660b127b7fe461ebfac9ddf0 to your computer and use it in GitHub Desktop.
When the local temperature of the TRV changes, update the calibration using an external temperature sensor.
blueprint:
name: Sonoff TRVZB Calibration
author: Niklas Vlach
description: "
When the local temperature of the TRV changes, update the calibration using an external temperature sensor.
**Version**: 0.0.3
"
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
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id:
- !input climate_entity
attribute: current_temperature
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: !input climate_entity
attribute: current_temperature
above: !input temperature_sensor_entity
- condition: numeric_state
entity_id: !input climate_entity
attribute: current_temperature
below: !input temperature_sensor_entity
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') }}"
trvcalib: "{{ states(local_temperature_calibration_entity) }}"
roomtemp: "{{ states(temperature_sensor_entity) }}"
calibration: "{{ ([-7, (trvcalib - (trvtemp - roomtemp)) | float | round(2), 7] | sort)[1] }}"
- action: number.set_value
target:
entity_id: !input local_temperature_calibration_entity
data:
value: "{{calibration}}"
@EMAKASS
Copy link

EMAKASS commented Nov 27, 2024

Excuse me, there was a similar script generated by ChatGPT, which was triggered after HA was restarted.

The only log entry related to your script is:
error: zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment