Alternative to Helper

Hey!
I need to store 2 Tokens (300-400 char) and change them ~every hour.

My first idea was to use 2 helper text. But the limit seems to be 255 characters?!
Is there a workaround or do you have any other ways i can perform my task?

Thanks!

Create a sensor and store it as an attribute.
That way it can be longer.
That is what I have done.

Do you may have an example-code for that?

Add the tokens as custom attributes to your existing input_text. Attributes aren’t limited to storing a 255-character string.

  1. Go to Configuration > Customisations

  2. Select your input_text.

  3. At the bottom of the form, where it indicates “Pick an attribute to override”, select Other.

  1. Enter a name for the first token (I used token1) and paste the long string you have (I used a 335-character long string) to prove it can exceed 255 characters). Create another attribute to store the second token.

Screenshot from 2021-09-22 13-48-42

  1. Click Save.

  2. Go to Developer Tools > States, select your input_text and confirm the custom attribute contains the desired string. This custom attribute and its value will survive a restart.

You can access the string in a template using the state_attr function:

{{ state_attr('input_text.test', 'token1') }}

If you need to change the custom attribute’s value programmatically, you can use rodpayne’s set_state.py python_script. However, that technique does not store the value permanently and it only lasts until Home Assistant is restarted.


If you are already using MQTT, an entirely different way to handle this is with an MQTT Sensor and publishing the tokens as payloads to be saved as the sensor’s attributes (this may be what Hellis81 suggested).