I am running Arduino code on the esp32. I am using <PubSubClient.h> for the mqtt functions. I am monitoring two switches and triggering one relay. I am using it on my garage door opener. Sometimes I leave the house and wonder if I closed the door. With my cell phone I can connect through my firewall and check the status of the door.
I will also monitor to see if the beam is broken. I leave the door up during the summer since our temperatures are 100-120 degrees F. This at least keeps the garage at outside temperature. Detecting the beam being broken will set off an alarm connected to the Raspberry Pi inside the house. This will alert me to intruders if there are any, human or animal.
If you are interested I can zip up my ESP32 code and schematic of the hardware that I bread boarded. The beam detect was the most interesting. The beam is a constant 3 msec 12 volt pulse stream. When broken the stream goes to a steady 12 volts. I use a NE555 as a missing pulse detector with a 10 msec timeout. You can't get through the beam in 10 msec. Of course a smart burglar may just step over the beam.
Node code is attached. You can see if there is a more simple way to detect the status switch.
[{"id":"71994e9.b9a4fb","type":"tab","label":"ESP32 Flow","disabled":false,"info":""},{"id":"6c5b5475.83bc84","type":"ui_button","z":"71994e9.b9a4fb","name":"Status Switch","group":"eb6c6b8d.b6f26","order":2,"width":0,"height":0,"passthru":false,"label":"Status ?","tooltip":"","color":"","bgcolor":"","icon":"","payload":"null","payloadType":"str","topic":"esp32/door/status","x":400,"y":120,"wires":[["58a47caa.389504"]]},{"id":"292b8758.7f9a8","type":"mqtt out","z":"71994e9.b9a4fb","name":"Publish","topic":"esp32/door/button","qos":"2","retain":"false","broker":"c3002906.2a182","x":660,"y":280,"wires":[]},{"id":"77d8c755.715a","type":"ui_button","z":"71994e9.b9a4fb","name":"Door Switch","group":"eb6c6b8d.b6f26","order":3,"width":0,"height":0,"passthru":false,"label":"Operate","tooltip":"","color":"","bgcolor":"","icon":"","payload":"pressed","payloadType":"str","topic":"esp32/door/button","x":390,"y":200,"wires":[["292b8758.7f9a8"]]},{"id":"f30ecb57.69abd","type":"ui_text","z":"71994e9.b9a4fb","group":"eb6c6b8d.b6f26","order":1,"width":0,"height":0,"name":"Door Status","label":"Door Status","format":"{{msg.payload}}","layout":"row-spread","x":670,"y":360,"wires":[]},{"id":"95f345b6.c0c44","type":"mqtt in","z":"71994e9.b9a4fb","name":"Return Status","topic":"esp32/door/stat-return","qos":"2","datatype":"utf8","broker":"c3002906.2a182","x":390,"y":280,"wires":[["f30ecb57.69abd"]]},{"id":"58a47caa.389504","type":"mqtt out","z":"71994e9.b9a4fb","name":"Publish","topic":"esp32/door/status","qos":"2","retain":"false","broker":"c3002906.2a182","x":660,"y":200,"wires":[]},{"id":"eb6c6b8d.b6f26","type":"ui_group","z":"","name":"Garage Door","tab":"5d370db7.ba1564","disp":true,"width":"6","collapse":false},{"id":"c3002906.2a182","type":"mqtt-broker","z":"","name":"MyPi","broker":"172.16.1.112","port":"1883","clientid":"pi","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"home/Relays","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5d370db7.ba1564","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
Edit: Corrected flow posting.