c0ntax
(Martin)
August 13, 2024, 2:33pm
1
I am trying to modify a template to produce a ‘cleaner’ result and I’m wondering how I amend the template to:
a) remove the quotation marks
b) have the current_position
value to appear next to the friendly_name
on the same line for each?
The current result:
Template:
{% set updates = expand('cover.all_blinds') | selectattr('state', 'eq', 'open') | list %}
{% set ns = namespace(result=[] ) %}
{% for item in updates %}
{% set ns.result = ns.result + [[item.attributes.friendly_name], [item.attributes.current_position] ] %}
{% endfor %}
{{ ns.result | join('\n') | replace (' Blinds', '') | replace (' (Simple)', '') | replace ('[', '')| replace (']', '') | replace ('.0', '%') }}
Hellis81
(Hellis81)
August 13, 2024, 2:38pm
2
Any reason why you first add them all to the namespace before outputting it?
Can’t you output it directly?
A wild guess:
{% set updates = expand('cover.all_blinds') | selectattr('state', 'eq', 'open') | list %}
{% for item in updates %}
{{ item.attributes.friendly_name | replace (' Blinds', '') | replace (' (Simple)', '') }} - {{ item.attributes.current_position | int }}%
{% endfor %}
1 Like
petro
(Petro)
August 13, 2024, 2:41pm
3
{% set ns = namespace(result=[] ) %}
{% for item in expand('cover.all_blinds') | selectattr('state', 'eq', 'open') %}
{% set name = item.attributes.friendly_name | replace (' Blinds', '') | replace (' (Simple)', '') %}
{% set position = item.attributes.current_position | int %}
{% set ns.result = ns.result + [ name ~ ' ' ~ position ~ '%' ] %}
{% endfor %}
{{ ns.result | join('\n') }}
1 Like
c0ntax
(Martin)
August 13, 2024, 2:46pm
4
@Hellis81 I just used a template found in another post where the OP needed a similar template for the same reason as myself and it included the namespace. I just edited that template to suit my needs up to where I could.
@petro That works as expected.
Thanks for your help.