How to store a list of switches based on template (over 255 char)

Hi,

I’d like to store a list of matching switches in variable/sensor which can be used in automations and scripts. I tried to set up a template sensor, but I get an error of exceeding 255 characters and the sensor state turns to ‘unavailable’.

What’s the correct way to store a list over 255 characters based on a template?

Example template:

{{ states.switch
  | map(attribute='entity_id')
  | select("search","switch.id")
  | list }}

Store the list in an attribute of the template sensor instead of the state or you can leverage reusable jinja to create a custom Template constant to access it in future templates.

1 Like