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 19, 2024

The script is excellent, but errors occasionally appear in the logs.

Z2M

[2024-11-19 14:13:47] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 15:06:59] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 16:01:48] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 16:53:41] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 17:44:17] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 18:38:59] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 19:30:00] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 20:22:39] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 21:14:27] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 22:05:04] error: 	zhc: Failed to apply calibration to 'device_temperature': 'device_temperature_calibration' is not a number, got string ()
[2024-11-19 22:24:50] error: 	z2m: MQTT error: Keepalive timeout
[2024-11-19 22:24:51] error: 	z2m: Not connected to MQTT server!
[2024-11-19 22:24:58] error: 	z2m: MQTT error: connect ENETUNREACH 192.168.1.111:1883
[2024-11-19 22:25:01] error: 	z2m: Not connected to MQTT server!
[2024-11-19 22:25:03] error: 	z2m: No converter available for 'set' 'local_temperature' (25.53)
[2024-11-19 22:25:03] error: 	z2m: No converter available for 'sensor_temp' (24.71)
[2024-11-19 22:25:03] error: 	z2m: Entity 'climate.34324324324324' is unknown
[2024-11-19 22:25:15] error: 	z2m: Exception while calling fromZigbee converter: Value: '2' not found in: [0, 1]}

@niklaszerozero
Copy link
Author

I'm sorry but I cannot replicate this error.
I have found a few similar issues where the device configuration was causing this.
Could you verify or send me your device configuration from the inside of configuration.yaml (/homeassistant/zigbee2mqtt/configuration.yaml)?

@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