mailbox is not surrounded by metal (otherwise antenna to the outside is needed)
parts list:
Wemos D1 mini
reed switch (i used the MC-31B) and magnet
triple AA battery holder
project box (i used on of those cheap black 100x60x25mm enclosures)
wires
construction:
flash the wemos with code that does the following in order:
a. connect to wifi (ideally with static IP for less power consumption)
b. connect to mqtt broker
c. send mqtt message, e.g. wemos/mailbox/openlid = true
d. ESP.deepSleep(0) which means deepsleep (power consumption ~ 0.1 mA) until it is reset
install reed switch and magnet to mailbox so that opening the lid toggles the switch
connect the reed switch to the RST and GND pin of the wemos d1 mini
connect the battery holder to 5V and GND pin of the wemos d1 mini
put batteries in and all the stuff in the enclosure and then in your mailbox
configure corresponding mqtt sensor and a automation of your choice in home assistant
Installed it two weeks ago. With those 2000 mAh batteries my (very rough) estimation is that they will last for one year. Depends on temperature and how often it is opened of course.
I had to replace the batteries two times since June.
I’m now testing with three rechargeable NiMH batteries (eneloops) connected to the 3V pin of the d1 mini.
I’m pretty new to this, but your example has been really helpful. Thank you! I have things working (reed switch changes the state to “true” in Home Assistant) but I’m wondering how you reset the state after the mailbox door has been closed. At that point, the ESP is in deep sleep and isn’t communicating the closure. Are you doing that through an Automation? If so, mind sharing the details? I’m not sure how to manually change the state back to anything other than true, once it’s been triggered. Thanks!
Really nice to hear that my description was helpful for you.
To be honest I don’t even use a sensor for that anymore.
You can just use the mqtt trigger for your automation and you should not need a sensor at all.
If you absolutely want to have a sensor you could add the off_delay to the mqtt binary sensor configuration you already have, I assume. Then you possibly also have to change the payload in the arduino code from “True” to “On”, but could also work without that change. I haven’t tested that.
Thanks for the reply! I guess the mqtt trigger makes more sense. I ended up getting the state changed back manually with mqtt.publish and that seems to do the job but maybe I should just scrap it and do it the better way you’ve suggested. Either way, thanks a bunch for your help. Really appreciate it.
…oh, one other question…I’m assuming you need GPIO 16 connected up to RST as well in order to enable Deep Sleep, is that correct? Or does the presence of the reed switch somehow take the place of that connection?
ESP.deepSleep(0); works without connecting GPIO16 to RST because the module does not have to wake itself after a certain time span.
The reed switch will wake up the wemos d1 mini just like the little physical reset button which does not need the GPIO16-RST connection either.