Tilt and turn windows with binary sensors

Hi,

My windows are tilt and turn. They have 2 binary sensors each. One used to check if window is tilted. The second to check if the window is opened.
In summary:

  binary_sensor:
    - name: window_kitchen_tilt
    - name: window_kitchen_open

Closed -> window_kitchen_tilt == off && window_kitchen_open == off
Tilted -> window_kitchen_tilt == on && window_kitchen_open == off
Open -> window_kitchen_tilt == on && window_kitchen_open == on

How can i combine those sensors to have a 3 state entity in my interface ?

sensor: #### Not a binary sensor, you have 3 states not two.
- platform: template
  sensors:
    window_kitchen:
      friendly_name: 'Kitchen Window'
      entity_id:
        - binary_sensor.window_kitchen_tilt
        - binary_sensor.window_kitchen_open
      value_template: >
        {% set kw_tilt = states('binary_sensor.window_kitchen_tilt') %}
        {% set kw_open = states('binary_sensor.window_kitchen_open') %}
        {% if kw_tilt == 'off' and kw_open == 'off' %}
          Closed
        {% elif kw_tilt == 'on' and kw_open == 'off' %}
          Tilted
        {% elif kw_tilt == 'on' and kw_open == 'on' %}
          Open
        {% endif %}

This assumes that the 4th state is impossible:

window_kitchen_tilt == off && window_kitchen_open == on

If this is possible you need to account for it in the if tests. Possibly by adding it to the ā€˜Openā€™ result, like so:

      value_template: >
        {% set kw_tilt = states('binary_sensor.window_kitchen_tilt') %}
        {% set kw_open = states('binary_sensor.window_kitchen_open') %}
        {% if kw_tilt == 'off' and kw_open == 'off' %}
          Closed
        {% elif kw_tilt == 'on' and kw_open == 'off' %}
          Tilted
        {% elif (kw_tilt == 'on' and kw_open == 'on') or (kw_tilt == 'off' and kw_open == 'on') %}
          Open
        {% endif %}

Which simplifies to:

      value_template: >
        {% set kw_tilt = states('binary_sensor.window_kitchen_tilt') %}
        {% set kw_open = states('binary_sensor.window_kitchen_open') %}
        {% if kw_tilt == 'off' and kw_open == 'off' %}
          Closed
        {% elif kw_tilt == 'on' and kw_open == 'off' %}
          Tilted
        {% elif  kw_open == 'on' %}
          Open
        {% endif %}

Works perfectly, thanks.
Using lovelace, i manage to change the icon using this new sensor (window open or window closed), but how can i change the icon color using the state ?

Can you tell me what sensors you are using? I have tilt and turn doors and windows and want to be sure the doors are locked and not just closed when I leave the house.

Regards
Steve

I do not have locking sensors.
Only one sensor at the top of the window (for the tilt) and another one at the bottom (for the turn).
I used reed switches. It could also be possible to use a reed switch for the locking by adding a magnet to the bolt of the door. But that requires previous wiring in the doors frame. If you do not have this wiring, try to find a small enough sensor that whould fit inside the bolts chamber once the door is locked. Seems tricky since a battery is already to big to fit insideā€¦

Good luck,
Would be nice to have an update since that gave me an idea of something new to addā€¦

Regards,

Eric

Sorry to open up the old thread again. But how did you mange to change the icon based on open / close?
And did you solve the issue of coloring the icon?
I have a similar sensor, but fail to achieve much with it, currently.

Something like this for the icon:

        icon_template: >
          {% set tilt = states('binary_sensor.window_tilt') %}
          {% set open = states('binary_sensor.window_open') %}
          {% if tilt == 'on' or open == 'on' %}
            mdi:window-open
          {% else %}
            mdi:window-closed
          {% endif %}

And no, did not find out how to change the color. The most simple way would be to have pre-colored icons i guess.

1 Like

I have not quite, but almost the same questionā€¦
Is there a native enum/type/whatever to say a window is tilted/open/closed?
Also for HomeKitā€¦ Iā€™d like to ask Siri if a window is open, and the should NOT include tilted ones.

Are there types for that yet (binary is not enough, as my windows have THREE states)? Or is it only something we can visualize in HA?

Anyone successful to show if a window is TILTED, in Homekit?/homebridge?

I have 2 BINARY SENSORS on each window one at the top, one at the bottom, they detect OPEN and CLOSE. I also have combined them to one ā€˜virtualā€™ SENSOR in home assistant to show OPEN, CLOSED and TILTED. Looks perfect in the Home Assistant UI but i have found no way to show the same in Homekit (via homebridge).

Why is that important?

  1. When I leave my house i donā€™t want any window to be OPEN , but I donā€™t mind if 2 windows are tilted, since I have them alarm secured anyways and want to get a notification if the status changes from TILTED to OPEN and trigger the alarm when Iā€™m awayā€¦
  2. Iā€™d like to ask Siri
  3. Because its 2021 and tilted windows in Homekit should be possibleā€¦

Hi Everyone,

i found this code and i need your help.

  1. the message in HA Studio Code:

  2. i want to change color for the the state:
    ā€œGeƶffnetā€ and ā€œGekipptā€ - red
    ā€œGeschlossenā€ - grey

I hope some one can help me. Thank you

      #EG
      tuer_wohnzimmer:
        friendly_name: 'Wohnzimmer TĆ¼r'
        entity_id:
          - binary_sensor.wohnzimmer
          - binary_sensor.wohnzimmer_gekippt
        value_template: >
          {% set kw_tilt = states('binary_sensor.wohnzimmer_gekippt') %}
          {% set kw_open = states('binary_sensor.wohnzimmer') %}
          {% if kw_tilt == 'off' and kw_open == 'off' %}
            Geschlossen
          {% elif kw_tilt == 'on' and kw_open == 'off' %}
            Gekippt
          {% elif  kw_open == 'on' %}
            Offen
          {% endif %}
        icon_template: >
          {% set tilt = states('binary_sensor.window_tilt') %}
          {% set open = states('binary_sensor.window_open') %}
          {% if tilt == 'on' or open == 'on' %}
            mdi:door-open
          {% else %}
            mdi:door-closed
          {% endif %}