cancel
Showing results for 
Search instead for 
Did you mean: 

Use person detection to trigger light, then turn off

kevwags
Community Member

I’m trying to have my backyard nest cam use person detection to turn on a lamp and then if there is no motion detected for 10 minutes, turn the lamp off. I also have a condition to do this only at night. I cannot get the section that turns off the light to work without errors:

 

metadata:
name: Backyard Motion Detected
description: When backyard camera detects person, activate living room lamp

automations:
- starters:
- type: device.event.PersonDetection
device: Backyard camera - Backyard

condition:
type: time.between
after: 22:00
before: sunrise

actions:
- type: device.command.OnOff
devices: Living Room Lamp - Living Room
on: true

- starters:
- type: device.event.MotionDetection
device: Backyard camera - Backyard
state: motionDetectionEventInProgress
is: false
for: 10 min

condition:
type: time.between
after: 22:00
before: sunrise

actions:
- type: device.command.OnOff
devices: Living Room Lamp - Living Room
on: false

7 REPLIES 7

Cosacalo
Community Member

I use this script to do what you want to do. You can add more conditions if you'd like.

metadata:
  name: Doorbell Camera Person Detected Light On
  description: Turn on the lights when camera sees someone.

automations:
  - starters:
      - type: device.event.PersonDetection
        device: Doorbell - Front door
    actions:
      - type: device.command.OnOff
        devices: Porch Light - Front door
        on: true
      - type: time.delay
        for: 20min
      - type: device.command.OnOff
        devices: Porch Light - Front door
        on: false
    condition:
      type: and

      conditions:
        - type: time.between
          after: sunset+1hour
          before: sunrise
        - type: device.state.OnOff
          state: on
          is: false
          device: Porch Light - Front door

EmptyNester
Gold Product Expert
Gold Product Expert

This is excellent,  thanks for posting!  It works great for me.

One additional question.  Since the doorbells have facial recognition is there a way to make an automation that play a short recording of my voice over the door bell the says "HELLO PAUL" when the doorbell see PAUL?

kevwags
Community Member

This worked! There is very little latency also which is fantastic. Final code below:

 

metadata:
  name: Backyard Motion Detected
  description: When backyard camera detects person, activate living room lamp for 10 minutes.

automations:
  - starters:
      - type: device.event.PersonDetection
        device: Backyard Camera - Backyard

    condition:
      type: time.between
      after: 22:00
      before: sunrise

    actions:
      - type: device.command.OnOff
        devices: Living Room Lamp - Living Room
        on: true
      - type: time.delay
        for: 10min
      - type: device.command.OnOff
        devices: Living Room Lamp - Living Room
        on: false

blackmagic
Community Member

@kevwags which lights are supported with the script editor? I have kasa switches that are added to my google home, but I guess those are not supported.

well.. it appears the HS220 switch is indeed supported as an action for on/off, but for some reason the script editor is not recognizing it as a device.

Not sure. I am using a Govee Wi-Fi bulb.

I had to unlink kasa, close the app, and then re-add it!