Sorry if the title is confusing. What I’m simply trying to do is create a notification that will tell me which sensors are “on”. I have a group called “windows_doors” with all of my window and door sensors specified. I’m testing this out by just calling the “notify.<my_mobile_app>” service. Here’s the jinja template code I have for the Service Data:
message: >
{% if is_state('group.windows_doors', 'on') %}
The following windows are open:
{% for window in expand('group.windows_doors') %} {% if window.state == 'on' %} {{ window.name }}
{% endif %}
{% endfor %}
{% endif %}
The logic seems to work however the text has a line break for every entity that doesn’t match the “on” condition. So for example, I’ll get a notification that looks like:
I see how I can use the “loop.first” and “loop.last” to add or not add the commas. As you can tell, I have zero experience with Jinja. Thanks for the help!
message: >-
{% if is_state('group.windows_doors', 'on') %}
The following windows are open:
{% for window in expand('group.windows_doors') | selectattr('state', 'eq', 'on') %}
{{ window.name }}
{% endfor %}
EDIT: Ah appears I was too slow testing out the selectattr thing in my own HA. Oh well, I like puzzles haha