Convert different binary status sensors to one text message

Hello to all,

first steps wit home assistand are done and now I try to solve some small things that are not so smart.
One of these things is my garage door.
Ther the status is displayed in different binary sensors comming from the KNX system like:
Garage door closed
Garage door opened
Garage door opens
Garage door closes

I want to have these status combined in one “meaasge box”.
Therfor I tried to add the following in the configuration.yaml but something ist wrong, because I cannot ad the entyty to my dasboard.

template:
- name: “status_garagentor”
unique_id: Status Garagentor
{% if states(‘binary_sensor.Garagentor_offen’)| boolean == ‘on’) }
Garagentor offen
{% elif states(‘binary_sensor.Garagentor_geschlossen’)| boolean == ‘on’) }
Garagentor geschlossen
{% elif states(‘binary_sensor.Garagentor_fahrt_auf’)| boolean == ‘on’) }
Garagentor fährt auf
{% elif states(‘binary_sensor.Garagentor_fahrt_zu’)| boolean == ‘on’) }
Garagentor fährt zu
{% else %}
Fehler
{% endif %}

Firstly, please format your code correctly: see here. Surround it with three backticks (```) before and after.

There are a lot of errors in that code:

  • missing sensor:
  • {% if ... } and {% elif ... } (should be %} at the end)
  • boolean filter doesn’t exist
  • no state: declaration
  • mismatched brackets (one open, two close)

Try this:

template:
  - sensor:
      - name: Status Garagentor
        unique_id: status_garagentor
        state: >
          {% if is_state('binary_sensor.garagentor_offen', 'on') %}
            Garagentor offen
          {% elif is_state('binary_sensor.garagentor_geschlossen', 'on') %}
            Garagentor geschlossen
          {% elif is_state('binary_sensor.garagentor_fahrt_auf', 'on') %}
            Garagentor fährt auf
          {% elif is_state('binary_sensor.garagentor_fahrt_zu', 'on') %}
            Garagentor fährt zu
          {% else %}
            Fehler
          {% endif %}

You can create template sensors via the UI: just paste the template (from {% if to the end) into the box.

Reporting Fehler on my system as I don’t have your sensors.

In future, try your templates in the Template Editor:

A more compact template, assuming the sensors’ friendly names are set properly:

template:
  - sensor:
      - name: Status Garagentor
        unique_id: status_garagentor
        state: "{{ states[('binary_sensor.garagentor_offen','binary_sensor.garagentor_geschlossen','binary_sensor.garagentor_fahrt_auf','binary_sensor.garagentor_fahrt_zu')|select('is_state','on')|first]['attributes']['friendly_name'] }}"
        availability: "{{ ('binary_sensor.garagentor_offen','binary_sensor.garagentor_geschlossen','binary_sensor.garagentor_fahrt_auf','binary_sensor.garagentor_fahrt_zu')|select('is_state','on')|count > 0 }}"

That goes unavailable if no sensor is on rather than returning Fehler.

Thank you Troon,

the hint, yousing - template sensor - is good. did’t knew it bevor.
I copied the suggested code into the template sensor.
There are no failures reported and the status is displayed correctly for each of the 4 Status in my dasboard.

Thank you!
Next time I will poste code in a better way.

But I’m wondering why not all 4 different sensors are displayed in the template

1 Like

The second sensor is 'on' so it does not need to watch the third and fourth as they cannot affect the output. Close the door and it’ll only list one when it is shut.

Thats what I’m wondering about. There are 4 Status possible.

Garagentor offen - that means garage door is open
Garagentor geschlossen - that means garage door is closed
Garagentor fährt auf - that means garage door is moving / opening
Garagentor fährt zu - that means garage door is moving / closing

actual the garage door is closed, but already the same

Sorry: they are listed in reverse order, my mistake. The template checks:

  • is it open?
  • is it closed?
  • is it opening?
  • is it closing?

If any of those is yes, it does not need to check any further down the list — that’s why only two are listed at this point in time.

1 Like

thank you for explanation, now it’s clear for me how it works and I can work on further adaptions to make my dasboard “smarter”.