The goal of this project is to make a battery powered WiFi door or window sensor that is completely hidden from view.  On the market, we have seen several battery powered sensors, but all require a small box and magnet to be stuck the outside of the door where it can be visible.  We would like to emulate the look of a completely concealed wired door sensor, but still have wifi connectivity and battery power.

We have seen these type of door sensors that can fit in a 3/4" hole drilled in the door jamb for zigbee and insteon, but not WiFi

hidden door sensor

The project starts by using the ESP-01F ultra miniature wifi module.  At only 10x11x2mm it is a perfect module to hide in a door jamb.  To this module we added a hall effect sensor to detect a magnet and a battery boost circuit to power it from a 3V CR123A lithium battery.

Door Sensor Back 

Door Sensor Front

Software

We plan on supporting at least two firmware builds on this board, ESPHome for Home Assistant and a custom firmware for MQTT and E-mail connectivity. 

ESPHome

The device configuration under ESPHome is quite simple. 

We set the device to send an message that says the door is open whenever the device wakes up. We then sleep the device for 2 minutes.  Further, we override the will message and shutdown message to also say the door is open.  This way, the only message the device can every send is that the door is open.  We need to do this since the device is completely powered down by the hall effect sensor as soon as the door is closed.  Closed must be handled by home assistant.

With this code the device will wake up every 2 minutes and send another open message.  Even this 2 minute wake up uses a good amount of battery, thus the completely shut down when the door is closed.

esphome:

  name: door-sensor-1

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "password"

wifi:
  ssid: "SSID"
  password: "PASSWORD"


#wifi:
#  ssid: !secret wifi_ssid
#  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Door-Sensor-1 Fallback Hotspot"
    password: "PASSWORD"

captive_portal:


mqtt:
  broker: IP
  username: mosquitto
  password: mosquitto
  birth_message:
    topic: doorsensor1/state
    payload: open
  will_message:
    topic: doorsensor1/state
    payload: open
  shutdown_message:
    topic: doorsensor1/state
    payload: open
  
deep_sleep:
  run_duration: 10s
  sleep_duration: 120s

Under Home Assistant we then treat the device like a binary sensor that only sends an "ON" state (i.e., a PIR Motion Sensor)

The open message from the sensor is defined as the "on" payload and we also create an "off" payload (which is never actually sent by the door sensor).  Further, we add a timer to automatically set the state to the off value after 130 seconds (a little longer than the timeout of the updates from the door open wake up timer).  This way, every door open event will last about 2 minutes.  

binary_sensor:
- platform: mqtt name: "Test Door Sensor" state_topic: "doorsensor1/state" payload_on: "open" payload_off: "closed" off_delay: 130 device_class: door


Hardware

A hall effect sensor is used to turn off the power to the board when the door is closed.

Hall Effect Sensor

The battery is boosted to 3.3V via a TPS6104 device.  Unfortunately we made a small mistake here.  We were thinking when this device was disabled it would go to the sleep current in the datasheet.  However, there is a perfect leakage path between from the battery through L1 and D1.  Sure, when U1 is disabled the 3.3V is only about 2.7V,  but this is still plenty to turn the ESP8266 on. 

Door Sensor DC DC

The simple solution for now is to feed the PWR_EN from the hall effect sensor to the enable pin of the ESP-01F with a small added wire.  This way when the hall effect sensor shuts down the board it shuts down both the ESP-01F and the DC/DC converter.  On the next rev of the board we will remove the TPL5111 timer we had put on as a test and use a fet to gate the battery into the DC/DC based on the hall effect sensor instead.

ESP-01F PWR_EN

First Case

First version of the case.  A few minor tweaks and it will be ready to go.

The wires are just for initial debug.

wifi door sensor case 1

wifi door sensor case 2

 To Do:

  • Custom firmware with captive portal instead of ESPHome
  • 3D Printed case with battery holder - IN PROGRESS
  • Power Improvement: Add a power gate instead of disabling the ESP and Power Switcher

Schematic