I just finished my door sensor with esphome and some cheap reed sensors.
Total cost for this project is about 15 €.
I’m using a WEMOS LOLIN32 ESP32 running on a 18650 Battery soldered to a strip board. Positive output is connected with an ADC Pin (34) and the reed sensor itself is connected with +3V and Pin 14 .
Pin 14 is defined as a binary GPIO sensor and also as the wakeup pin for the ESP itself.
If no motion is detected the ESP32 will sleep for 6 hours and wake up for 30 seconds publishing the battery value and the current door state. If the door is opened the esp awakes from deep sleep and sends the current state. See the esphome source code for further details
If the voltage of the battery drops below 3V the esp performs a complete shutdown (in theory (still to be explored in detail)).
Some pictures:
performance is fine, I change the battery every 2 months.
the battery alert isn’t working as intended. right now I use a “update check script” like sensor warning.
if the door sensor (or the signal strength) isn’t updated for 6 hours I’ll get a notification.
Conclusion for all my battery sensor powered esps right now:
bme280 with a cheap old battery and update interval once per hour: approx. runtime 1 month
same with a good new battery: 2-3 months
the doorsensor (also cheap battery but never out in the cold): ~ 2 months
Great, thanks. I’m planning to adapt it to use a roller lever switch for my freezer for that often gets stuck very slightly open. Reed switches seem all to be too sensitive for the small gap.
On my (fake?) lolin32 board +/- is twisted so I had to solder black to plus and red to ground… but that depends as usual on your hardware
On word for the analog reading, never got any alarms for the voltage drop… so it is basically useless.
Maybe @ottoWinter could explain that better than I can…
I advise you to use some kind of template sensors that checks if the sensors has not been updated for an defined amount of time (in my case >6h). Works pretty well =)
I have tried the exact same model to automate my mailbox I want a pushbullet to be sent to my phone when the postman drops a parcel … however i find that it takes about 10 secs for the esp32 to wake-up from deep-sleep and communicate to home assistant that the door was opened (by the postman). if it takes him (or her) less than 10 secs (ie. open door, drop parcel and close the door) then the esp 32 will wake-up but no change in status will be detected… I do not see how to fix that … while in deep-sleep is there any way for the esp32 to memorize the change that occured before wifi was fully reactivated? apart from leaving a note on the mailbox that the door should be left opened for more than 10 seconds of course
great post. I tried it out on my esp32 and it seems to work. Although Im using a PIR sensor on pin for the wakeup…
Only one issue, Battery drains in less than one day (1 x 18650) the room im testing on is quite busy so the PIR would trigger a lot. Any advise. I would like to get it working on a battery.
Busy rooms sounds like you could have a power source there? Maybe that’s better for your usecase…
Otherwise you could try to work with filters to force the minimum sleep time to a certain level (maybe need to experiment with a filter for the pir sensor too, to don’t retrigger a wake up) but this goes for sure on the detection ‘rate’. You will have kind of a dead zone after a detection - but maybe that fits your case, can’t tell?
Problem for you is that the device sucks most of it’s energy when wakin’ up (connecting to WiFi, api…) - which does it a lot’s of times in your case.
You could count the total runtime of the board (time in wake up) for a charge of battery (maybe with the duty_cycle sensor? The uptime sensor behaves weird when powered with battery…).
Anyone tried this code with an esp8266, alot smaller and can be mounted with a small litho for windows, doors would need a larger battery. There is a guy on youtube that has done it, but he is using arduino code, I would like to be able to have a yaml file to use with esptool, but I am not familiar enough to be able to modify the code. here is a link to the youtube video, his printed case is perfect and just a bit larger than the old wired reed sensors.