Core: State max characters 255

Created on 5 Nov 2017  路  5Comments  路  Source: home-assistant/core

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):
0.57.0

Python release (python3 --version):
3.4

Component/platform:
sensor or input_text

Description of problem:
Before 0.57.0 i had a sensor which i populated with lyrics. This no longer works and throws an error that the max length of a state is 255 characters. Same applies for the new input_text component.

Expected:
Would like to be able to set the state to more than 255 characters, which was possible before 0.57.0

Problem-relevant configuration.yaml entries and steps to reproduce:




    1. 2.
  1. 3.

Traceback (if applicable):

2017-11-05 16:14:43 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/aiohttp/web_protocol.py", line 422, in start
    resp = yield from self._request_handler(request)
  File "/srv/homeassistant/lib/python3.4/site-packages/aiohttp/web.py", line 306, in _handle
    resp = yield from handler(request)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
    res = yield from res
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
    res = yield from res
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/http/ban.py", line 58, in ban_middleware_handler
    return (yield from handler(request))
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 423, in handle
    result = yield from result
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/api.py", line 225, in post
    hass.states.async_set(entity_id, new_state, attributes, force_update)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 752, in async_set
    state = State(entity_id, new_state, attributes, last_changed)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 538, in __init__
    "State max length is 255 characters.").format(entity_id))
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.lyrics. State max length is 255 characters.

Additional info:

All 5 comments

0.57 had a breaking change:
https://github.com/home-assistant/home-assistant/pull/9696
https://home-assistant.io/blog/2017/11/04/release-57/#breaking-changes

You can use state attributes for longer strings.

I'm unclear how to fix this issue. My sensor takes the Last message (TTS) from MQTT topic and makes it available as a sensor value. This value is routinely over 255 characters. I can't find in the documentation how to create an attribute for the MQTT to get around the 255 character limitation. Right now, it just errors out.

sensor:
  - platform: mqtt
    state_topic: "polly/lastmsg"
    name: "Last Message"

Any guidance would be appreciated.

I think you would need a custom component to couple mqtt subscription and setting a state with attributes.

Thanks for the response. I'm probably an edge case so I'll just deal with the occasional error in my logs. It would be nice though to be able to easily set the attribute entries for custom sensors via YAML.

still not clear how to get this :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ariel-madril picture ariel-madril  路  451Comments

grantalewis picture grantalewis  路  145Comments

Ciqsky picture Ciqsky  路  129Comments

Gio76 picture Gio76  路  223Comments

McGiverGim picture McGiverGim  路  124Comments