Can I save an image from a web URL as a files to HA?

I have an CCTV camera that supports motion detection but not snapshotting natively in HA.

I can set up an automation to email me if motion is dectected, but I cannot get it to automatically attach a snapshot of that motion.

The camera does give me a URL, and if you access it in a browser it returns a still image as a JPG file.

http://(IP Address)/webcapture.jpg?command=snap&channel=0&user=user&password=password

What code do I need to add to the automation to save the file form this URL to the folder " /share/snapshots/".

I know almost nothing about coding, so I would appreciate it greatly if someone could please type up some sample code, rather than directing me to the help page. I’ve read it but don’t understand most of it.

This is roughly what I have already, it’s just a modified version of what I use for other camera with a snapshot feature. The motion sensor is OK, the email is OK, I just don’t know how to save the image from that URL to my share folder:

alias: Send a picture when loading dock#1 camera#1 one senses motion
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.LD1C1_cell_motion_detection
    from: "off"
    to: "on"
condition: []

action:
 
get the image from this URL http://(IP Address)/webcapture.jpg?command=snap&channel=0&user=user&password=password and save it to the folder /share/snapshots/LD1C1.jpg (folder already set up with all permissions in place)

  - service: notify.email_notification
    data:
      message: There is Activity on Loading Dock#1
      title: There is Activity on Loading Dock#1
      target: email~address.com
      data:
        images:
          - /share/snapshots/LD1C1.jpg

mode: single

Please don’t just say that I need to read the help file, I’m not yet in a place where I understand it.

add in configuration.yaml

shell_command:
get_it: wget -P /share/snapshots/ http://(IP Address)/webcapture.jpg?com…

add an new automation to call the shell command with ever trigger you consider:
action:
- service: shell_command.get_it
That will download the immage. Verify the immage filename

See more:
Shell Command
wget

1 Like

use wget -O /share/snapshots/LD1C1.jpg http://…