ESPHome: Reed Switch

This summer my living room window is open quite often and I would like to see if I forgot to close it, while I am not at home. I looted reed switches years ago somewhere and never tried using them.

First I experimented on a breadboard with a Pico. But when everything worked out I replaced the Pico with an unused cheap ESP8266 from years ago and deployed it to the living room window I open often.

Using a reed switch is as easy as it can get. When used with a Pico or an ESP connect one side to Ground and the other one to a Pin that can be pulled up. For the ESP8266 this doesn't work for all the Pins, I used D4.

The switch with a magnet attached looks like this:

img1

I setup at a window by attaching the magnet to the moving part (the window) and the electronics (the reed switch and the ESP/Pico) to the frame. My setup with the ESP8266 looks like this:

img2

I used multiple magnets to be sure the switch will work.

The ESPHome setup for the ESP8266 (I ommit the wifi, api, ota part here):

esphome:
  name: lolin1

esp8266:
  board: nodemcuv2
  framework:
    version: recommended

binary_sensor:
  - platform: gpio
    pin:
      number: D4
      mode:
        input: true
        pullup: true
    name: "Living Room Window"
    device_class: window

Important here is setting the pullup and input to true.

In Homeassistant:

img3

Of course this can be used to trigger actions in Homeassistant. I am thinking about an LED at the door to my appartment to immediatly see if the window is closed when leaving. But maybe this is a bit too much. :)