I have added line template: !include templates.yaml
to /homeassistant/configuration.yaml and created the file templates.yaml.
My template sensor is
- sensor:
- name: "Tuya last reported"
unique_id: sensor.tuya_last_reported
icon: mdi:trending-up
state: >-
{% set sensorIn = "tuya_01_tz3000_fie1dpkm_ts0201_temperature" %}
{% set lastReportDate = states.sensor[sensorIn].last_reported | string %}
{% set lastReportChangedDate = states.sensor[sensorIn].last_changed | string %}
{{lastReportDate}}
{{lastReportChangedDate}}
lastReportDate
and lastReportChangedDate
are always the same. I have enabled debug mode in ZHA and I can see from /homeassistant/home-assistant.log that my sensor is sending rerorts.
2024-04-20 08:43:11.015 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2074))])
2024-04-20 08:43:11.020 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2074]
2024-04-20 08:43:23.673 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2075))])
2024-04-20 08:43:23.679 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2075]
!! lastReportDate and lastReportChangedDate are update to 2024-04-20 05:43:23.681579+00:00
2024-04-20 08:43:34.015 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2077))])
2024-04-20 08:43:34.022 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2077]
2024-04-20 08:43:52.021 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2077))])
2024-04-20 08:43:52.027 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2077]
2024-04-20 08:44:04.317 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2078))])
2024-04-20 08:44:04.321 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2078]
2024-04-20 08:44:10.753 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2077))])
2024-04-20 08:44:10.758 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2077]
2024-04-20 08:44:19.026 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2079))])
2024-04-20 08:44:19.031 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2079]
2024-04-20 08:44:25.953 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2081))])
2024-04-20 08:44:25.960 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2081]
2024-04-20 08:44:33.039 DEBUG (MainThread) [zigpy.zcl] [0xC201:1:0x0402] Decoded ZCL frame: TemperatureMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=int16s, value=2079))])
2024-04-20 08:44:33.044 DEBUG (MainThread) [homeassistant.components.zha.core.cluster_handlers] [0xC201:1:0x0402]: cluster_handler[temperature] attribute_updated - cluster[Temperature Measurement] attr[measured_value] value[2079]
!! lastReportDate and lastReportChangedDate are stil 2024-04-20 05:43:23.681579+00:00. No change.