But for some reason I can’t get it to work…
For debugging I map the state and do |list in the final version that will be the name and |first.
It’s probably something very simple, but I don’t see it
Another way, if all your CO2 sensors contain _co2 in the entity ID, and no other sensors do:
# build a list of entity IDs
{% set sl = states['sensor']|map(attribute='entity_id')|select('contains','_co2')|list %}
# build a list of their states
{% set ssl = sl|map('states')|map('float', default=0)|list %}
# find the maximum
{% set sm = ssl|max %}
# find the corresponding entity ID
{% set sn = sl[ssl.index(sm)] %}
{{ sn }}: {{ sm }}