zigbee2mqtt
zigbee2mqtt copied to clipboard
Too large a device state causes Home Assistant to crash
What happened?
Hello, I've a problem with a thermostat Moes BHT-002-GBLZBW. It has quite long state which lead to HA crash, because HA expects state not longer than 255 symbols.
I've filed an issue to HA, but they said it's problem in zigbee2mqtt: https://github.com/home-assistant/core/issues/103141
As I can see there was a try to fix this issue, but without success: https://github.com/Koenkk/zigbee2mqtt/issues/16460#issuecomment-1537341464
truncate
does not work as expected.
May be the reason in true
written in lower case here: https://github.com/Koenkk/zigbee2mqtt/blob/311ea070b167ddc6d8de1f8922aed0d8b38025d7/lib/extension/homeassistant.ts#L931C50-L931C50?
What did you expect to happen?
No response
How to reproduce it (minimal and precise)
No response
Zigbee2MQTT version
1.33.2
Adapter firmware version
20220219
Adapter
Egony Ebyte E72-2G4M20S1E
Debug log
No response
I am facing the follwoing error with HA 2023.12.1 and Z2M 1.34.0-1 which might be related to the issue you are describing:
Logger: homeassistant.helpers.entity
Source: helpers/entity.py:872
First occurred: 17:33:59 (203 occurrences)
Last logged: 17:38:59
Failed to set state for sensor.moes_bht_thermostat_dachstudio_program, fall back to unknown
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 872, in _async_write_ha_state
hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 1732, in async_set
state = State(
^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1309, in __init__
validate_state(state)
File "/usr/src/homeassistant/homeassistant/core.py", line 193, in validate_state
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state with length 941. State max length is 255 characters.
Hello I have the same error but without crash since the 1.30.0 update I'm now on 2023.12.1 HAOS and 1.34.0-1 z2mqtt and always the same problem Logger: homeassistant.helpers.entity Source: helpers/entity.py:872 First occurred: 10:33:30 (100 occurrences) Last logged: 14:20:09
Failed to set state for sensor.thermostat_program, fall back to unknown Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 872, in _async_write_ha_state hass.states.async_set( File "/usr/src/homeassistant/homeassistant/core.py", line 1732, in async_set state = State( ^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 1309, in init validate_state(state) File "/usr/src/homeassistant/homeassistant/core.py", line 193, in validate_state raise InvalidStateError( homeassistant.exceptions.InvalidStateError: Invalid state with length 930. State max length is 255 characters.
` I can't delete and reinstall the thermostat because i'm not on place... If you have an idea...
I have similar issue. As a workaround i filtered "program" from publishing in payload.
@jbouwh in https://github.com/home-assistant/core/issues/103141#issuecomment-1791032698 you mention that truncate
doesn't work for the value_template
, why is this the case? I added this because HA cannot handle too large states.
This is some time ago. AFAIN this is not about attributes, but the state it self. May the truncate calculation is not accurate enough to calculate the actual size after truncating. By in general, states sould be small, any attributes should be static most of the time
@oleynikandrey
truncate does not work as expected. May be the reason in true written in lower case here:
changed this now, can you try and see if this has been fixed?
Changes will be available in the dev branch in a few hours from now.
@Koenkk I just tested latest z2m release (1.35.1) with HA 2024.1.2 and still have these in HA logs:
2024-01-11 19:02:11.693 ERROR (MainThread) [homeassistant.helpers.entity] Failed to set state for sensor.kitchen_thermostat_program, fall back to unknown Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1125, in _async_write_ha_state hass.states.async_set( File "/usr/src/homeassistant/homeassistant/core.py", line 1807, in async_set state = State( ^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 1384, in init validate_state(state) File "/usr/src/homeassistant/homeassistant/core.py", line 204, in validate_state raise InvalidStateError( homeassistant.exceptions.InvalidStateError: Invalid state with length 930. State max length is 255 characters.
I think this best thing to do is to disable this entity in HA until the `truncate is fixed.
changed this now, can you try and see if this has been fixed?
No it doesn't fix the problem
In https://github.com/home-assistant/core/issues/103141#issuecomment-1793439289 I suggested solution, will that not work?
Maybe Z2M can split big state message into separate messages? Each of which will be less than 255 characters long...
PS I use autodiscovering feature and can't create config for every sensor... The HA team says that the size limitation of the state was introduced because performance reasons and does not want to remove it.