Skip to content
NodeMCU code to report home alarm sensor status to MQTT
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
extra Updating the schematic/breadboard drawing to make it more clear. Mar 28, 2017
LICENSE Updating blog post link May 5, 2018
config.lua Fixing boot issue when using GPIO0 on ESP8266 Apr 14, 2017
secrets.lua.example Updating wifi station config format to support newer NodeMCU firmware Mar 7, 2018
sensor.lua Fixing boot issue when using GPIO0 on ESP8266 Apr 14, 2017


A project to report home alarm sensor status via MQTT using a NodeMCU development board.


This was a pretty simple build, using only a few components

  • NodeMCU Development Board (can easily be found on Amazon or AliExpress)

  • Door sensors (any kind of switch will do)

Firmware Requirements

This project runs using a customized NodeMCU firmware package from the Cloud Build Service. The following modules are needed:

  • file
  • gpio
  • mqtt
  • net
  • node
  • tmr
  • uart
  • wifi


secrets.yaml contains the WiFi SSID/PSK and the MQTT broker credentials. Use the secrets.yaml.example file as a base.

config.yaml contains GPIO pin/device mappings as well as some basic MQTT topic/payload configuration.

Circuit Digram

The GPIO pins are configured with the weak internal pull-up resistor enabled. The switches are then connected to ground. When a switch is closed, the GPIO pin reads low.

Circuit Diagram


This code publishes a payload of open or closed to an individual topic for each sensor. The topic prefix, topic names, and payload are defined in config.yaml.

Other Links

Blog post

My full Home Assistant Configuration

You can’t perform that action at this time.