Delivery driver walks down the driveway, I need fast and reliable indication of the event, e.g. Light flash, (I wear headphones all day)
- Philips Hue outdoor motion sensors can be slow and are not 100% reliable for capturing motion events (personal experience)
- CCTV motion events are even slower.
- Dedicating an old tablet to permanently monitor the CCTV for the driveway is a limited solution.
- Doorbell camera waits for button press to alert me, (delivery drivers don't always do this) OR they leave immediately after pressing the button.
- Use ESPresence to flash the light of any room in the house it detects that I am present in.
- IR beam trigger event uses tasker to launch my doorbell cam app, giving me a 5-10s head start and not relying on the door bell button press event.
Create a new ESPHome project, adding the code below, uploading it to the Wemos D1 when ready.
esphome:
name: stairs-beam-sensor
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Stairs Beam Sensor Fallback Hotspot"
password: "i7T22TUhHHYq"
captive_portal:
binary_sensor:
- platform: gpio
pin:
number: D1
inverted: true
mode:
input: true
pullup: true
filters:
- delayed_on: 300ms
name: "Stairs Beam Sensor"
device_class: motion
Check that the new ESPHome device has been created and added to the devices list
Click on the Stairs Beam Sensor device to see a list of entities. You can test the Motion entity by connecting GND to D1 on the Wemos D1. The motion entity will change from "Clear" to "Detected"
Connecting D1 to GND to simulate the IR beam sensor detecting motion
Finally, you can add the new Stairs Beam Sensor entity to a Home Assistant dashboard
Now that the sensor has been coded, tested and is recognised by Home Assistant, it's time to actually make it do something useful.
Home Assistant automations can provide that functionality.
- Indoor beam sensor | Outdoor beam sensor (either sensor will work)
- Wemos D1 Mini
- R-78E5.0-0.5 switching regulator
- DC power jack - DC005 (optional)
- XH-2A connectors (optional)
- Dupont crimpers (optional)
IR beam relay is connected in the Normally Open (NO) position
EasyEDA PCB file | EasyEDA Schematic file | Gerber files for PCB
I followed this excellent tutorial, to flash the Wemos D1 Mini with Tasmota to send an ON / OFF trigger via MQTT to Home Assistant. I got this working but hit a few hurdles owing to my still learning Home Assistant.
Questions I had after reading the tutorial:
- How do I configure the MQTT part of Tasmota on the Wemos?
- How do I congifure Home Assistant exactly to recognise the Wemos and show the motion output?
1. Configuring the Wemos with Tasmota
-
Ensure your MQTT server is setup in Home Assistant
-
Obtain the IP address of the newly flashed Tasmota Wemos device from your router
-
Go to the IP address of the new Tasmota device to configure MQTT
Configure MQTT on Tasmota
- Main Menu > Configuration > Configure MQTT
- Enter the IP address of your MQTT server, (Home Assistant, IP address if using the Mosquitto add-on)
- Enter the MQTT username and password
Configure MQTT Topic Name
-
Main Menu > Configuration > Configure Other
-
Under Device Name, enter a name that will be used to pass MQTT messages
Confirm MQTT is sending messages using the chosen topic name
2. Configuring Home Assistant
To get Home Assistant to recognise the incoming MQTT messages, I added the following code inside the mqtt.yaml (Here for reference only, I no longer use this code, see V3 below.)
binary_sensor:
# Name used for entity
- name: "Beam sensor motion"
state_topic: "stat/Tasmota_Beam_Sensor/POWER"
payload_on: "ON"
payload_off: "OFF"
qos: 0
device_class: motion
# icon: "mdi:leak"
Adding the Sensor to an Entities Card
Transferring from a prototype board to a custom PCB, I used this voltage regulator.
I should have paid more attention it was the wrong one:
5.5V DC Voltage Regulator Step Down Power Supply Module 4.75V-12V to 5V 800mA
After destroying (3) ESP8266's, I decided to experiment with ESPHome and revise the entire circuit, looking for a better regulator to power the Wemos.
1st custom PCB showing incorrect regulator headerAll working code and PCB designs are at the top of the page.
I experimented with: (aka, trying anything and everything to get it working):
- Powering the esp and the beam sensor seperately, which worked well.
- Pulling the resistor high in ESPHome
- Setting inverted to true
After a lot of "experimentation", and confusing myself about sensors not closing, I reached out to the Home Assistant community and got some simple and excellent advice from Aruffell and Julian Hall
I made the following checks and alterations
- Beam sensor relay was a DRY relay (no connection on either relay terminal to the supply +ve / -ve)
- Made sure the relay was set to normally open (NO) I actually hadn't checked this previously
- PCB optimisations for solder pad size, spacing and track width
- Changed the V1 voltage regulator to a L7805CV. It ran too hot so I eventually settled on a switching regulator R-78E5.0-0.5