How to Store Long Text in Home Assistant
Sometimes you want to store a big chunk of text in Home Assistant - like a long note, a log, or an AI response. However, there's a 255-character limit for states and for input_text helpers. Here's how to work around this and save longer text!
Where the 255-Character Limit Applies
- Entity state: The main value (state) of any entity is always limited to 255 characters. You can't go over this, even with advanced methods.
- input_text helper: This is also limited to 255 characters (set when you create it).
How to Store Longer Text
If you need to store more than 255 characters, use an attribute. Attributes are extra pieces of info attached to an entity. They don't have the same short limit as the state!
- Use a Template Sensor or Custom Integration: Some advanced integrations or scripts (like
python_scriptor custom components from HACS) let you set attributes easily. - Store the text in a file: For really big notes, you can use the
notify.fileservice or create a file sensor that reads from a text file. This is perfect for logs or very long messages.
Beginner Example: Storing a Long Note as an Attribute
Here's a simple way to add a long note to an entity as an attribute using a python_script (a built-in way to run small bits of Python code from Home Assistant).
- Go to Settings > Automations & Scenes > Scripts, and create a new script.
- Save this as
python_scripts/set_long_attribute.pyin your config/python_scripts folder:
entity_id = data.get('entity_id') long_value = data.get('long_value') hass.states.set(entity_id, hass.states.get(entity_id).state, {"long_note": long_value}) - Reload Python Scripts in Developer Tools > YAML > Reload Python Scripts.
- Call the script from an automation, script, or Developer Tools > Services like this:
service: python_script.set_long_attribute data: entity_id: sensor.your_sensor long_value: "This is a super long note or text string that can be as long as you need!" - Your entity will now have an attribute called
long_notewith your full text.
Other Options
- For very large data, use file sensors to read from a text file, or notify.file to write logs and notes to a file outside Home Assistant.
- For basic use, stick to storing your long text as an attribute (as shown above).
Key Points
- State & input_text: Always 255 characters max.
- Attributes: Can store much longer text!
- Use a python_script or custom integration for easiest results.