Event not firing a trigger – event_length never goes above 0 (SecuritySpy for Home Assistant)

I can’t get an event to fire a trigger with an event_object Attribute change, but all the pieces seem to be working as expected. This automation is trying to use the SecuritySpy for Home Assistant integration, but it’s not clear if that is where the problem lies.

My setup

Goal
SecuritySpy will detect if a human is present, and fire an event – I’d like to have Home Assistant do something when this happens. For example, someone walks up to the front door and it turns the porch light to 100%, sends me a notification, etc. For now (while testing) I just have it set up to send me a notification.

Automation YAML

alias: 'cam1 / Front Door: person detected – TEST'
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.cam1_front_door_motion
    attribute: event_object
    to: human
condition: []
action:
  - service: camera.snapshot
    data:
      entity_id: camera.cam1_front_door
      filename: /config/www/cam_captures/frontdoor.jpg
  - service: notify.mobile_app_benish
    data:
      message: Person at Front Door
      data:
        image: /local/cam_captures/frontdoor.jpg
        url: securityspy:///live?cameraNum=2
        actions:
          - action: URI
            title: Large Image (latest capture)
            uri: >-
              https://myNabuCasaUniqueIDobfuscated.ui.nabu.casa/local/cam_captures/frontdoor.jpg
          - action: URI
            title: Live Video in Security Spy
            uri: securityspy:///live?cameraNum=2
mode: single

The Automation is enabled. The Trigger is a direct copy of the example on the SecuritySpy for Home Assistant README (but with my entity_id).

All the pieces seem to be working individually:

  • If I click Run Actions from the Automation detail page, the Actions work as expected (I get a notification on my phone with the specified image and notification actions).
  • There are no Conditions, so I guess we can say those work. :slight_smile:
  • SecuritySpy will send me a native notification when a human is detected with this camera, so the human detection is working as expected in SecuritySpy.
  • If I get rid of attribute: event_object and to: human in the above Automation – i.e. just use regular motion detection without checking for a human – it fires the trigger as expected. In fact it fires a ton of them in quick succession. So the binary_sensor.cam1_front_door_motion created by SecuritySpy for Home Assistant does work: regular motion is detected and the corresponding event will fire.
  • If I look at the binary_sensor.cam1_front_door_motion Entity in Developer Tools > States I can see the event_object Attribute change to human as expected when I walk in front of the camera as seen in this video screen capture. Of note, event_object rapidly changes between human and None and the event_length never goes above 0 when it’s at human. I suspect this might be the root of the issue? But I don’t have a for: setup for the Trigger, so I’d expect it to trigger regardless of the event_length? Out of desperation I did try setting for: to 0 seconds, but that had no effect so I removed it.
  • If I manually set the state to on with event_object: human via Developer Tools > States > Set State, it will trigger the Automation. Also of note, it takes about 4 seconds for the notification to show up when I manually set the State like this. In contrast, notifications directly from SecuritySpy and the motion-only test Automation in Home Assistant (without event_object: human) both trigger / notify much faster (less than a second).

I enabled Debug Logging for SecuritySpy for Home Assistant, but I don’t see anything useful there.

I’m new to Home Assistant and very new to YAML, so apologies for any mistakes regarding terminology. Any help is greatly appreciated.

In case anyone else runs across this: I found an Issue on the integration’s Github repo that seemed related. The solution there worked for me as well:

Added a Template Sensor to configuration.yaml:

sensor:
  - platform: template
    sensors:
      frontdoor_person_detected:
        friendly_name: Person detected at front door
        value_template: >
          {{state_attr('binary_sensor.cam1_front_door_motion', 'event_object') }}

Where frontdoor_person_detected is whatever name you want for the sensor and binary_sensor.cam1_front_door_motion is the entity for the camera from the SecuritySpy for Home Assistant integration that includes event_object.

Then in my Automation’s Trigger I set the Entity to that Template Sensor and set Human as the value for To. I first tried human (lowercase) and it didn’t work, so watch for that. The YAML for the Trigger is just:

platform: state
entity_id: sensor.frontdoor_person_detected
to: Human

With that it was working, but bombarding me with rapid notifications. I found this clever condition that will limit it to one notification per whatever time interval you want:

condition: template
value_template: >-
  {{ (as_timestamp(now()) -
  as_timestamp(states.automation.cam1_front_door_person_detected.attributes.last_triggered
  | default(0)) | int > 30)}}

Change cam1_front_door_person_detected to the entity name of your automation, and change 30 to however many seconds you want between notifications.