Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT InvalidStateError with length 320 #117861

Closed
ghost opened this issue May 21, 2024 · 13 comments · Fixed by #118006
Closed

MQTT InvalidStateError with length 320 #117861

ghost opened this issue May 21, 2024 · 13 comments · Fixed by #118006

Comments

@ghost
Copy link

ghost commented May 21, 2024

The problem

I noticed an issue in my log files regarding the following: homeassistant.exceptions.InvalidStateError: Invalid state with length 320. State max length is 255 characters. This is in regards to a ir blaster device (ZS06) using MQTT. The device does function properly even though I receive this problem but I wanted to see a resolution can be found to eliminate the error message that occurs any time i restart my HA.

The complete error message is listed below under the log file section.

What version of Home Assistant Core has the issue?

2024.5.4

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

https://www.home-assistant.io/integrations/mqtt/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-05-21 15:56:30.710 ERROR (MainThread) [homeassistant.helpers.entity] Failed to set state for sensor.0x385cfbfffe3e3594_learned_ir_code, fall back to unknown
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1203, in _async_write_ha_state
    hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2310, in async_set
    state = State(
            ^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1788, in __init__
    validate_state(state)
  File "/usr/src/homeassistant/homeassistant/core.py", line 228, in validate_state
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state with length 320. State max length is 255 characters.

Additional information

No response

@home-assistant
Copy link

Hey there @emontnemery, @jbouwh, @bdraco, 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!

Code owner commands

Code owners of mqtt can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign mqtt Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mqtt documentation
mqtt source
(message by IssueLinks)

@jbouwh
Copy link
Contributor

jbouwh commented May 21, 2024

Can you share the MQTT info (if possible in JSON format). You can find this at the MQTT device info page.
The config topic and payload, a state payload would be very helpful.

@ghost
Copy link
Author

ghost commented May 21, 2024

MQTT discovery data:
Topic: homeassistant/switch/0x385cfbfffe3e3594/switch/config
availability:

  • topic: zigbee2mqtt/bridge/state
    command_topic: zigbee2mqtt/IR Remote Control/set
    device:
    identifiers:
    • zigbee2mqtt_0x385cfbfffe3e3594
      manufacturer: TuYa
      model: Universal smart IR remote control (ZS06)
      name: IR Remote Control
      via_device: zigbee2mqtt_bridge_0x00124b0029e84ce5
      json_attributes_topic: zigbee2mqtt/IR Remote Control
      name: null
      object_id: ir_remote_control
      origin:
      name: Zigbee2MQTT
      sw_version: 1.37.1
      support_url: https://www.zigbee2mqtt.io
      payload_off: 'OFF'
      payload_on: 'ON'
      state_topic: zigbee2mqtt/IR Remote Control
      unique_id: 0x385cfbfffe3e3594_switch_zigbee2mqtt
      value_template: '{{ value_json.learn_ir_code }}'
      platform: mqtt

Subscribed topics:
zigbee2mqtt/bridge/state
1 most recently received message(s)
Received 3:55:55 PM
QoS: 0, Retained
Payload: online

Is this what you needed? There is a bit more but I think this was what you were asking for specifically. Let me know

@jbouwh
Copy link
Contributor

jbouwh commented May 21, 2024

No, I need the config for the entity that causes the failure (in JSON format, there is a switch), the config is probably the correct one, and the state payload (at topic zigbee2mqtt/IR Remote Control) for this entity causing the issue. The bridge state is not relavat for this issue. Did you open an issue for Zigbee2MQTT as you opened an issue at the Home Assistant Core repo.

@ghost
Copy link
Author

ghost commented May 21, 2024

{
"home_assistant": {
"installation_type": "Home Assistant Container",
"version": "2024.5.4",
"dev": false,
"hassio": false,
"virtualenv": false,
"python_version": "3.12.2",
"docker": true,
"arch": "x86_64",
"timezone": "America/New_York",
"os_name": "Linux",
"os_version": "6.6.13+bpo-amd64",
"run_as_root": true
},
"custom_components": {},
"integration_manifest": {
"domain": "mqtt",
"name": "MQTT",
"codeowners": [
"@emontnemery",
"@jbouwh",
"@bdraco"
],
"config_flow": true,
"dependencies": [
"file_upload",
"http"
],
"documentation": "https://www.home-assistant.io/integrations/mqtt",
"iot_class": "local_push",
"quality_scale": "platinum",
"requirements": [
"paho-mqtt==1.6.1"
],
"is_built_in": true
},
"data": {
"connected": true,
"mqtt_config": {
"broker": "10.0.0.10",
"port": 1883,
"username": "REDACTED",
"password": "REDACTED",
"discovery": true,
"discovery_prefix": "homeassistant",
"birth_message": {
"topic": "homeassistant/status",
"payload": "online",
"qos": 0,
"retain": false
},
"will_message": {
"topic": "homeassistant/status",
"payload": "offline",
"qos": 0,
"retain": false
}
},
"device": {
"id": "fa93e33dba2cff61951f3ed3b780369e",
"name": "IR Remote Control",
"name_by_user": null,
"disabled": false,
"disabled_by": null,
"entities": [
{
"device_class": null,
"disabled_by": null,
"disabled": false,
"entity_category": null,
"entity_id": "switch.0x385cfbfffe3e3594",
"icon": null,
"original_device_class": null,
"original_icon": null,
"state": {
"entity_id": "switch.0x385cfbfffe3e3594",
"state": "unknown",
"attributes": {
"learn_ir_code": null,
"learned_ir_code": "BUojkBErAuALAQN9BisCwAFAC+AHAwNeAisCwBPgAwFAE8ABwAtAB4ADQDUDKwJ9BoADAysCXgJACwX3nUojygiAB+ABjwJeAivgAAEFXgJ9Bl4CQAcAKyABAX0G4AkDBSsCXgJ9BoADACvgAAEBXgJAEwAroAEJfQYrAisCXgJ9BkADACtgBwMrAl4C4AcL4AWPA14CKwJAA+ADAQZeAn0GXgIroAEBfQbgCQMFKwJeAn0GQAMBKwLgAQFADwJeAiugAQN9BisCQAECfQZeIANABwErAkABAX0GQA8CXgIrIAELfQYrAvedSiPKCCsC",
"linkquality": 114,
"friendly_name": "IR Remote Control"
},
"last_changed": "2024-05-21T12:55:55.700958+00:00",
"last_reported": "2024-05-21T12:56:30.710548+00:00",
"last_updated": "2024-05-21T12:56:30.710548+00:00"
},
"unit_of_measurement": null
},
{
"device_class": null,
"disabled_by": null,
"disabled": false,
"entity_category": null,
"entity_id": "sensor.0x385cfbfffe3e3594_learned_ir_code",
"icon": null,
"original_device_class": null,
"original_icon": null,
"state": {
"entity_id": "sensor.0x385cfbfffe3e3594_learned_ir_code",
"state": "unknown",
"attributes": {},
"last_changed": "2024-05-21T12:55:55.701251+00:00",
"last_reported": "2024-05-21T12:56:30.821881+00:00",
"last_updated": "2024-05-21T12:56:30.821881+00:00"
},
"unit_of_measurement": null
},
{
"device_class": null,
"disabled_by": null,
"disabled": false,
"entity_category": null,
"entity_id": "text.0x385cfbfffe3e3594_ir_code_to_send",
"icon": null,
"original_device_class": null,
"original_icon": null,
"state": {
"entity_id": "text.0x385cfbfffe3e3594_ir_code_to_send",
"state": "unknown",
"attributes": {
"mode": "text",
"min": 0,
"max": 255,
"pattern": null,
"learn_ir_code": null,
"learned_ir_code": "BUojkBErAuALAQN9BisCwAFAC+AHAwNeAisCwBPgAwFAE8ABwAtAB4ADQDUDKwJ9BoADAysCXgJACwX3nUojygiAB+ABjwJeAivgAAEFXgJ9Bl4CQAcAKyABAX0G4AkDBSsCXgJ9BoADACvgAAEBXgJAEwAroAEJfQYrAisCXgJ9BkADACtgBwMrAl4C4AcL4AWPA14CKwJAA+ADAQZeAn0GXgIroAEBfQbgCQMFKwJeAn0GQAMBKwLgAQFADwJeAiugAQN9BisCQAECfQZeIANABwErAkABAX0GQA8CXgIrIAELfQYrAvedSiPKCCsC",
"linkquality": 114,
"assumed_state": true,
"friendly_name": "IR Remote Control Ir code to send"
},
"last_changed": "2024-05-21T12:55:55.700661+00:00",
"last_reported": "2024-05-21T12:56:30.710470+00:00",
"last_updated": "2024-05-21T12:56:30.710470+00:00"
},
"unit_of_measurement": null
}
]
},
"mqtt_debug_info": {
"entities": [
{
"entity_id": "switch.0x385cfbfffe3e3594",
"subscriptions": [
{
"topic": "zigbee2mqtt/bridge/state",
"messages": [
{
"payload": "online",
"qos": 0,
"retain": 1,
"time": "2024-05-21T12:55:55.699740+00:00",
"topic": "zigbee2mqtt/bridge/state"
}
]
},
{
"topic": "zigbee2mqtt/IR Remote Control",
"messages": [
{
"payload": "{"learn_ir_code":null,"learned_ir_code":"BUojkBErAuALAQN9BisCwAFAC+AHAwNeAisCwBPgAwFAE8ABwAtAB4ADQDUDKwJ9BoADAysCXgJACwX3nUojygiAB+ABjwJeAivgAAEFXgJ9Bl4CQAcAKyABAX0G4AkDBSsCXgJ9BoADACvgAAEBXgJAEwAroAEJfQYrAisCXgJ9BkADACtgBwMrAl4C4AcL4AWPA14CKwJAA+ADAQZeAn0GXgIroAEBfQbgCQMFKwJeAn0GQAMBKwLgAQFADwJeAiugAQN9BisCQAECfQZeIANABwErAkABAX0GQA8CXgIrIAELfQYrAvedSiPKCCsC","linkquality":114}",
"qos": 0,
"retain": 0,
"time": "2024-05-21T12:56:30.709961+00:00",
"topic": "zigbee2mqtt/IR Remote Control"
}
]
}
],
"discovery_data": {
"topic": "homeassistant/switch/0x385cfbfffe3e3594/switch/config",
"payload": {
"availability": [
{
"topic": "zigbee2mqtt/bridge/state"
}
],
"command_topic": "zigbee2mqtt/IR Remote Control/set",
"device": {
"identifiers": [
"zigbee2mqtt_0x385cfbfffe3e3594"
],
"manufacturer": "TuYa",
"model": "Universal smart IR remote control (ZS06)",
"name": "IR Remote Control",
"via_device": "zigbee2mqtt_bridge_0x00124b0029e84ce5"
},
"json_attributes_topic": "zigbee2mqtt/IR Remote Control",
"name": null,
"object_id": "ir_remote_control",
"origin": {
"name": "Zigbee2MQTT",
"sw_version": "1.37.1",
"support_url": "https://www.zigbee2mqtt.io"
},
"payload_off": "OFF",
"payload_on": "ON",
"state_topic": "zigbee2mqtt/IR Remote Control",
"unique_id": "0x385cfbfffe3e3594_switch_zigbee2mqtt",
"value_template": "{{ value_json.learn_ir_code }}",
"platform": "mqtt"
}
},
"transmitted": []
},
{
"entity_id": "sensor.0x385cfbfffe3e3594_learned_ir_code",
"subscriptions": [
{
"topic": "zigbee2mqtt/bridge/state",
"messages": [
{
"payload": "online",
"qos": 0,
"retain": 1,
"time": "2024-05-21T12:55:55.699740+00:00",
"topic": "zigbee2mqtt/bridge/state"
}
]
},
{
"topic": "zigbee2mqtt/IR Remote Control",
"messages": [
{
"payload": "{"learn_ir_code":null,"learned_ir_code":"BUojkBErAuALAQN9BisCwAFAC+AHAwNeAisCwBPgAwFAE8ABwAtAB4ADQDUDKwJ9BoADAysCXgJACwX3nUojygiAB+ABjwJeAivgAAEFXgJ9Bl4CQAcAKyABAX0G4AkDBSsCXgJ9BoADACvgAAEBXgJAEwAroAEJfQYrAisCXgJ9BkADACtgBwMrAl4C4AcL4AWPA14CKwJAA+ADAQZeAn0GXgIroAEBfQbgCQMFKwJeAn0GQAMBKwLgAQFADwJeAiugAQN9BisCQAECfQZeIANABwErAkABAX0GQA8CXgIrIAELfQYrAvedSiPKCCsC","linkquality":114}",
"qos": 0,
"retain": 0,
"time": "2024-05-21T12:56:30.709961+00:00",
"topic": "zigbee2mqtt/IR Remote Control"
}
]
}
],
"discovery_data": {
"topic": "homeassistant/sensor/0x385cfbfffe3e3594/learned_ir_code/config",
"payload": {
"availability": [
{
"topic": "zigbee2mqtt/bridge/state"
}
],
"device": {
"identifiers": [
"zigbee2mqtt_0x385cfbfffe3e3594"
],
"manufacturer": "TuYa",
"model": "Universal smart IR remote control (ZS06)",
"name": "IR Remote Control",
"via_device": "zigbee2mqtt_bridge_0x00124b0029e84ce5"
},
"enabled_by_default": true,
"json_attributes_topic": "zigbee2mqtt/IR Remote Control",
"name": "Learned ir code",
"object_id": "ir_remote_control_learned_ir_code",
"origin": {
"name": "Zigbee2MQTT",
"sw_version": "1.37.1",
"support_url": "https://www.zigbee2mqtt.io"
},
"state_topic": "zigbee2mqtt/IR Remote Control",
"unique_id": "0x385cfbfffe3e3594_learned_ir_code_zigbee2mqtt",
"value_template": "{{ value_json.learned_ir_code }}",
"platform": "mqtt"
}
},
"transmitted": []
},
{
"entity_id": "text.0x385cfbfffe3e3594_ir_code_to_send",
"subscriptions": [
{
"topic": "zigbee2mqtt/bridge/state",
"messages": [
{
"payload": "online",
"qos": 0,
"retain": 1,
"time": "2024-05-21T12:55:55.699740+00:00",
"topic": "zigbee2mqtt/bridge/state"
}
]
},
{
"topic": "zigbee2mqtt/IR Remote Control",
"messages": [
{
"payload": "{"learn_ir_code":null,"learned_ir_code":"BUojkBErAuALAQN9BisCwAFAC+AHAwNeAisCwBPgAwFAE8ABwAtAB4ADQDUDKwJ9BoADAysCXgJACwX3nUojygiAB+ABjwJeAivgAAEFXgJ9Bl4CQAcAKyABAX0G4AkDBSsCXgJ9BoADACvgAAEBXgJAEwAroAEJfQYrAisCXgJ9BkADACtgBwMrAl4C4AcL4AWPA14CKwJAA+ADAQZeAn0GXgIroAEBfQbgCQMFKwJeAn0GQAMBKwLgAQFADwJeAiugAQN9BisCQAECfQZeIANABwErAkABAX0GQA8CXgIrIAELfQYrAvedSiPKCCsC","linkquality":114}",
"qos": 0,
"retain": 0,
"time": "2024-05-21T12:56:30.709961+00:00",
"topic": "zigbee2mqtt/IR Remote Control"
}
]
}
],
"discovery_data": {
"topic": "homeassistant/text/0x385cfbfffe3e3594/ir_code_to_send/config",
"payload": {
"availability": [
{
"topic": "zigbee2mqtt/bridge/state"
}
],
"command_topic": "zigbee2mqtt/IR Remote Control/set/ir_code_to_send",
"device": {
"identifiers": [
"zigbee2mqtt_0x385cfbfffe3e3594"
],
"manufacturer": "TuYa",
"model": "Universal smart IR remote control (ZS06)",
"name": "IR Remote Control",
"via_device": "zigbee2mqtt_bridge_0x00124b0029e84ce5"
},
"json_attributes_topic": "zigbee2mqtt/IR Remote Control",
"name": "Ir code to send",
"object_id": "ir_remote_control_ir_code_to_send",
"origin": {
"name": "Zigbee2MQTT",
"sw_version": "1.37.1",
"support_url": "https://www.zigbee2mqtt.io"
},
"unique_id": "0x385cfbfffe3e3594_ir_code_to_send_zigbee2mqtt",
"value_template": "{{ value_json.ir_code_to_send }}",
"platform": "mqtt"
}
},
"transmitted": []
}
],
"triggers": []
}
}
}

I was advised to try here first

@ghost
Copy link
Author

ghost commented May 23, 2024

is this enough info?

@jbouwh
Copy link
Contributor

jbouwh commented May 23, 2024

is this enough info?

possible, I'll have a look later

@jbouwh
Copy link
Contributor

jbouwh commented May 23, 2024

@jnewland I have enough information. The issue is that a sensor or text entity cannot have a state with more then 255 chars. If the length exceeds this limit we should log a better error message showing the entity causing the issue.

That the state exceeds the limit is not an issue of MQTT. This is just a bad configuration.

@ghost
Copy link
Author

ghost commented May 24, 2024

@jnewland I have enough information. The issue is that a sensor or text entity cannot have a state with more then 255 chars. If the length exceeds this limit we should log a better error message showing the entity causing the issue.

That the state exceeds the limit is not an issue of MQTT. This is just a bad configuration.

was this reply intended for me?

@jbouwh
Copy link
Contributor

jbouwh commented May 24, 2024

@jnewland I have enough information. The issue is that a sensor or text entity cannot have a state with more then 255 chars. If the length exceeds this limit we should log a better error message showing the entity causing the issue.
That the state exceeds the limit is not an issue of MQTT. This is just a bad configuration.

was this reply intended for me?

my bad, I meant to address @contactmetherenow. The attached PR will improve the error logging and close this issue. It will not solve the Z2M issue BTW.

@jbouwh
Copy link
Contributor

jbouwh commented May 24, 2024

The error is caused by the sensor config added by Z2M. You could try to disable this entity.

@ghost
Copy link
Author

ghost commented May 24, 2024

Should I be contacting Z2M to address the sensor error? if so what is the correct github for Z2M because i see quite a few. (FYI I am running Z2M as a docker container)

@jbouwh
Copy link
Contributor

jbouwh commented May 24, 2024

Should I be contacting Z2M to address the sensor error? if so what is the correct github for Z2M because i see quite a few. (FYI I am running Z2M as a docker container)

Yes, you can submit an issue here: https://github.com/Koenkk/zigbee2mqtt/issues

@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants