So I have a load of xiaomi sensors in the house now and am trying to develop an alarm system.
What I want to do is have a button on the front door that I press in order to arm the alarm system. If all of the windows are closed, the alarm will arm and activate after 30 seconds. Simple enough.
Where I’m having problems is that I’d like it to flag up if I’ve left a window open when trying to arm the alarm. That was easy to do when I had window sensors in just one room, but now theyre in 5 rooms it gets a little tricky and I ultimately want to get a TTS announcement saying which rooms the windows are open in (e.g. you’ve left windows open in the bedroom and front room) so I know where I need to go to close the windows.
I’ve made template sensors to merge all the sensors for each room as below:
- platform: template
sensors:
living_room_windows:
friendly_name: Living Room Windows
value_template: >-
{%- if is_state("binary_sensor.xiaomi_living_room_l", "off") and is_state("binary_sensor.xiaomi_living_room_mid", "off") and is_state("binary_sensor.xiaomi_living_room_r", "off") %}
Windows closed
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "on") and is_state("binary_sensor.xiaomi_living_room_mid", "off") and is_state("binary_sensor.xiaomi_living_room_r", "off") %}
Left window open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "off") and is_state("binary_sensor.xiaomi_living_room_mid", "off") and is_state("binary_sensor.xiaomi_living_room_r", "on") %}
Right window open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "off") and is_state("binary_sensor.xiaomi_living_room_mid", "on") and is_state("binary_sensor.xiaomi_living_room_r", "off") %}
Middle window open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "on") and is_state("binary_sensor.xiaomi_living_room_mid", "on") and is_state("binary_sensor.xiaomi_living_room_r", "off") %}
Left & middle windows open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "off") and is_state("binary_sensor.xiaomi_living_room_mid", "on") and is_state("binary_sensor.xiaomi_living_room_r", "on") %}
Right and middle windows open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "on") and is_state("binary_sensor.xiaomi_living_room_mid", "off") and is_state("binary_sensor.xiaomi_living_room_r", "on") %}
Left and right windows open
{%- elif is_state("binary_sensor.xiaomi_living_room_l", "on") and is_state("binary_sensor.xiaomi_living_room_mid", "on") and is_state("binary_sensor.xiaomi_living_room_r", "on") %}
All 3 windows open
{%- endif %}
icon_template: '{% if is_state("sensor.living_room_windows", "Windows closed") %}mdi:lock{% else %}mdi:lock-open-outline{% endif %}'
I dont want to do something similar for each template sensor as I want to add more window sensors in the future and dont fancy doing 64 elif’s for every possible combination of rooms with windows open.
Can someone suggest a simple way to get the automation to automatically identify which rooms have a window open (based on a single template sensor for each room) and allow me to combine them in a tts announcement?