Help with camera.snapshot, not saving image - feeling defeated

Hi - I am seeking help in one of the most basic service calls camera.snapshot. I am new HA user, implemented about a month ago - been learning the ins and outs. My HA OS is on a dedicated NUC.

I have taken the time to search in the forums but I am very confused as my root folder structure seems different than most responses.

I feel defeated on my first automation :frowning:. I keep telling myself, if I cannot get this right, I should go back to homekit and stay out of the tinkering world. But I thought I’d ask here as my last resort.

Automation objective: when the doorbell rings, take snapshot (and save it) and send notification to companion app.

Implementation YAML code: I built this automation using the UI, but got the code from YAML editor:

alias: Send notification when doorbell rings
description: ""
triggers:
  - type: occupied
    device_id: b7d9194dae0d54d747217d809c6e1426
    entity_id: 1eaf2a5f107c88e61b9559a1d8fdc473
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: camera.snapshot
    metadata: {}
    data:
      filename: /tmp/front_door_doorbell.jpg
    target:
      entity_id: camera.g4_doorbell_pro_entrance_cam
  - action: notify.mobile_app_ks_iphone_14
    metadata: {}
    data:
      message: Someone at the door.
      title: Doorbell Notification
    enabled: true
mode: single

Extra info: I followed the required steps to (I think) to setup the save:

  • created folder called tmp, added config file code to allow dirs, restarted HA
  • Did I do anything wrong? I spent alot of time tracing and trying things out, but no luck
            
# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

#KI Customization
homeassistant:
  allowlist_external_dirs:
    - "/tmp"

Here is a screenshot of my folder structure from Editor:

Your input/advice is greatly appreciated.

See an example, e.g., here :Notification with snaphot of camera and live feed option

3 notions to keep in mind:

  • The root of the files you see in the editor is “/config”, not “/”
  • Your snapshot must be accessible through an outside url
  • Static files are stored in the “/config/www” folder, and accessed through a “https(s)://<your-external domain>/local/…” url
1 Like

Hello! I faced a similar issue and resolved it by saving the snapshot into the media

/media/facesnap/Camera07.jpg

Thank you for the thoughtful response.

Based on the points you raised, I changed the filename path in the action by replacing /tmp with /config/www/<filename.jpg>.

It worked and snapshot is available in the www folder.

Thank you so much.

In the spirit of learning, few questions come to mind:

  1. is /config/www an exposed file i.e. accessible from the outside? is there a way to limit that?
  2. for the access url, does this mean that /local is the same as /config/www?

Thank you again
K

  1. Yes; allowlist_external_dirs to restrict
  2. Yes
1 Like

Thank you.

Based on the input from Chris B above, I was able to make it work.

Now that I have that baseline established (in that it works for /config/www), I am going to tinker with the approach you are proposing as well. I think it would be good to know more than one method to achieve the same outcome.

Can you provide what your config file looks like for whitelist_external_dirs to use /media? I am curious b/c my gut tells me that is where I got stuck.

Thanks

Great to hear it works! Marking @koying answers as the solution would be helpful so others facing the same issue can quickly find the fix.

1 Like

Appreciate it. I also marked this as a solution for others.

I consider this resolved.

For #1 (and again in the learning zone), does the code below work to restrict?

homeassistant:
  allowlist_external_dirs:
    - "/config/www"