achildrenmile.github.io

View on GitHub

Door/Window Sensor

2021-03-04 #Blog | #Windowsensor

Do you want to create your own door/window sensor and add to #HomeAssistant.
Great! So, here we go!

Window/door sensor

What hardware do you need?

Hardware - Put the stuff together

Platform - Home Assistant

In order to run the whole thing, you need to have a running Home Assistant instance including MQTT broker. You can find several guides and howto’s like this one in the net.

Software - flash the controller

Side note: This will give you a rough overview about the software steps. In case you have not yet programmed in Arduino Studio and no experience there are several tutorials out there like e.g. randomnerdtutorial.

Mount the hardware and test

Now mount the hardware near the window in order that the switch has contact when window is closed and no contact when the window is open. Try if the defined mqtt channel receives signal, when there is no contact and when there is contact. To do this, you just need to run a MQTT software like MQTT.fx, connect to the broker and subscribe to the corresponding channel. If everything is configured properly then you’ll receive the JSON messages. In case you don’t receive messages, you have to check the wiring as well as the configuration parameters in your secrets.h. Furthermore, you can connect to the controller via putty and check the serial print for more information, add debug information to the software, etc.

Home Assistant configuration

If all works well and you receive messages in the defined channel, you can do the last steps in order to add the sensor to your smart home platform.

Open the configuration.yaml of your Home Assistant instance and add following sensor to the sensor configuration:

  - platform: mqtt
    name: "YOUR WINDOW/DOOR SENSOR NAME"
    state_topic: "homeassistant/doorzone1/alarm"
    value_template: 'Window '

After that restart your Home Assistant. Then add the sensor to your Dashboard and you’ll see something like this:

HassDashboardWindowSensor

Congratulations, you created your own window/door sensor!