Use Nest camera motion detection

Hi There,

In my carport i have a Nest camera and some Philips Hue lights.
Is there a way to use the camera as a motion sensor?
I can use the nest event as a trigger to power the lights, that is not the issue.

   "event_type": "nest_event",
    "data": {
        "device_id": "xxxxx",
        "type": "camera_motion",
        "timestamp": "xxxx",
        "nest_event_id": "xxxx"
}

The thing i need help with: How can i use “event “camera_motion” not seen for x minutes” in an automation?

Thank you!

This is not a simple task, but not impossible either.

Event triggers are instantaneous and do not have states you can trigger on by them being in a particular ‘state’ for any length of time.

Assuming you want to turn off the lights there are a number of ways to do this:

  1. Trigger on the lights being in the 'on' state for x minutes, and turn them off in the action. The problem with this is that the for ‘timer’ will not reset when more motion is detected. It is simple though and may fit your need.

or

  1. Use an actual timer and a couple of automations. Start/restart the timer using an automation triggered every time the movement event occurs. Another automation that is triggered by the timer.finished event switches off the lights.

or

  1. Create a triggered binary sensor. The trigger is your camera movement event. The state is is just 'on' (true), use the auto_off, option to turn off the binary sensor after a second or two. Then an automation uses a state trigger watching for this binary sensor to be 'off' for x minutes, then turns off the light. The for time resets every time there is movement and the binary sensor turns on.

To me, option 3 is the best as it offers the required functionality for the smallest amount of configuration.

Example triggered template binary sensor:

template:
  - trigger:
      - platform: event
        event_type: nest_event
        event_data:
          device_id: "xxxxx"
          type: camera_motion
    binary_sensor:
      - name: "Carport Movement"
        state: "{{ true }}"
        auto_off: 2
        device_class: motion

Automation example:

trigger:
  - platform: state
    entity_id: binary_sensor.carport_motion
    to: 'off'
    for:
      minutes: x
action:
  - service: light.turn_off ...etc
2 Likes

This works like a charm Tom! Thank you!
Motion sensor

2 Likes

Is the device id the entity id of the nest camera?

No the device id will be different from the entity id.

I created a templates.yaml file and couldnt get this to work. Here is my script:

- trigger:
    - platform: event
      event_type: nest_event
      event_data:
        device_id: ********************************
        type: camera_motion
  binary_sensor:
    - name: "Driveway Sensor"
      state: "{{ true }}"
      auto_off: 2
      device_class: motion

Am I missing anything?

Do you have this in configuration.yaml?

template: !include: templates.yaml

And did you restart home assistant after creating the triggered template binary sensor?

I did. I also got an error that there is something wrong on line 1. I no longer see the message and checking the config works so not sure what’s causing it to not work.