Jinja: Filter on entity_id


I’m trying to make a list of entity_ids filtered on their entity_id (in the example for switches that are on and with their entity_id starting with an ‘s’), but it does not give the expected result. Can someone please indicate what is wrong? To debug I’m showing the result of the find in the loop. It seems fine there. If I remove the quotes in the rejectattr call, it gives me an error.

Thanks, Johan

{%- for device in states.switch|rejectattr('state','in','off')|rejectattr('entity_id.find("switch.s")' != 0) %}{%- if loop.first %}{%- else %}, {% endif %}{{device.entity_id }} {{device.entity_id.find('switch.s')}}{%- if loop.last %}{% endif %}{%- endfor %}