Help with value template

Hi, I am trying to get a sensor working that will tell me which doors are open. Currently I have it working so that I can see if all doors are closed but if more than one door is open I can only see the first one in the sensor. Can anyone help out or point me in the right direction? Below is the sensor, Cheers

- platform: template
  sensors:
    all_doors:
      value_template: >-    
        {% if (is_state('sensor.xiaomi_door_1_status','Closed')) and
        (is_state('sensor.xiaomi_door_2_status','Closed')) %} and
        (is_state('sensor.xiaomi_door_3_status','Closed')) %} and
        (is_state('sensor.xiaomi_door_4_status','Closed')) %} and
        (is_state('sensor.xiaomi_door_5_status','Closed')) %} and
        (is_state('sensor.xiaomi_door_6_status','Closed')) %} and
        (is_state('sensor.back_door_status','Closed')) %} and
        (is_state('sensor.front_door_status','Closed')) %} and
        (is_state('sensor.garage_door_status','Closed')) %} and
        House secure
        {% elif (is_state('sensor.xiaomi_door_1_status','Open')) %}
        Kitchen door is open
        {% elif (is_state('sensor.xiaomi_door_2_status','Open')) %}
        Glass sliding door is open
        {% elif (is_state('sensor.xiaomi_door_3_status','Open')) %}
        Bedroom door is open
        {% elif (is_state('sensor.xiaomi_door_4_status','Open')) %}
        Storeroom door is open
        {% elif (is_state('sensor.xiaomi_door_5_status','Open')) %}
        Glass sliding door 2 is open
        {% elif (is_state('sensor.xiaomi_door_6_status','Open')) %}
        Ensuite door is open
        {% elif (is_state('sensor.back_door_status','Open')) %}
        Back door is open
        {% elif (is_state('sensor.front_door_status','Open')) %}
        Front door is open
        {% elif (is_state('sensor.garage_door_status','Open')) %}
        Garage door is open
        {% else %}
        Status unknown
        {% endif %}
      icon_template: mdi:door-closed
      friendly_name: 'All doors'

figured it out, if anyone comes across this this is the working template

- platform: template
  sensors:
    all_doors:
      value_template: >-    
    {% if (is_state('sensor.xiaomi_door_1_status','Closed')) and
    (is_state('sensor.xiaomi_door_2_status','Closed')) and
    (is_state('sensor.xiaomi_door_3_status','Closed')) and
    (is_state('sensor.xiaomi_door_4_status','Closed')) and
    (is_state('sensor.xiaomi_door_5_status','Closed')) and
    (is_state('sensor.xiaomi_door_6_status','Closed')) and
    (is_state('sensor.back_door_status','Closed')) and
    (is_state('sensor.front_door_status','Closed')) and
    (is_state('sensor.garage_door_status','Closed')) %}
    House secure
    {% endif %}
    {% if (is_state('sensor.xiaomi_door_1_status','Open')) %}kitchen door open{% endif %} {% if (is_state('sensor.xiaomi_door_2_status','Open')) %}glass sliding door open{% endif %} {% if (is_state('sensor.xiaomi_door_3_status','Open')) %}bedroom door open{% endif %} {% if (is_state('sensor.xiaomi_door_4_status','Open')) %}storeroom door open{% endif %} {% if (is_state('sensor.xiaomi_door_5_status','Open')) %}glass sliding door 2 open{% endif %} {% if (is_state('sensor.xiaomi_door_6_status','Open')) %}ensuite door open{% endif %} {% if (is_state('sensor.back_door_status','Open')) %}back door open{% endif %} {% if (is_state('sensor.front_door_status','Open')) %}front door open{% endif %} {% if (is_state('sensor.garage_door_status','Open')) %}garage door open
    {% endif %}
      friendly_name: 'All doors'
2 Likes

I do something similar for my Alexa Intent, but I use a loop like this:

 {%-for state in states 
    if (
         (state.entity_id == "light.cooking") or (state.entity_id.startswith("switch"))
        ) and (state.state=="on")  -%}        
        {%- if loop.first -%}The {% elif loop.last -%} and the {% else -%} the {% endif -%} 
           {{state.name}} {% if state.name.endswith('s')%} are {%else%} is {%endif%} {{state.state}},
       {%- if loop.last %}
         {%- if loop.index >0 %}
           Everything else is off. .
         {%- endif%} 
        {%- endif%} 
    {%- else%}
       Everything is off. .
    {%- endfor%}

This gives me a natural language result like this:
“The bedroom light is on and the office lights are on. Everything else is off”

5 Likes

That looks nice, I might try incorporate it