well, that works, but should have thought of my old |int
trick:
{% set rooms = ['woonkamer','hall','master_bedroom','hobbykamer','office','dorm_marte'] %}
{% set ns = namespace(speakers = '') %}
{% for i in range(rooms | length) %}
{% if states('input_boolean.player_' ~ rooms[i]) == 'on' %}
{% set d = ', ' if ns.speakers | length > 0 else '' %}
{% set ns.speakers = ns.speakers ~ d ~ 'media_player.googlehome_' ~ rooms[i] %}
{% endif %}
{% endfor %}
{% if ns.speakers|length|int == 0 %} None
{% else %}
{{ ns.speakers }}
{% endif %}
|int
makes 0 out of nothing
cool.
also, since we’re templating niceties:
value_template: >
{{ states.input_boolean|selectattr('entity_id','in',state_attr('group.activate_media_players','entity_id'))
|selectattr('state','eq','on') |map(attribute='name')|join(', ') }}
value_template: >
{{ states.input_boolean|selectattr('entity_id','in',state_attr('group.activate_media_players','entity_id'))
|selectattr('state','eq','on')|list|length }}
have been playing with the for loop to count the ‘on’ booleans, but didn’t get it right, and using the ns.speaker|length won’t work since it is the string of all spelled media players, so doesn’t count the items, but the characters.
using the above:
friendly_name_template: >
{% set count = states.input_boolean
|selectattr('entity_id','in',state_attr('group.activate_media_players','entity_id'))
|selectattr('state','eq','on')|list|length %}
{% set player = 'player' if count in [0,1] else 'players' %}
{% set number = 'No' if count == 0 else count %}
{{number}} Media {{player}} active
Now how the get the counter in the main template loop…