Two window sensors one output | Zwei Fenstersensoren eine Ausgabe

I’m curious: When you click on your profile (last entry in sidebar menu), what is set under „theme“?

Hi there,

“Backend-Select” is selected.

Greetings Werner

Hallo,

da ist “Backend-Select” ausgewählt.

Gruß Werner

Then the colors should work. Strange.

The colors also work normally. The symbols only remain blue for the newly created window sensors

Normal funktionieren die Farben auch. Nur bei den neu erstellten Fenstersensoren bleiben die Symbole blau.

I was wrong. Also the default theme can’t change the colors of a custom sensor in a generic frontend card. What a pity.

Hi there,

no problem. If this does not work, I will display all open or tilted windows on a map. I use this system for this:
🔹 Auto-entities - Automatically fill cards with entities

Unfortunately, I still can’t do that either.
Tried to select “fensterstatus” as Entities - that also worked.
However, if I enter “offen” as the “State”, it doesn’t work.

I changed the sensor code a bit, for example:

      fensterstatus_schlafzimmer_dg:
        friendly_name: Fenster Schlafzimmer-DG
        value_template: |
          {% set b1 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_007cf906_on_off') %}
          {% set b2 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_698aff06_on_off') %}
          {% if b1 == 'off' and b2 == 'off' %} geschlossen
          {% elif b1 == 'on' and b2 == 'off' %} gekippt
          {% elif b2 == 'on' %} offen
          {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
          {% else %} ?
          {% endif %}
        icon_template: |
          {% set b1 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_007cf906_on_off') %}
          {% set b2 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_698aff06_on_off') %}
          {% if b1 == 'off' and b2 == 'off' %} mdi:window-closed-variant
          {% elif b1 == 'on' and b2 == 'off' %} mdi:angle-acute
          {% elif b2 == 'on' %} mdi:window-open-variant
          {% elif b1 == 'unavailable' or b2 == 'unavailable' %} mdi:exclamation
          {% else %} ?
          {% endif %}

Greetings Werner

Hallo,

kein Problem. Wenn es so nicht geht, werde ich mir alle offenen oder gekippten Fenster in einer Karte anzeigen lassen. Ich nutze dazu dieses System:

Leider bekomme ich auch das noch nicht hin.
Habe versucht als Entities fensterstatus zu wählen - das hat auch funktioniert.
Jedoch wenn ich als “State” z.B. “offen” eingebe, da funktioniert es nicht.

Den Sensorencode habe ich noch etwas geändert, z.B.:

      fensterstatus_schlafzimmer_dg:
        friendly_name: Fenster Schlafzimmer-DG
        value_template: |
          {% set b1 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_007cf906_on_off') %}
          {% set b2 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_698aff06_on_off') %}
          {% if b1 == 'off' and b2 == 'off' %} geschlossen
          {% elif b1 == 'on' and b2 == 'off' %} gekippt
          {% elif b2 == 'on' %} offen
          {% elif b1 == 'unavailable' or b2 == 'unavailable' %} nicht verfügbar
          {% else %} ?
          {% endif %}
        icon_template: |
          {% set b1 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_007cf906_on_off') %}
          {% set b2 = states('binary_sensor.lumi_lumi_sensor_magnet_aq2_698aff06_on_off') %}
          {% if b1 == 'off' and b2 == 'off' %} mdi:window-closed-variant
          {% elif b1 == 'on' and b2 == 'off' %} mdi:angle-acute
          {% elif b2 == 'on' %} mdi:window-open-variant
          {% elif b1 == 'unavailable' or b2 == 'unavailable' %} mdi:exclamation
          {% else %} ?
          {% endif %}

Gruß Werner

Sorry it works, with this code:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: '*fensterstatus*'
      state: '*offen*'
  exclude: []

But how can I define a state as offen or gekippt?

Sorry es funktioniert doch, mit diesem Code:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: '*fensterstatus*'
      state: '*offen*'
  exclude: []

Aber wie kann ich als state offen oder gekippt definieren?

My first success.

It works like this:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: '*fensterstatus*'
      state: '*offen*'
    - entity_id: '*fensterstatus*'
      state: '*gekippt*'
  exclude: []

Mein erster Erfolg.

Es funktioniert so:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: '*fensterstatus*'
      state: '*offen*'
    - entity_id: '*fensterstatus*'
      state: '*gekippt*'
  exclude: []
1 Like

Who did you work that?

I have do a new card but nothing would show? I have one entity_id for open and one for gekippt.

I would show it on the card if its open or gekippt or closed.

Hi there,

so i ended up in the l:

type: custom:auto-entities
card:
  type: entities
  title: Offene Fenster
  state_color: true
  show_header_toggle: false
filter:
  include:
    - entity_id: '*fensterstatus*'
      state: offen
    - entity_id: '*fensterstatus*'
      state: '*offen oder gekippt*'
    - entity_id: '*fensterstatus*'
      state: gekippt
    - entity_id: '*fensterstatus*'
      state: '*nicht*'
    - entity_id: '*fensterstatus*'
      state: '?'
  exclude:
    - entity_id: '*fensterstatus*'
      state: '*geschlossen*'
sort:
  method: friendly_name


Greetings Werner

thx for this piece of code!

Hello

I’ll take a look here, I did the same thing as you before and changed your code so that it fits. I created a template.yaml with this text. Of course the commando is also stored in the Config.yaml.

- sensor:
    - name: Fensterstatus_Esszimmer_Links
      value_template: |
        {% 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 %} ?
        {% endif %}
      icon_template: |
        {% 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 %} ?
        {% endif %}

but he doesn’t make a sensor with it as an error message he tells me

Invalid configuration for template in template.yaml, line 12: icon_template is an invalid option for template, check: sensor->0->icon_template Invalid configuration for template in template.yaml, line 2: Required key “state” not specified. Invalid configuration for template in template.yaml, line 3: value_template is an invalid option for template, check: sensor->0->value_template

I don’t know what else I have to write where, I’m pretty new to HA

Greetings Timo

1 Like

Hallo Timo und willkommen im Forum!

Dies hier ist ein rein englisches Forum, daher ist es hier nicht nur Usus, sondern Pflicht, in englisch zu schreiben! Das hat verschiedene Gründe, wie z.B. dass alle Benutzer die Einträge ohne Übersetzungstool lesen können sollen!

Daher editiere bitte Deinen Beitrag und übersetze ihn auf englisch.

Desweiteren nutze bitte entsprechende Formatierungen für Deinen Code, es ist so schlicht nicht möglich, bestimmte Fehler zu sehen, da YAML sehr kritisch mit Leerzeichen und Einrückungen ist (welche ohne Formatierung verloren gehen).

Zu beidem findest Du hier entsprechende Hinweise:

Vielen Dank dafür! :slight_smile:

Die Fehlermeldung besagt übrigens, dass Du eine falsche Konfiguration verwendest, auf den ersten Blick sieht es nach einer Mischung zwischen altem und neuem Template Format aus. Dazu gerne mehr, nachdem Du den Beitrag geändert hast!

Vielen Dank nochmal und bitte nicht böse sein, aber bei so einem grossen Forum müssen ein paar Regeln sein! :slight_smile:


Hello Timo and welcome to the forum!

This is an english only forum, that’s why it’s not only a wish, but rather a requirement to post in english.This has different reasons, one of them being that all users should be able to read posts without the use of a translation tool.

Please edit your post and translate it to english.

And please format your code, this way it’s not possible to see some errors, as YAML is very picky with whitespace and indentations (which will be lost without proper formatting).

See here for both:

Thanks a lot!

Btw. the error message you get tells you, that you are trying to use a wrong configuration. On a first glance, it looks like it’s a mix of old and new template format. More on that, after you edited your post.

Again, thanks a lot, and please don’t take this as rude, but in a forum, big as this one, some rules are required! :slight_smile:


Changed topic title to english to avoid further german posts

I’ve done it

1 Like

Thanks, great! :slight_smile:

The sensor cannot be set up, because you’re mixing old and new format for template sensors.

The dash in front of sensor shows, you’re trying to use the new format, but unfortunately the keys you use, are from the old format. The old format uses value_template and icon_template, where the new format has state and icon instead. :slight_smile:

In this case you can use the new format, which would be like this:

template:
  - 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 %}

I’m not exactly sure, what you mean by this:

How did you implement it in your config? If you have problems here, please post both files, configuration.yaml and template.yaml.

I created this entry in config.yaml

template: !include template.yaml

Then I created a template.yaml. This now contains your changed text

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.