Use an ESP32 Arduino as a toggle button that communicates state over MQTT. Optionally, if a PIR motion sensor is connected, motion state can be reported as well.
Pressing a button toggles the light and the state of the binary sensor. If the light is toggled on, an "ON" message is sent. If the light is toggled off, an "OFF" message is sent. The state of the light can also be remotely controlled via the mqtt_sub_topic.
If motion is detected, then "ON" message is sent to mqtt_motion_topic.
To get started:
- Copy config.h.template to config.h
- Edit the values to match your setup
- Open main/main.ino in Arduino IDE
- Install the PubSubClient library (Sketch -> Include libraries -> Manage libraries)
- Select the device type, compile, and run. If necessary, install support for the relevant device (e.g. ESP32).