In today’s world, home automation has become increasingly popular, and one useful addition to your smart home setup is a door sensor. The MC38 door sensor is a cost-effective magnetic reed switch that can detect whether a door is open or closed. By integrating it with the Wemos D1 Mini and ESPHome, we can seamlessly monitor the state of the door in Home Assistant.

In this post, I’ll guide you through the advantages of using an MC38 sensor, how it works, and how to integrate it with ESPHome and Home Assistant to create a smart door sensor.

Why Use the MC38 Sensor?

The MC38 door sensor is widely used in home security systems for detecting door or window states (open or closed). It offers the following benefits:

  • Affordable: Low cost compared to many other smart home sensors.
  • Simple Installation: Easy to set up with just two wires.
  • Reliable Detection: It uses a magnetic reed switch, which triggers when a magnet is nearby (door closed) or moved away (door open).
  • Versatile: Can be used on doors, windows, or any opening structure.

Features of the Integration

Integrating the MC38 sensor with Wemos D1 Mini and ESPHome offers several features:

  1. Real-time Monitoring: Get instant notifications in Home Assistant when your door opens or closes.
  2. Internal Pull-up: No need for external resistors; the ESP8266 (Wemos D1 Mini) has built-in pull-ups that simplify the wiring.
  3. Customizable Behavior: Through ESPHome, you can add delay filters, change reporting frequencies, or trigger automations based on the door state.
  4. Wi-Fi Connectivity: The sensor is Wi-Fi enabled, thanks to the Wemos D1 Mini, allowing remote monitoring via your Home Assistant setup.

ESPHome YAML Configuration

To get started with integrating the MC38 door sensor into Home Assistant, you’ll need to flash your Wemos D1 Mini with the ESPHome YAML configuration.

Here’s a sample configuration for this integration:

esphome:
name: blr-front-doorsensor
friendly_name: blr-front-doorsensor

esp8266:
board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
encryption:
key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX="

ota:
platform: esphome
password: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.0.130
gateway: 192.168.0.1
subnet: 255.255.255.0
dns1: 192.168.0.3
dns2: 192.168.0.47

# Enable fallback hotspot (captive portal) in case Wi-Fi connection fails
ap:
ssid: "blr-front-doorsensor"
password: "XXXXXXXXX"

captive_portal:

# Binary sensor setup for MC38 door sensor
binary_sensor:
- platform: gpio
pin:
number: D2 # GPIO pin connected to the signal wire of MC38 sensor
mode: INPUT_PULLUP # Internal pull-up enabled
name: "MC38 Door Sensor"
device_class: door
filters:
- delayed_on: 100ms # Add a small delay to debounce the sensor
- delayed_off: 100ms

Steps to Flash and Integrate:

  1. Wiring the Sensor:
    • Connect the signal wire of the MC38 sensor to D2 on the Wemos D1 Mini.
    • The other wire should be connected to ground (GND).
  2. Configure ESPHome:
    • Add the above YAML code to your ESPHome dashboard and flash it to your Wemos D1 Mini.
    • Once the flashing is complete, the MC38 door sensor will be ready to report its status to Home Assistant.
  3. Integrate with Home Assistant:
    • After flashing, the new sensor will automatically appear in your Home Assistant dashboard.
    • You can now use this sensor to trigger automations, such as turning on lights when the door opens or sending an alert when it remains open for too long.

Controller & Sensor Used

Conclusion

With this integration, you can transform a simple door sensor into a smart sensor that enhances your home security and automation system. The MC38 sensor paired with the Wemos D1 Mini and ESPHome offers an affordable and customizable solution to keep track of the state of your doors or windows. Try it out and make your home smarter!

By Abhi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.