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

Just for fun, I’d like to build an extremely simple ESPHome node that detects presence very reliable in my toilet area. My PIR sensor works fine for the rest of the bathroom; but not very well in the toilet area.

Could someone please help me pick out which specific parts I should buy (and from where to buy them) ? I need the whole thing to be as simple as possible; with the least amount of parts. I did my best to pick out the items I need below.

  1. ESP8266 NodeMCU
  2. Ultrasonic Distance Sensor.
  3. 3.3v Lithium Ion battery/battery holder with “ready to connect” wires to wifi module’s pins. No soldering/cutting needed.
  4. Compact pre-made generic enclosure to hold the parts securely in place.
  5. Short jumper cables

Thank you so much in advance for anyone that can help me get started with my first ESPHome project!

EDIT: In case there’s already a z-wave product that does all of this already, I would MUCH prefer to do that. Please let me know if there is already a product for this so I doing have go build one myself.

I’ve used these for a project in which I wanted to know how much a box was filled with stuff. They worked just ok, but not reliably enough for a distance measurement, but they should work good as a YES/NO presence detector. The advantage is that they have a long cable and they’re waterproof.

This, on the other hand, this has proved to be very reliable on distance measurements, but it’s not waterproof.

I had an idea for a “toilet detection sensor”, but my idea involved using strain gauges:

you can put them under the toilet seat and also have a rough idea on the weight of the person using it: you can then turn on some automations (like music, venting, lights) depending on the person sitting there.

cheers!

Thank you so much for all your suggestions. I’m having trouble deciding which sensor to use that would be most practical for both sitting down and standing in the toilet area. I would really appreciate which sensor you think would work best for both.

The weight sensor wouldn’t work for when I’m standing. I would only use that if the other options are not possible.

How large of an area can I focus the laser distance sensor? If I could detect presence by pointing the laser sensor in a general area where I sit or stand… that would probably work best. Or, maybe the water-proof sensor would be better for a larger area to focus on?

Also, which battery (and respective battery holder) would you suggest if connecting to a ESP8266 NodeMCU? I am not sure which battery/battery holder to use where I can simply just connect the two pins directly to the NodeMCU.

It’s an ESP32 in the form factor of the D1 mini. Great little board for an excellent price. Much more capable than the ESP8266, especially if you are going to battery power it (better deep sleep options).

Thanks @tom_l. My understanding is the 8266 modules might be a little easier to work with for my first ESPHome project; especially since I don’t need the extra capabilities like bluetooth. I there’s no difference, then I’ll go with one of these.

The ESP32 will be much easier for a battery powered device as you have better sleep options.

There is no extra difficulty in using an ESP32. You just get more memory, faster cpu, more analogue inputs, better sleep control, built in hardware for PWM control, etc…

Thanks tom. What battery/battery holder (with wires) would you recommend for the ESP32 D1 mini? I’m looking for something I can just connect directly to the 3.3v pin/ground pins without any fuss… or some kind of battery holder that could power the USB mini plug.

No idea. The battery capacity required will depend on your application, how long it is awake vs asleep, and what it is doing whilst awake.

You will also require a battery protection circuit to prevent over discharging, which can be a fire hazard. Unless you use protected 18650 cells.

Powering via the USB port using a good quality battery bank (the type used for recharging phones) could be one way. But be aware some of these shut down if the current is below a threshold you will definitely trip when your device is asleep,

I have no idea either. This is all brand new to me. I’m not sure where else to ask for which parts to buy for this presence detection node in the 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