Closed Jarikk closed 1 year ago
Hey there @emontnemery, @jbouwh, mind taking a look at this issue as it has been labeled with an integration (mqtt
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
mqtt documentation mqtt source (message by IssueLinks)
Seems there's an issue with the value template of the entity. It should be addressed an issue with Zigbee2MQTT.
To get more information you can turn on MQTT debug logging.
You can add this to your configuration.yaml
:
# Example configuration.yaml entry
logger:
default: info
logs:
homeassistant.components.mqtt: debug
Here is the debug message.
Shouldn't this template {{ value_json.program|default("") | truncate(254, True, '', 0) }} handle the case when "value_json.program" is NULL?
2023-08-13 19:53:40.820 DEBUG (MainThread) [homeassistant.components.mqtt.models] Rendering incoming payload '{"child_lock":null,"current_heating_setpoint":23,"deadzone_temperature":null,"heat":"OFF","last_seen":"2023-08-13T19:53:40+03:00","linkquality":51,"local_temperature":26,"local_temperature_calibration":null,"max_temperature_limit":null,"min_temperature_limit":null,"preset":"hold","preset_mode":"hold","program":null,"running_state":"idle","sensor":null,"system_mode":"off"}' with variables {'entity_id': 'sensor.0x60a423fffeb27fa1_program', 'name': 'program', 'this': <template TemplateStateFromEntityId(sensor.0x60a423fffeb27fa1_program)>} with default value 'default' and Template<template=({{ value_json.program|default("") | truncate(254, True, '', 0) }}) renders=0>
Shouldn't this template {{ value_json.program|default("") | truncate(254, True, '', 0) }} handle the case when "value_json.program" is NULL?
H'm that seem weird indeed.
This works in the template debugger.
{% set value_json={"child_lock":null,"current_heating_setpoint":23,"deadzone_temperature":null,"heat":"OFF","last_seen":"2023-08-13T19:53:40+03:00","linkquality":51,"local_temperature":26,"local_temperature_calibration":null,"max_temperature_limit":null,"min_temperature_limit":null,"preset":"hold","preset_mode":"hold","program":null,"running_state":"idle","sensor":null,"system_mode":"off"} %}
{{ value_json.program|default("") | truncate(254, True, '', 0) }}
When I try to reproduce I get (new logging code):
2023-08-13 18:58:10.774 ERROR (MainThread) [homeassistant.components.mqtt.models] TypeError: object of type 'NoneType' has no len() rendering template for entity 'sensor.bedroom_temperature_mqtt_sensor', template: '{{ value_json.program|default('') | truncate(254, True, '', 0) }}', default value: default and payload: {
"child_lock": null,
"current_heating_setpoint": 23,
"deadzone_temperature": null,
"heat": "OFF",
"last_seen": "2023-08-13T19:53:40+03:00",
"linkquality": 51,
"local_temperature": 26,
"local_temperature_calibration": null,
"max_temperature_limit": null,
"min_temperature_limit": null,
"preset": "hold",
"preset_mode": "hold",
"program": null,
"running_state": "idle",
"sensor": null,
"system_mode": "off"
}'
There is the following config inside the MQTT topic "homeassistant/sensor/0x60a423fffeb27fa1/program/config", in case it might be helpful:
{
"availability": [
{
"topic": "zigbee2mqtt_livingroom/bridge/state",
"value_template": "{{ value_json.state }}"
},
{
"topic": "zigbee2mqtt_livingroom/Balcony, thermostat/availability",
"value_template": "{{ value_json.state }}"
}
],
"availability_mode": "all",
"device": {
"identifiers": [
"zigbee2mqtt_0x60a423fffeb27fa1"
],
"manufacturer": "Moes",
"model": "Moes BHT series Thermostat (BHT-002-GCLZB)",
"name": "Balcony, thermostat"
},
"enabled_by_default": true,
"name": "Balcony, thermostat program",
"state_topic": "zigbee2mqtt_livingroom/Balcony, thermostat",
"unique_id": "0x60a423fffeb27fa1_program_zigbee2mqtt_livingroom",
"value_template": "{{ value_json.program|default(\"\") | truncate(254, True, '', 0) }}"
}
I understand, but it is the value template that is not working. The truncate function does not allow None
. The default
filter is not working as program
is not undefined
.
The template should be changed. This should work though:
{{ value_json.program or '' | truncate(254, True, '', 0) }}
As this not an issue with MQTT or Home Assistant please open one for Zigbee2MQTT
Linked PR will address the logging that could be improved. As this issue is addressed for Z2M I'll close it here, as this is not an issue with MQTT or Home Assistant/
The problem
I have my HA log full of identical errors. They appear after receiving an update message from Moes BHT-002-GCLZB Thermostate device connected to Zigbee2Mqtt.
What version of Home Assistant Core has the issue?
core-2023.8.2
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
MQTT
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Additional information
No response