How to take snapshot after motion is detected on camera

Hi all, I’m struggling to figure out the easiest way to implement this across the couple cameras I have so far. One supports ffmpeg and the other only mjpeg. I’ve tried the following as an automation with the ffmpeg enabled camera (a Hikvision cube) and I get an error when checking the yaml.

From automations.yaml

- id: garagetakepicture
  alias: Take picture in garage on motion
  initial_state: true
    - platform: state
      entity_id: camera.hikvision
      to: 'on’
    - service: camera.snapshot
        entity_id: camera.hikvision
        filename: 'garage_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg'

The error

Error loading /config/configuration.yaml: while parsing a block mapping in "/config/automations/automations.yaml", line 257, column 7 expected <block end>, but found '<scalar>' in "/config/automations/automations.yaml", line 264, column 20

My camera setup in cameras.yaml (called from configuration.yaml)

- platform: ffmpeg
  input: rtsp://
  name: Hikvision

I would prefer not to use the binary sensor for Hikvision as I won’t be able to use this on the other camera, which isn’t Hikvision.

Any ideas?

1 Like

Solved via the Reddit subthread, there is an erroneous single quote in the to: ‘on’ line

OK, so bump now because while everything works, it doesn’t trigger when there is motion detected. Is the automation above correct?

Your trigger doesn’t seem correct. It should be some kind of sensor.
Camera is already on, so won’t trigger anything

Thanks, it’s unclear to me what trigger I need. The camera docs (to me) are not clear about how I trigger a snapshot when motion is detected using that motion service.

In this case, you would need some other sensor/device to create the trigger.

The ffmpeg platform ONLY allows you to use any video feed as a camera in Home Assistant.

@rsachoc someone contributed these command line sensors for a foscam. you need to insert your ip, user and password.

Try and see if they work. if they do your trigger is

- platform: state
  entity_id: sensor.entrance_camera_motion
  to: 'Detected’

Thanks, think I’m getting there. Does the link in for the camera need to be the ffmpeg URL or the MJPEG url (or something else)? Reason I ask is that my camera (Hikvision DS-2CD2420F) dosen’t seem to support MJEPG (only RTSP) so I’m struggling to get it working (I tried testing it with the curl command in the command line on the docker image and using the RTSP link returns nothing).

Well there’s a foscam component in HA, but im not using that. Im using zoneminder which pulls the image with rtsp.
if you get nothing try changing the url, use http and the recommended port for your camera.