Perimeter Monitoring w/ a Laser Beam

Greetings…

I thought I would offer what solution I have in place to monitor perimeter activity. I have several laser beams that I use to trigger, not alarms, but notifications of someone or something such as a vehicle passing through my perimeter. The events can, of course, be tailored to trigger any kind of action you desire.

I use the Seco PN# E-931-S35RRQ Laser beam. It is available on Amazon. It runs around $50. I have had great success with these. I use the following ESPHome code to create the sensors. I have never had a single false positive. When the laser beam is broken, it was indeed broken. Albeit I have had a few birds fly though it and triggered it. If the beam is placed high enough off the ground, it will prevent animals such as dogs, cats and the like from triggering. And aside from owls and bats, no flying creatures at night, at least not in my neck of the woods.

Here’s the code I use.

esphome:
  name: 'gatecontroller'
  friendly_name: Frontgate Controller

  platformio_options:
    upload_speed: 115200

esp32:
  board: 'wt32-eth01'
  
ethernet:
  type: 'LAN8720'
  mdc_pin: 'GPIO23'
  mdio_pin: 'GPIO18'
  clk_mode: 'GPIO0_IN'
  phy_addr: 1
  power_pin: 'GPIO16'
  manual_ip:
    static_ip: 10.2.4.10
    gateway: 10.2.4.1
    subnet: 255.255.255.0

#web_server:
#  port: 8089
#  local: true

mqtt:
  broker: 10.2.0.44
  username: !secret mqtt_user
  password: !secret mqtt_password
  topic_prefix: frontgate

logger:
   on_message:
     level: DEBUG
     then:
       - mqtt.publish:
           topic: frontgate/log
           payload: !lambda |-
             return "level: " + to_string(level) + "|tag: " + tag + "|message: " + message;

api:
  encryption:
    key: !secret api_key

ota:
  - platform: esphome
    password: !secret ota_password

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

binary_sensor:
  # Gate Status - Reed Switch Open/Closed?
  - platform: gpio
    pin:
      number: 15
      mode:
        input: true
        # pullup: true
        pullup: true
        output: false
        open_drain: false
        pulldown: false
      inverted: false
    id: gate_position
    name: Front Gate Position
    icon: "mdi:door-sliding-lock"
    device_class: door
    # filters:
    # - delayed_on: 10ms
    # disabled_by_default: false

# GATE BEAM1    
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - GRAY Wire  - Normally Closed - is a CLOSED circuit which opens when the beam is broken
#   - WHITE Wire - Comm
#   - BLUE wire  - Ground
#   - BROWN Wire - Voltage 24v
  - platform: gpio
    pin:
      number: 14
      # mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      # inverted: True
      mode:
        input: true
        pullup: true
        output: false
        open_drain: false
        pulldown: false
      inverted: false
    id: gate_beam1_sensor
    icon: "mdi:dots-horizontal"
    name: "Beam 1 Status"
    device_class: motion
    filters:
    - delayed_on: 10ms

# Perimeter BEAM2
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - GRAY Wire  - Normally Closed - is a CLOSED circuit which opens when the beam is broken
#   - WHITE Wire - Comm
#   - BLUE wire  - Ground
#   - BROWN Wire - Voltage 24v
  - platform: gpio
    pin:
      number: 12
      # mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      # inverted: True
      mode:
        input: true
        pullup: true
        output: false
        open_drain: false
        pulldown: false
      inverted: false
    id: perimeter_beam2_sensor
    icon: "mdi:dots-horizontal"
    name: "Beam 2 Status"
    device_class: motion
    filters:
    - delayed_on: 10ms
    
# GATE OPENER RELAY
switch:
  - platform: gpio
    pin: GPIO2
    name: "Gate Relay"
    id: gate_motor_controller
    internal: false

sensor:
  - platform: dht
    pin: GPIO4
    temperature:
      name: "Gate Controller Box Temperature"
    humidity:
      name: "Gate Controller Box Humidity"
    update_interval: 60s

cover:
  - platform: template
    device_class: gate
    name: "Frontgate Status"
    id: template_cover_frontgate
    lambda: |-
      if (id(gate_position).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      - switch.turn_on: gate_motor_controller
      - delay: 300ms
      - switch.turn_off: gate_motor_controller
    close_action:
      - switch.turn_on: gate_motor_controller
      - delay: 300ms
      - switch.turn_off: gate_motor_controller

You do realize that if a configuration option is (False - OFF) then there’s no need to include all of that extra clutter in your code, right? Most of them if not all of them are in that state by default to begin with anyway and it doesn’t make the code look complicated or sophisticated to where adding it makes the author look sophisticated or something. It’s really kind of silly to purposely add all that but whatever…

Except for bats and birds triggering it? That’s what a false positive means…

IR laser break beam sensors are pretty cool but, i really feel like they have a limited application and really only work in places where you can 100% funnel people to go through it and any possibilities of the sensor being gone around from either side is a major problem IMO. I personally think that the best way to incorporate them is into a group of sensors that each complement a different one so that you lean into their strengths and limit their weaknesses.

There’s a lot of stuff in your code that seems excessive and some stuff just seems completely unnecessary or just out of place and i would challenge you to keep working on improving it.

Just a suggestion too but, have you considered creating a “person/pet” counter for inside of the area people must pass the sensor? It would take a pair of sensors to be able to detect which direction the person is moving but, it would give you basically a “people counter” and will keep track of how many have entered, left, or how many people are still inside that zone and all based on 2x laser sensors spread apart roughly 2" from each other.

Another suggestion is why not incorporate this “position feedback” sensor directly into your Cover entity for the gate? The cover integration is has configuration options to configure these sensors within your Cover. You only need a minimum of 1 position sensor to configure the Feedback Cover which IMO is far better and if you add that second feedback sensor(Reed Sensor) then it will make it much more accurate as far as where the gate position is at as well as it allows you to verify 100% if its Open/Closed based on physical sensors and not just assuming the state based on some basic logic/automations.

Feedback Cover - ESPHome - Smart Home Made Simple Feedback Cover - ESPHome - Smart Home Made Simple

binary_sensor:
  # Gate Status - Reed Switch Open/Closed?
  - platform: gpio
    pin:
      number: 15
      mode:
        input: true
        # pullup: true
        pullup: true
        output: false
        open_drain: false
        pulldown: false
      inverted: false
    id: gate_position
    name: Front Gate Position
    icon: "mdi:door-sliding-lock"
    device_class: door
    # filters:
    # - delayed_on: 10ms
    # disabled_by_default: false