I have a template that I’m trying to create which will show all of the lights that are set to manual control with the adaptive lighting custom integration. They are listed in an array as an attribute of the switch entity.
I’m 99% of the way there, but when I view the entity in lovelace, there are 2 spaces on a new line that I can’t seem to figure out how to get rid of. I’m hoping someone better at templating than I can take a look at this and either help me out, or if there’s a better way write this template I’m all ears
Here’s my current template:
sensor:
name: Adaptive Lighting Manually Controlled Lights
unique_id: f7ef4c86-4967-4f85-9df6-7a2f04ca7b62
state: >-
{% set adaptive_light_entities = expand('group.adaptive_lights') %}
{% set manual_lights_looplength = namespace(value=0) %}
{% for x in adaptive_light_entities if state_attr(x.entity_id, 'manual_control') %}{{"\r\n"}}
{% set manual_lights_looplength.value = loop.length %}
{{ state_attr(state_attr(x.entity_id, 'manual_control')[0], 'friendly_name') }}
{% endfor %}
{% if manual_lights_looplength.value == 0 %}All lights are being controlled by Adaptive Lighting{% endif %}
And here’s what it looks like in lovelace using a mushroom template card:
And here’s the yaml for the card:
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
It’s building a list of friendly_names. If the list is not empty, it displays all items in the list separated by a newline character. If the list is empty, it reports the ‘All lights are … etc’ message.
The subtle difference is that the method I suggested first builds a list of names then displays the list’s contents delimited by explicit newlines whereas your method displays each name as it’s found and relies on Jinja’s implicit whitespace control.