Copy-paste the following template into the Template Editor and confirm it reports the correct information.
If it works correctly, but the line spacing isnāt what you want, add or remove the hyphens in {%- and {-%} to see how they control whitespace and line breaks. Adjust them to suit your requirements and then use the template in a Markdown card.
{%- set probes_all = ['binary_sensor.ibbq_probe_1_fault', 'binary_sensor.ibbq_probe_2_fault',
'binary_sensor.ibbq_probe_3_fault', 'binary_sensor.ibbq_probe_4_fault'] -%}
{%- set probes_off = expand(probes_all) | selectattr('state', 'ne', 'on') | map (attribute='entity_id') | list -%}
{% for p in probes_off -%}
P{{p.split('_')[3]}}: {{p[:-6]}}
{% endfor -%}
EDIT
Correction. Wrong variable name. Replaced probes with probes_off.
All were āoffā except P3 which was āonā yet it lists all. Also I wanted the actual state of binary_sensor.ibbq_probe_1, binary_sensor.ibbq_probe_2, binary_sensor.ibbq_probe_3, binary_sensor.ibbq_probe_4 not the nameā¦
Try the corrected version that uses two variables whose names are probes_all and probes_off.
You can also try this version in the Template Editor which displays more information about the templateās inner workings.
{%- set probes_all = ['binary_sensor.ibbq_probe_1_fault', 'binary_sensor.ibbq_probe_2_fault',
'binary_sensor.ibbq_probe_3_fault', 'binary_sensor.ibbq_probe_4_fault'] -%}
{{ probes_all }}
{{ expand(probes_all) | map('state') | list }}
{%- set probes_off = expand(probes_all) | selectattr('state', 'ne', 'on') | map (attribute='entity_id') | list -%}
{{ probes_off }}
{% for p in probes_off -%}
{{ p }}
P{{p.split('_')[3]}}: {{p[:-6]}}
{% endfor -%}
Wonāt that simply be off for all of them given that itās what you want the template to extract (only the entities that are not on)? If thatās what you want then you can just use this:
{%- set probes_all = ['binary_sensor.ibbq_probe_1_fault', 'binary_sensor.ibbq_probe_2_fault',
'binary_sensor.ibbq_probe_3_fault', 'binary_sensor.ibbq_probe_4_fault'] -%}
{%- set probes_off = expand(probes_all) | selectattr('state', 'eq', 'off') | map (attribute='entity_id') | list -%}
{% for p in probes_off -%}
P{{p.split('_')[3]}}: {{p[:-6]}} off
{% endfor -%}
If you donāt want the name at all just remove {{p[:-6]}}.