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)
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.
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.
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.