Coder Social home page Coder Social logo

ir-beam-sensor's Introduction

IR Beam Sensor using ESPHome

Scenario

Delivery driver walks down the driveway, I need fast and reliable indication of the event, e.g. Light flash, (I wear headphones all day)


Problem with existing methods

  • 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.

End goal

  • 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.



ESPHome Code

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



Bench test the code

Check that the new ESPHome device has been created and added to the devices list

New ESPHome device added to 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"

All information for new stairs beam sensor device

Connecting D1 to GND to simulate the IR beam sensor detecting motion

Bench testing the Wemos D1 ESP Home code by bridging ground and D1

Finally, you can add the new Stairs Beam Sensor entity to a Home Assistant dashboard

Adding new stairs beam sensor to an entities card




Flash a light

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.

Stair beam sensor in Home Assistant automation to flash a ligh




Building a custom PCB

Parts




Indoor IR beam sensor connections

Indoor IR beam sensor wiring for volage supply and relay contacts to Wemos D1

IR beam relay is connected in the Normally Open (NO) position

Indoor IR beam sensor wiring with normally open (NO) setting connected




Custom PCB

EasyEDA PCB file | EasyEDA Schematic file | Gerber files for PCB

Schematic for IR beam sensor pcb

PCB layout of IR beam sensor project

3D view of PCB layout




Project History


V1 - Oct 2021

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:

  1. How do I configure the MQTT part of Tasmota on the Wemos?
  2. 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

      Tasmota topic naming

    Confirm MQTT is sending messages using the chosen topic name

    • Main menu > Console

      Tasmota console showing correct topic name is being used

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

Enitities card in Home Assistant showing motion sensor

Adding IR beam sensor motion entity to an entities card in Home Assistant




V2 Jan 2022

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.

Version 1 of custom PCB for IR beam sensor

1st custom PCB showing incorrect regulator header


V3 - Dec 2022 (final)


All 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

ir-beam-sensor's People

Contributors

sygad avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.