A fully functional, anti false positive, Alarm system

Problem
Cameras are helpful, but most systems are triggered by a simple spider practicing bungee rope in front of them. PIRs are excellent in a security setup, but any cat or dog walking in front of them or a sudden variation in temperature will trigger them.

Goal
Create an anti-false positive, extremely reliable security system.

Prerequisite

  • A functional HA
  • A PC to run Blueiris
  • Some Cameras (I use some Dahua & Wyze but most would do)
  • A tool to clear up false positives on Cameras (I use Sentry AI)
  • An MQTT server
  • Some PIRs (I use Zwave ones, from NEO Coolcam, NAD-PD01Z)
  • [Optional] smart speaker (like sonos)
  • [Optional] AI sentry for further anti-false-positives
  • [Optional] pushover

Camera config
It varies a lot based on your camera model, your network LAN/WLAN connexion quality, and many other factors. Those are broad guidelines, and nothing is set in stone.

On my Dahuas:

  • Main video stream: H265 / smart codec off / 1080p / 15 FPS / CBR / 1536 kb/s / I frame: 30
  • Sub video stream: H264.H /704x576 / CBR / 1024 kb/s / I frame= 50 / SVC:1

Blueiris config
Blueiris is a Windows-based camera system (NVR or VMS), able to deal with most cameras, record, detect, alert, etc. It’s supported in HA through HACS, and will pop every sensor & service needed in HA.

There are tons of parameters in there. So instead of covering them all, I’ll soon paste some screenshots of the most important ones.

[COMING SOON]

PIRs config
For neo coolcams Z-wave PIRs:

  • motion sensitivity : 60
  • on/off duration : 30
  • re-trigger : 8
  • Temp differential threshold: 100

HA group config

security:
  name: Security sensors
  entities:
    - binary_sensor.cam1_motion
    - binary_sensor.cam2_motion
    - binary_sensor.cam3_motion
    - ...
    - binary_sensor.pir1
    - binary_sensor.pir2
    - binary_sensor.pir3
    - ...

In your future automation, when group.security turns to on, it means one of those tilted.

HA MQTT config
From configuration.yaml:

mqtt:
  binary_sensor: !include_dir_merge_list mqtt/binary_sensor

from mqtt/binary_sensor/cameras.yaml

- name: "Cam1 motion"
  state_topic: homeassistant/blue_iris/binary_sensor/Cam1/state
  payload_on: "on"
  payload_off: "off"
  device_class: motion

Add one of those entries per camera. That way, you create a binary sensor that, in combination with BI config, will turn on when there is a detection.

HA automation

- id: "110020"
  alias: Alarm - Combined (3+) tiggers
  description: Combine 3 different camera and motion triggers within 90s before setting off Alarm
  trigger:
    - platform: state
      entity_id: group.security
      from: "off"
      to: "on"
  condition:
    and:
      - condition: template
        value_template: >
          {%- set counter = namespace(total=0) %}
          {%- for sensor in expand('group.security') | map(attribute='last_changed') %}
            {%- if now() - sensor < timedelta(seconds=90) %}
              {%- set counter.total = counter.total + 1 %}
            {%- endif %}
          {%- endfor %}
          {{ iif(counter.total > 2 and counter.total <5, true, false) }}
      - condition: state
        entity_id: device_tracker.idevice_housemaid
        state: "not_home"
      - condition: state
        entity_id: input_boolean.security_2h_snooze
        state: "off"
      - or:
          - condition: state
            entity_id: group.family_members
            state: not_home
          - condition: time
            after: "23:00"
            before: "08:00"
  action:
    - service: notify.emergency
      data_template:
        title: "ALARM!"
        message: >
          {{ "3 or more sensors triggered:" }}
            {% for sensor in expand('group.security') -%}
              {%- if sensor.state == "on" -%}
                {{- " * " + state_attr(sensor.entity_id, 'friendly_name').partition(' ')[0] + "\n" -}}
              {% endif %}
            {%- endfor %}
        data:
          priority: 1
          sound: bugle
    - service: notify.mobile_app_k
      data:
        message: >
          {{ "3 or more sensors triggered:" }}
            {% for sensor in expand('group.security') -%}
              {%- if sensor.state == "on" -%}
                {{- " * " + state_attr(sensor.entity_id, 'friendly_name').partition(' ')[0] + "\n" -}}
              {% endif %}
            {%- endfor %}
    - service: media_player.volume_set
      data:
        entity_id: media_player.gaming_room
        volume_level: "0.7"
    - service: media_player.play_media
      data:
        entity_id: media_player.gaming_room
        media_content_type: music
        media_content_id: "http://192.168.XXX.YYY:8123/local/dog.wav"
    - service: camera.snapshot
      entity_id: camera.blueiris_cam1
      data:
        filename: "/config/www/tmp/snapshot_cam1.jpg"
    - service: notify.home_alert
      data_template:
        title: "Camera R"
        message: '{{now().strftime("%H:%M %d-%m-%Y")}}'
        data:
          attachment: "/config/www/tmp/snapshot_cam1.jpg"
          priority: 0
          sound: intermission
    - service: notify.mobile_app_k
      data:
        message: "CAM1 Live stream"
        data:
          entity_id: camera.blueiris_cam1

TIPS
You can adjust the sensibility of your PIRs to accommodate for the outdoor temperature using an automation. Having the dog barking on the Sonos speaker is a strong deterrent. (Provided you take a credible dog sound, there are plenty on youtube. Avoid short loops, take at least 3 minutes.) Car parking radar detectors make an excellent, rain proof & invisible 3rd possibility if you want multi-wavelength detection. They come cheap and are easy to reverse engineer to piggy back an ESP8266 + MQTT.

Disclamer
Don’t eat glue, do not jump from bridges, own risk, etc.

(My other posts: Integrate any remote to HA, Run HA boot+data on SSD with a PI, False positive proof security system, Advanced solar panel monitoring)

2 Likes

Watching this.

I’ve got a fairly extensive “poor man’s” alarm system setup using HA, Blue Iris, PIR motion sensors, etc but any new ideas are always welcome.

The fun part is that in my country, I can’t directly set my system to call the police automatically.
The “pro” alarms are allowed to automatically phone the police though.

So I have wired my alarm’s remote with an ESP8266. If I have an alert triggered, I can press the panic button of the “official” alarm and this system will call the police by itself.

For an experimented user like you, I’d say the “trick” is specifically here:

{%- set counter = namespace(total=0) %}
{%- for sensor in expand('group.security') | map(attribute='last_changed') %}
    {%- if now() - sensor < timedelta(seconds=90) %}
        {%- set counter.total = counter.total + 1 %}
    {%- endif %}
{%- endfor %}
{{ iif(counter.total > 2 and counter.total <5, true, false) }}

The 3 triggers minimum in 90s means that someone is eventually reckoning the perimeter around the house before breaching in. Also, sometimes I had my camera rebooting all at the same hour at night or the BI windows machine renewing DHCP or a switch issue, etc.

The limit I set with the “<5” is to avoid those camera “signal loss”.
Minimum 3 and maximum 4, because if any of the above happens, meaning if all cameras go down temporarily, I don’t want the system to trigger an alarm. It’s likely a FP, hence the constraint.

Thanks for the idea and the code for the counter itself!

Just wanted to add that it would probably make sense to have each of the sensors (and not the group) as automation triggers - otherwise you could miss an alarm when someone would trigger a sensor (at which point the automation will fire, but there will be no alarm due to only one sensor triggered) and continue browsing around keeping the security group constantly “on”, eventually triggering 3 or more sensors (at which point there will be no alarm again because the group state will not change and the automation simply won’t be triggered).

you’re entirely right, I’ll update

1 Like