always prefer the state_attr() myself for known reasons, and kind of like the further development of the bottom version, since it emphasizes the relation to the mother sensor visually for me.
thought about being safe, but must admit, on the level of the mother sensor:
if sensor.solar_edge_overview exists, all the other sensors exist.
And, as a matter of fact, the mother sensor happens to get thrown out now and then, the rest sensor doesnt always connect. If so, all these sensors show Unknown…
so, shouldn’t I test on the existence of the mother sensor?
{% if 'sensor.solaredge_overview' %}
{% set overview = state_attr('sensor.solaredge_overview','overview') %}
{{(overview.lifeTimeData.energy|float/1000)|round(2)}}
{% else %} Unavailable #(or offline...)
{% endif %}
I was wrong about this one. It works for selecting a set of similarly named entities but not for rejecting them.
It can be done in two steps:
{% set x = states
| selectattr('object_id','gt','solaredge_')
| selectattr('object_id','lt','solaredge_x')
| map(attribute='entity_id')
| list %}
{{ states | rejectattr('entity_id', 'in', x) | list }}
You must have missed my post where I said match serves the purpose of startswith. Here’s the relevant section from Home Assistant’s documentation for Templating - Regular Expressions
Test string is match(find, ignorecase=False) will match the find expression at the beginning of the string using regex.
Test string is search(find, ignorecase=True) will match the find expression anywhere in the string using regex.
from the looks of it, they still can’t be used for the original intent which is something that filters a list based on contains or startswith. I haven’t played with the tests much, but they don’t appear to help much.
EDIT: They can’t be used in selectattr, rejectattr, select, or reject. Making them 100% useless IMO.
EDIT2: Nope, they can!
{% set items = ['abc', 'bcd', 'cde'] %}
{{ items | select("search", 'b') | list }}