Two window sensors one output | Zwei Fenstersensoren eine Ausgabe

Ah ok, that won’t work, sorry. :slight_smile:

Please change your template.yaml to this:

- sensor:
  - name: Fensterstatus_Esszimmer_Links
    state: |
      {% set b1 = states('binary_sensor.esszimmer_fenster_links_gekippt') %}
      {% set b2 = states('binary_sensor.esszimmer_fenster_links_offen') %}
      {% if b1 == 'off' and b2 == 'off' %} geschlossen
      {% elif b1 == 'on' and b2 == 'off' %} gekippt
      {% elif b2 == 'on' and b1 == 'on' %} offen
      {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
      {% else %}  unbekannt
      {% endif %}
    icon: |
      {% set b1 = states('binary_sensor.esszimmer_fenster_links_gekippt') %}
      {% set b2 = states('binary_sensor.esszimmer_fenster_links_offen') %}
      {% if b1 == 'off' and b2 == 'off' %} mdi:window-closed-variant
      {% elif b1 == 'on' and b2 == 'off' %} mdi:angle-acute
      {% elif b2 == 'on' and b1 == 'on' %} mdi:window-open-variant
      {% elif b1 == 'unavailable' or b2 == 'unavailable' %} mdi:exclamation
      {% else %} mdi:exclamation
      {% endif %}

What I did was delete the first line (template:) and two spaces at the beginning of every row, so the indentation fits. And you already have template: in your config. :slight_smile:

Not important, just use the corrected version above. After saving you have to reload the config. Go to Developer tools > YAML and first check your config by pressing the button in the first paragraph. If you get an ok, than reload template entites with the button a little downwards. In german this is under Entwicklerwerkzeuge > YAML > Konfiguration prüfen and the secomnd one is called Template Entitäten.

Please report back, if everything works as expected. :slight_smile:

All right, it works. Thank you

1 Like

Sorry to bother, but may I ask for some guidance about this piece of code?
At the moment it’s driving me insane, that it’s not working as expected.
I added the

template: !include template.yaml

into the configuration.yaml, created a template.yaml and added the following code

- sensor:
  - name: Esszimmer Balkontuer
    state: |
        {% set b1 = states('binary_sensor.esszimmer_balkontuer_oben_contact') %}
        {% set b2 = states('binary_sensor.esszimmer_balkontuer_unten_contact') %}
        {% if b1 == 'true' and b2 == 'true' %} geschlossen
        {% elif b1 == 'false' and b2 == 'true' %} gekippt
        {% elif b2 == 'false' and b1 == 'false' %} offen
        {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
        {% else %}  unbekannt
        {% endif %}
    icon: |
        {% set b1 = states('binary_sensor.esszimmer_balkontuer_oben_contact') %}
        {% set b2 = states('binary_sensor.esszimmer_balkontuer_unten_contact') %}
        {% if b1 == 'true' and b2 == 'true' %} mdi:door-closed-variant
        {% elif b1 == 'false' and b2 == 'true' %} mdi:angle-acute
        {% elif b2 == 'false' and b1 == 'false' %} mdi:door-open-variant
        {% elif b1 == 'unavailable' or b2 == 'unavailable' %} mdi:exclamation
        {% else %} mdi:exclamation
        {% endif %}

So, I’m using Aqara Window/Door Sensors, attached to Zigbee2mqtt, which expose “contact” as state true or false. But, no matter if I use true/false in the code above or on/off, every time it creates the entity “sensor.esszimmer_balkontuer” with the state “unbekannt”.
Any advice from your side what I’m doing wrong? Much appreciated.
Thanks in advance.
Regards
Sven

EDIT: Issue solved. It should be on/off and it seems I switched the state (off is closed and on is open) so it was an undefined state.

Hello and welcome to the community! :slight_smile:

I see you got it solved for you! :+1:

Just to explain: if a binary_sensor, like your Aqara sensors, has a device_class, this is what makes it on/off, open/closed and so on.