I just wanted to share my project for making window sensors a little smarter.
Usually window sensors do only have a state open or close. A window which is tilted is usually shown as open and therefore this information is not perfectly useful e.g. if you want to alarm on rain and let people know whether they need to get up from the couch or stay seated.
Or if I leave the house for a short period of time I usually donāt care about tilted windows. However if windows are fully open and it starts raining this immediately causes flooding in our flat.
I use aqara window sensors which are mounted close to the top of the window. In order to also get the tilt status I added a second aqara sensor to each window to the very bottom of it. In case the window is tilted the top sensor is āopenā while the bottom sensor is āclosedā.
On lovelace it looks like this - where the outline square means open and the triangle means tilted:
To get started I created a dropdown helper in the helper ui for every window with four different states like this:
Furthermore I needed a new template sensor showing the correct icons depending on the state of the window. This also needs to be done for every window.
- platform: template
sensors:
kontaktsensor_arbeitszimmer_advanced:
value_template: '{{ states("input_select.kontaktsensor_arbeitszimmer") }}'
friendly_name: 'Kontaktsensor Arbeitszimmer Advanced'
icon_template: >-
{% if is_state('sensor.kontaktsensor_arbeitszimmer_advanced', 'Open') %}
mdi:square-outline
{% elif is_state('sensor.kontaktsensor_arbeitszimmer_advanced', 'Tilted') %}
mdi:network-strength-outline
{% elif is_state('sensor.kontaktsensor_arbeitszimmer_advanced', 'Closed') %}
mdi:square
{% else %}
mdi:alert-circle-outline
{% endif %}
Now an automation is needed which is being triggered by every state change of any of my contact sensors and then set the right state for this particular window.
alias: Contact Sensors State
description: ''
trigger:
- platform: state
entity_id: binary_sensor.openclose_9
id: Kontaktsensor Arbeitszimmer Oben
- platform: state
entity_id: binary_sensor.openclose_93
id: Kontaktsensor Arbeitszimmer Unten
- platform: state
entity_id: binary_sensor.openclose_12
id: Kontaktsensor Schlafzimmer Oben
- platform: state
entity_id: binary_sensor.openclose_94
id: Kontaktsensor Schlafzimmer Unten
- platform: state
entity_id: binary_sensor.openclose_11
id: Kontaktsensor Bad Oben
- platform: state
entity_id: binary_sensor.openclose_95
id: Kontaktsensor Bad Unten
- platform: state
entity_id: binary_sensor.openclose_10
id: Kontaktsensor Kuche Oben
- platform: state
entity_id: binary_sensor.openclose_96
id: Kontaktsensor Kuche Unten
- platform: state
entity_id: binary_sensor.openclose_22
id: Kontaktsensor Wohnzimmer links Oben
- platform: state
entity_id: binary_sensor.openclose_97
id: Kontaktsensor Wohnzimmer links Unten
- platform: state
entity_id: binary_sensor.openclose_21
id: Kontaktsensor Wohnzimmer rechts Oben
- platform: state
entity_id: binary_sensor.openclose_98
id: Kontaktsensor Wohnzimmer rechts Unten
- platform: state
entity_id: binary_sensor.openclose_7
id: Kontaktsensor Terrasse Oben
- platform: state
entity_id: binary_sensor.openclose_99
id: Kontaktsensor Terrasse Unten
condition: []
action:
- choose:
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Arbeitszimmer Oben
- condition: trigger
id: Kontaktsensor Arbeitszimmer Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_arbeitszimmer
data:
option: >
{% if states('binary_sensor.openclose_9') == 'on' and
states('binary_sensor.openclose_93') == 'on' %}
Open
{% elif states('binary_sensor.openclose_9') == 'on' and
states('binary_sensor.openclose_93') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_9') == 'off' and
states('binary_sensor.openclose_93') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Schlafzimmer Oben
- condition: trigger
id: Kontaktsensor Schlafzimmer Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_schlafzimmer
data:
option: >
{% if states('binary_sensor.openclose_12') == 'on' and
states('binary_sensor.openclose_94') == 'on' %}
Open
{% elif states('binary_sensor.openclose_12') == 'on' and
states('binary_sensor.openclose_94') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_12') == 'off' and
states('binary_sensor.openclose_94') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Bad Oben
- condition: trigger
id: Kontaktsensor Bad Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_bad
data:
option: >
{% if states('binary_sensor.openclose_11') == 'on' and
states('binary_sensor.openclose_95') == 'on' %}
Open
{% elif states('binary_sensor.openclose_11') == 'on' and
states('binary_sensor.openclose_95') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_11') == 'off' and
states('binary_sensor.openclose_95') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Kuche Oben
- condition: trigger
id: Kontaktsensor Kuche Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_kuche
data:
option: >
{% if states('binary_sensor.openclose_10') == 'on' and
states('binary_sensor.openclose_96') == 'on' %}
Open
{% elif states('binary_sensor.openclose_10') == 'on' and
states('binary_sensor.openclose_96') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_10') == 'off' and
states('binary_sensor.openclose_96') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Wohnzimmer links Oben
- condition: trigger
id: Kontaktsensor Wohnzimmer links Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_wohnzimmer_links
data:
option: >
{% if states('binary_sensor.openclose_22') == 'on' and
states('binary_sensor.openclose_97') == 'on' %}
Open
{% elif states('binary_sensor.openclose_22') == 'on' and
states('binary_sensor.openclose_97') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_22') == 'off' and
states('binary_sensor.openclose_97') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Wohnzimmer rechts Oben
- condition: trigger
id: Kontaktsensor Wohnzimmer rechts Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_wohnzimmer_rechts
data:
option: >
{% if states('binary_sensor.openclose_21') == 'on' and
states('binary_sensor.openclose_98') == 'on' %}
Open
{% elif states('binary_sensor.openclose_21') == 'on' and
states('binary_sensor.openclose_98') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_21') == 'off' and
states('binary_sensor.openclose_98') == 'off' %}
Closed
{% else %}
Error
{% endif %}
- conditions:
- condition: or
conditions:
- condition: trigger
id: Kontaktsensor Terrasse Oben
- condition: trigger
id: Kontaktsensor Terrasse Unten
sequence:
- service: input_select.select_option
target:
entity_id: input_select.kontaktsensor_terrasse
data:
option: >
{% if states('binary_sensor.openclose_7') == 'on' and
states('binary_sensor.openclose_99') == 'on' %}
Open
{% elif states('binary_sensor.openclose_7') == 'on' and
states('binary_sensor.openclose_99') == 'off' %}
Tilted
{% elif states('binary_sensor.openclose_7') == 'off' and
states('binary_sensor.openclose_99') == 'off' %}
Closed
{% else %}
Error
{% endif %}
default: []
mode: queued
max: 20
This automation is very lenghy but what it does is basically, to check which window group of sensors the trigger belongs to and then set the state according to the state combinations of both sensors.
By using variables, there may be a better (shorter) way to set up this automation.
This works extremely reliable and possible use cases are e.g.:
- having a speaker (in my case Alexa) tell you which windows are fully open and which are only tilted when a rain sensor detects rain
- get a notification each time leaving the house (based on presence detection) telling me the correct status of all windows and in case a window is fully open I can go back and close it.
Best
Pete