Mini ESPHome Motion & Light Sensor - D1 Mini

I use a lot of ESPHome based motion and light sensors in my Home Assistant setup. If there is a readily available 5 volt supply, I will use them in place of Zigbee sensors. I just find them more dependable.
The aim of this project was to come up with a 3D printable case design that was as small as practically possible, using the readily available Wemos D1 Mini (clone) ESP8266 board, together with an AM312 motion sensor and a simple LDR based light sensor.
The design I came up with isn't much bigger than an Aqara Zigbee sensor and doesn't look bad either (IMHO).




Design Features
- No-screw clip frame for the D1 Mini. Fits the majority of clone boards that have angled corners at the Wi-Fi antennae end.
- Additional frame to hold a small section of strip-board. Can make the wiring more straigtforward as there is only a single 3.3v and ground pin on the D1 Mini.
- Push in mounting for the AM312 movement sensor.
- Push through mounting for the LDR (dab of superglue gel or some double-sided tape to secure it).
- Two outer case designs. The one pictured and an additional design with a window for a DHT22 temperature/humidity sensor.
Please note, the DHT22 will be in very close proximity to the D1Mini which will significantly skew the temperature readings. - Top and bottom panels are secured with M2 cap head hex screws (minimum 5mm long).
- Open backs to the D1Mini and stripboard mounting frame and additional slots for routing hook-up wires.
NOTES
- Try and get D1 Minis without the header pins pre-soldered. They will not fit in this case and would be a pain to remove!
- Most AM312 sensors come with a 3pin DuPont header already soldered to the board - there is no room for this - it will need to be removed.
- You will need some flexible hook-up wire. I like to use multiple colours to indicate what goes where.
- You will need a 10k resistor to act as a voltage divider when used in combination with the LDR.
- To keep the design as compact as possible, the Micro USB is not used to provide power. I simply cut and stripped the end of a USB cable and soldered the power conductors directly on the D1 Mini +5v and GND.
Order of Assembly
It can be a bit of a juggle getting everything connected and assembled. It's also quite difficult to explain so I would suggest doing a dry run based on the following order:
- Glue the LDR in place (you may need to open the holes slightly).
- Trim the LDR Leads so they are about 10mm long.
- Solder flexible hook-up wire to the LDR leads - make it at least twice the height of the case. It's easy to trim!
- Bend the LDR leads in opposite directions against the inside of the case and put some electrical tape over them (sticking them to the inside of the case).
- Solder hook-up wires to the AM312 (same length as above).
- Push the AM312 through the front of the case. It's a tight fit so you may want to temporarily remove the dome (it will just pull off) and push against a hard, flat surface).
- I used the stripboard to 'expand' the 3.3v and GND connections on the D1 Mini. You don't have to do this - you can just link between the sensors but, I do find mounting the 10k resistor is easier if soldered on the board.
- If using the 2 frames, place them back to back and run the wiring through the frames, soldering onto the relevant D1 Mini pins.
- Solder on the 5 volt supply wires.
- Put a small cable tie around the 5v supply cable (right at the point where it is stripped). Make sure it is tight so it can act as strain relief.
- Slip the 2 frames into the case slots.
- Give it a test before attaching the top and bottom panels!
Breadboard Circuit Diagram

Sample ESPHome Configuration
substitutions:
devicename: replace-this-with-your-device-name
upper_devicename: Give it a nice name
esphome:
name: "${devicename}"
platform: ESP8266
board: d1_mini
logger:
api:
ota:
- platform: esphome
wifi:
ssid: !secret ssid
password: !secret wifipass
# Set a static IP or reserve one for each device on your router
# manual_ip:
# static_ip: 192.168.0.10
# gateway: 192.168.0.1
# subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${devicename} Hotspot"
password: ""
captive_portal:
web_server:
port: 80
binary_sensor:
- platform: gpio
pin: D5
name: ${upper_devicename} Motion
id: pir
device_class: motion
filters:
- delayed_on: 300ms
- delayed_off: 30s
# The delayed on filter above can help with false triggers
# Delayed off is the time it takes for the sensor to effectively reset.
sensor:
- platform: adc
pin: A0
name: ${upper_devicename} Lux
update_interval: '30s'
unit_of_measurement: lux
filters:
- lambda: |-
return (x / 10000.0) * 2000000.0;
# Light measurement with an LDR is never going to be accurate compared with a true lux sensor.
# The lambda filter above gets it within a reasonable and useable ballpark3D Print Files
STL files for this project are available on Cults3D:
https://cults3d.com/en/3d-model/gadget/mini-motion-and-light-sensor-wemos-d1-mini
Buy Me A Beer
As you can imagine, this design took several hours to perfect.
If you find it useful, please consider a small donation via Paypal:
https://www.paypal.com/paypalme/johnbeardon
Thank you!





Comments