trying to create this template listing all ‘on’ lights, with their respective last_changed
time.
I can’t use
{{s.name + ': ('+ s.last_changed + '),\n'}}
but don’t see what I should use now.
Secondary (minor) issue is that I dont want to use the ‘,’ on the last item, but I cant get my head around the correct construction for that in below template… which now uses the comma after each listed item, including the last.
Please have a look with me here.
{%- set count = expand('group.all_lights_only')
|map(attribute='state')
|select('==','on')
|list|count %}
{% set phrase = 'light is' if count == 1 else 'lights are' %}
{%- if count > 0 %}
{%- for s in expand('group.all_lights_only')
if s.state == 'on' %}
{%- if loop.first %}{{loop.length}} {{phrase}} on: {% endif %}
{{s.name + ': ('+ s.entity_id + '),\n'}}
{%- endfor %}
{%- else %} All lights off
{%- endif %}