From what I have read on some old discussions, I seem to have understood that it’s not possible, and it’s not even possible to convert sensor values from string to json or lists (list filter create a list with an item for every character). The only options are node-red and python scripts, is it correct?
An entity’s state
value can store a single string of up to 255 characters. If you were to use it to store this:
2.35, 4.67, 1.82, 0.15
you can use a template containing split(', ')
to convert it to a list.
In contrast, an entity’s attributes
can store multiple values where each one can be text, list, dict, float, integer, or boolean. There’s no length limit (other than the host machine’s resources).
What is your intended application?
Ok, thank you. Now it’s a lot clearer. I’d like to create a variable (with snarky snark integration) or a template sensor to store the windows that are open or the lights that are on. I use them in different automations so I thought It was better to use a sensor to store them. Based on your response, I think the best thing to do is storing them in a template sensor attribute. Isn’t it?
Example:
template:
- sensor:
- name: Open Doors
state: >
{{ states.binary_sensor | selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'door')
| selectattr('state', 'eq', 'on') | list | count }}
attributes:
names: >
{{ states.binary_sensor | selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'door')
| selectattr('state', 'eq', 'on') | map(attribute='name') | list }}