I am using a text helper to contain an AI generative answer that is sometimes more than 255 characters (though I am trying to request AI generative to limit to 255, but that was not working …)
By default, a text helper seems to be limited to 255 characters :
I am not sure if this is a limitation I was able to “bug”, or if the limitation is only using the arrows that is only allowing you to set up to 255 characters, b ut anyway, this helper is now able to contain much more than 255 characters !! :
I was not able to find anything related to the AI answers … the issu remains that when I ask Google generative to limit the answer to 255 characters, it doesn’t obey … but that is not the discussion in here.
I do not get what you mean by “limit of the text variable” … In fact as you can see above I was able to store in that variable 302 characters … !!
… and have in my text helper a limit of 2555 characters !!
I haven’t seen anything in the latest Release Notes announcing an entity’s state can now store more than 255 characters. Maybe it did but I missed it. However, it would be a significant change so I would expect it to be prominently reported.
My concern is that you may have found a bug that, although it allows storing more than 255 characters and appears to work, may cause unexpected problems in the future. (EDIT perform the test in my NOTE below).
For example, sometimes the database’s structure is modified when upgrading Home Assistant. During the conversion process, it may experience difficulties with a value that is supposed to be limited to 255 but is actually longer (or it will simply truncate it).
I think the safer method is to store the long text in a Trigger-based Template Sensor’s attributes (can store up to 16Kb). Here’s an example of how to do that:
If you implement the example, your Markdown Card can reference the stored generative_ai text like this:
Out of curiosity, after you restart Home Assistant, does input_text.generative_ai_doorbel still report the long text value?
I’m wondering if the long text value is simply in the state machine but not actually written to the database (or only the first 255 characters are stored). Restarting Home Assistant will reveal more clues. I’m betting the entire value isn’t actually being stored (partial or none).
Its supposed to fail and truncate at 255. If you want to store text, op use the trigger based temple sensor or the integration i pointed to in this post. I remember your Google isn’t behaving post when I wrote this last night.
But no. Don’t do that. It will be fixed and your stuff will disappear. Use trigger based template.
I suspect this is like using Developer Tools → States to set an entity’s state value. There are no guardrails and you can write whatever you want (edit not quite; it does do some validation) but it’s only a temporary value in the state machine and not written to the database. The value is lost (or overwritten by its underlying integration) after a restart.
Arguably the only bug is that a Text Helper UI’s should, ideally, set the Maximum permissible value to 255 (and not mislead one to believe it will store more than that).
But when trying to paste a long text like Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
into a field, the entity becomes “unknown”.
Same with calling a service.
Although we can see a nice green “success” button:
2025-03-07 18:44:03.717 ERROR (MainThread) [homeassistant.helpers.entity] Failed to set state for input_text.xxxxxx, fall back to unknown
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1227, in _async_write_ha_state
hass.states.async_set_internal(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
entity_id,
^^^^^^^^^^
...<5 lines>...
time_now,
^^^^^^^^^
)
^
File "/usr/src/homeassistant/homeassistant/core.py", line 2363, in async_set_internal
state = State(
entity_id,
...<8 lines>...
timestamp,
)
File "/usr/src/homeassistant/homeassistant/core.py", line 1807, in __init__
validate_state(state)
~~~~~~~~~~~~~~^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 237, in validate_state
raise InvalidStateError(
...<2 lines>...
)
homeassistant.exceptions.InvalidStateError: Invalid state with length 445. State max length is 255 characters.
Anyway, a possibility to define a wrong length seems to be a bug - so here is the issue:
OR have an alternative method allowing le to get a long answer (> 255 characters) and be able to display it in a Dashboard (my case markdown card)
I need to check if solution from @123 using a Triggerd-based Sensor’s attribute works for me … but to be honest this is Chinese so let me some time to investigate and check this.
P.S. I will also restart my HA to see what this text template variable becomes now … will post after the restart.
@NathanCu FYI when the Generative AI was populating more than 255 characters, then it was simply NOT updating the text helper at all (so even not truncating it).
I have the latest HA release (March 2025 I think).
ok, so here is the current text helper information before the restart :
That totally depends on how you were trying to do it. My personal custom intent just chops off anything > 255 and reports to the LLM it’s message was truncated at 255 and data may be lost…
It fixes the problem of trying to stuff more than 255.because the first time the llm does and gets it’s hand slapped it stops.
So that is an alternative to the “rigger based temple sensor” @NathanCu was pointing above, in order to be able to store more than 255 characters and use this in a markdown card ?
Sorry, could you elaborate how you managed to set a value to this input_text entity? As I describe above, I failed to set it either from more-info, by service call & in devtools-> state.