# Synthèse Lumières

**URL:** <https://forum.hacf.fr/t/synthese-lumieres/4517>\
**Category:** Template / Jinja\
**Tags:** lumière-light\
**Created:** [Avril 28, 2021, 8:06 UTC](https://forum.hacf.fr/t/synthese-lumieres/4517 "2021-04-28T08:06:23Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Clemalex](https://forum.hacf.fr/user_avatar/forum.hacf.fr/clemalex/32/3691_2.png) [@Clemalex](https://forum.hacf.fr/u/Clemalex)\
**Post date:** [Avril 28, 2021, 8:06 UTC](https://forum.hacf.fr/t/synthese-lumieres/4517/1 "2021-04-28T08:06:23Z")

</div>

Petit code pour avoir le nombre de lumières allumées sur le total ainsi que leur nom :

 ![animate](https://forum.hacf.fr/uploads/default/original/2X/4/4cb7eaa2d14036724330593b00f9ab6589793de3.gif)

_Mise à jour du post avec la prise en compte de `browser_mod` pour exclure les écrans qui sont considérés comme des lampes (et qui n'ont pas d'attribut `friendly_name)` :_

```auto
sensor:
  - platform: template
    sensors:
      toutes_les_lampes:
        friendly_name_template : >
          {% set domain = 'light' %}
          {% set state = 'on' %}
          {# Définition du `namespace` afin de pouvoir récupérer la valeur définie dans la boucle #}
          {% set light = namespace(is_light=0, is_on=0) %}
          {%- set entities = (states[domain]| map(attribute='entity_id') | list ) -%}
          {%- for entity in entities -%}
            {% if not ( is_state_attr(entity,'type','browser_mod') or is_state(entity,'unavailable')) %}
              {% set light.is_light = light.is_light + 1 %}
              {% if is_state(entity,'on') %}
                {% set light.is_on = light.is_on + 1 %}
                {%- if loop.last %}
                  {{ state_attr(entity,'friendly_name') }}
                {% else %}
                  {{ state_attr(entity,'friendly_name') }},
                {%- endif %}
              {%- endif %}
            {%- endif %}
          {%- endfor -%}
          {{light.is_on}}/{{light.is_light}}
        value_template: >
          {% set domain = 'light' %}
          {% set state = 'on' %}
          {%- set entities = (states[domain] | selectattr('state','eq', state) | map(attribute='entity_id') | list ) -%}
          {%- for entity in entities -%}
            {% if not is_state_attr(entity,'type','browser_mod') %}
              {%- if loop.last %}
                 {{ state_attr(entity,'friendly_name') }}
              {% else %}
                 {{ state_attr(entity,'friendly_name') }},
              {%- endif %}
            {%- endif %}
          {%- endfor -%}

```

[source initiale](https://community.home-assistant.io/t/psa-turn-on-off-all-lights-in-home-assistant-0-104-group-all-changes/163743?u=clemalex)

---

_[View the full topic](https://forum.hacf.fr/t/synthese-lumieres/4517)._
