Help needed to build my very first compact ESPHome + esp8266 + Sensor for toilet area

Designing a battery powered wifi device is not the best beginner project. You don’t have power nearby?

I wish I did. It’s just a small closed off toilet area adjacent to the general bathroom. I didn’t realize the battery would be so much work.

@tom_l (or anyone) Would the below item work for me? It seems to have a builtin battery holder and it’s an ESP32. I’m very motivated to this project… and, would prefer not to give up.

ESP8266 ESP32 ESP-32S For WeMos WiFi Wireless Bluetooth Development Board CP2102 CP2104 Module With 18650 lithium Battery Shield

Rough back of the envelope calculation:

1x 18650 cell = 2200mAh
ESP average current = 100mA

Therefore the esp will last 22 hours on that one battery if on all the time. If the ESP is only on for a tenth of the time (1min awake, 10 min asleep) it will last 220hrs, or 9 days. Allow for only 80% depth of discharge to protect the battery and it will only last a week.

This is a very rough estimate, neglecting sleep current and the 100mA average is probably a pretty rough guess too.

Thanks for the calculations. I’m guessing the device would be almost always be using sleep current only; unless triggered by the sensor. Wouldn’t battery usage be similar to zigbee/zwave motion detectors with much smaller lithium-ion battery capacities? It would be fine with me if that’s the case.

What’s the lighting situation? They sell light socket adapters which would give you an outlet for a DC adapter powering your circuit. May not be the best looking setup, but it does give you another option.

I’m thinking about the ultrasonic option myself, by mounting an ESP/sensor inside the vanity in that small room.

@zmodem that’s an awesome idea! Maybe I could get one of these to fit inside the ceiling light above the toilet:
ceiling-light

I might be able to put all the components inside the light cover above… having only a tiny sensor and wire mounted next to the ceiling light cover.

The only thing left for me to decide on is which sensor to get.

Which sensor would work best for me if I place it on the ceiling? I need the sensor to detect a person whether they’re standing or sitting below it. Would the laser sensor work better or the Ultrasonic sensor?

Lastly, what enclosure can I use for the ESP32? Or, can I just keep things barebone?

Can someone please recommend me an ultrasonic sensor I can connect directly to the ESP32 (or ESP8266) with only jumper cables… that’s also supported by ESPHome? Preferably something with the speaker/microphone connected directly to the PCB. I wanted to use the HC-SR04; however, it looks like there’s a voltage incompatibility between the HC-SR04 and ESP modules. Maybe I misunderstood?

Well, if you have the two lid toilet (first covers the toilet, second one is for sitting onto or lifted when standing), you could simply use switches to detect the open/close lid states. These swiches could then be used to wake up your ESP32. The combination of triggered swiches gives you start of business, sitting/stanting state end of business. So you could even have statistics about the users sitting/standing behaviour and the corrosponding business durations.

@CeeCee thanks for the suggestion. The lid to my toilet is always in an open state. Also, I would prefer not to keep any electronics that close to my toilet, unless I have no other choice. I like @zmodem’s idea of using a light socket power adapter to power the ESP32 via mini-USB cable; keeping the ESP32/sensor on my ceiling.

Well I have the HC-SR04 up and running in my automatic plant water system (monitors water level).
Your ESP, if somehow powered by 5V, has a 5V pin. So you can connect the HC to that one. It understands teh signals from the ESP to the module. The voltage from the module to the ESP is 5V, therefore too high to safely use it. But if you are comfortable with a bit of soldering, you can mod the module like this:

https://www.instructables.com/id/Modify-Ultrasonic-Sensors-for-3-Volts-Logic-prepar/

Then you should be able to easily use this module with the ESP sensor component:
https://esphome.io/components/sensor/ultrasonic.html

@CeeCee thanks for the tips. I would like to keep this project as simple as possible; avoid any extra work that I don’t have to do. It looks like the US-100 emulates an HC-SR04; and, doesn’t need a logic shifter… just connects the jump wires wires directly; utilizing only 3.3v.

UPDATE: Man, I’m so bummed out. I just opened up the light/fan cover in the ceiling of my bathroom. There’s definitely not enough space for a light socket adapter splitter and a USB power adapter. Not even close.

My only choice is to use an efficient battery powered OIT device.

Is it possible to use an existing off-the-shelf wireless low-resolution camera into a binary sensor for HA?

just my two cents, and please excuse my personal opinion at this point, but as a guest in your house, I would feel quite uncomfortable with a camera pointed on me while doing private business.

Apart from that, from my experience cameras are quite energy hungry (in a way that you will have to charge quite often).
If it is still about presence detection, maybe I can suggest another route. Recently (?) China is flooding the market with zigbee sensors that are energy effcient and “easy to install”. See Dr. Zzzzs video:

So there is this Xiaomi device f.ex.
https://www.aliexpress.com/item/4000151421805.html?spm=a2g0o.productlist.0.0.47fe32afDHdmk2&algo_pvid=e6c75bc3-b966-48b6-a33f-a4a0fe807997&algo_expid=e6c75bc3-b966-48b6-a33f-a4a0fe807997-1&btsid=0b0a119a15979888170377157e2989&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

That will do battery operated presence detection and will last a good while on the batteries.

Hope that helps,
Christian

Maybe you can try using a different sensor like HFS-DC06. Video for reference.
Does it have to look good? I made a crude battery powered temp sensor.

Thanks for the video. I like that the HFS-DC06’s sensitivity can be adjusted with it’s builtin potentiometer. The video shows that it draws a wopping 14mA @3.3v (as opposed to typical PIR sensors at <1mA @3.3v). The other sensors in the video draw around 3mA; however, they have other sensitivity-related limitations that the HFS-DC06 doesnt have.

What kind of battery would I need to make it last at least 2-3 months? It might not be feasible to use a battery source.

With most reasonably modern motion sensors, the current drawn by the esp while wifi communicates, will be the design driver for battery life. So the main question to answer when doing anything esp+battery is, how often will it need to send data? I think tom_i gave similar advice above.

I have designed some custom battery powered esp motion devices that last years between charges if only tripped like once a day. Same things might last a few months if they hey activated a few times a day… burn out in weeks if I tried using them in a heavy traffic area. So the big driver of battery life, no matter how elegant the circuit design is, will be simply how often it waked every day where it will be used.

Answer that, and any decent nerd can run the calcs to determine battery size for X hour life.

[Edit: Also, if you can modify the cover/housing of the fan safely, you may have room to wire up something that has a mains powered supply (sonoff or similar). The problem I forsee with that is the power up there is likely not constant, but switched at the wall). There may be another way to get this done though… may have to break down and get a nice zwave motion that hits the potty area.

Radar motion sensors like the rcwl0510 are nice when you need to ‘see through’ a wall. However that can be an issue if seeing through certain walls is not desired, since those things have little directional control.

@CeeCee, This project wasn’t intended for any of the bathrooms in my home, except for my personal bathroom attached to my bedroom. But, yeah, the camera idea was a bad idea in more ways than one.

Isn’t the Xiaomi device just another PIR sensor? If it is, I already have a bunch of those (zwave/zha).

Yes, just a PIR.

Guys… based on my current options, I’ve decided to just add a second PIR sensor dedicated to the the toilet area. It’s not perfect; but, it would be a little better than what I have now. I’ve already spent way too much time on this. If I was able to add an ultrasonic sensor (or radar sensor with attenuated sensitively) in the existing light/fan enclosure relatively easily, I would probably do that. Thanks for all your responses!

1 Like