Camera.snapshot: struggling to save

I’m fighting this for multiple days :blush:
The goal: take a snapshot from a camera and display on mobile with a popup.

If I store a picture in www, I can view it in my browser with ha-ip:8123/local/pic.jpg

/local == /config/www

Taking a snapshot is another thing…
I tried with:

data:
  filename: /config/www/cam.jpg

and get:

Cannot write /config/www/cam.jpg, no access to path; allowlist_external_dirs may need to be adjusted in configuration.yaml

Tried with al kind of different ways in config

  allowlist_external_dirs:
    - '/config/www'
    - '/media'

returns

I also tried with subfolders in www: nada
Saving in media seems to work but the file doesn’t show up.

What am I missing?!?

Check here
Try adding permissions for the folder with “chmod”.

1 Like

Hi Ildar (is that your first name?) thanks for jumping in!

Could it be because I’m running HA Core… :thinking:

I was thinking about dir permissions but also whether my config and use of this was correct.
So far, I did’t want to mess with the default dir structure and their permissions yet and don’t get the logic yet.
I have read quite some topics & docs but cannot get it right.

  • now /local = /config/www but I cannot open the same test file with ha-ip:8123/config/www/pic.jpg
  • I’m already using the /media dir for TTS and referencing those does work
  • if I take a snapshot with the /media path, the action is executed but no file to be found + I cannot open the existing ones (cannot figure out how to address those)
  • if I create a dir at the same level as www (so similar situation as the media dir) how would I use that
    → does this mean that, without jumping through hoops, I can only use www - with the correct config?

You don’t have to explain/answer everything, I’m just sharing my findings and hope to get it working and understand the process on the way.

It is “ILDAR”, not “LIDAR” (as some people here keep calling me here) which is a part of a vacuum cleaner which I hope I am not.

Try “ha-ip:8123/local/pic.jpg” (works on my site).

No idea, using HA Docker ))).

“Executed” = means “button in Services became green & no messages in Log”, right? )))
If yes - here is an issue

Have you tried searching created files in a directory tree?

1 Like

So if I understand you have nothing in the allow list? That entry needs to be under homeassistant:

homeassistant:
  media_dirs:
    local: '/media'
  allowlist_external_dirs:
    - '/config/file_sensors'
    - '/config/www/community'
    - '/config'
    - '/media'

1 Like

Check if the file exists inside the docker container.

docker exec -it homeassistant /bin/bash

In /tmp or not sure where, try to find the file there.

It is needed only if you wish to see a content in a Media Browser.

One “/config” is enough.

OP uses core.

2 Likes

Did you put the code inside homeassistant? Like:

homeassistant:
  name: xyz
  .
  whatever:
  .
  allowlist_external_dirs:
    - /config/www

Edit: Sorry, i didnt read one of the answers

And btw is not a good idea to include the whole config folder.

1 Like

Note that write and read do not take place at the same folder:
write: filename: **/config/www/tmp/**snapshot_doorcam.jpg
read:url: **/local/tmp/**snapshot_doorcam.jpg

For example, take snapshot and send to iphone:
Write action:

  - entity_id: camera.doorcam
    data:
      filename: /config/www/tmp/snapshot_doorcam.jpg
    action: camera.snapshot

Attach to notification:

  - device_id: 12345abcdef670ff959107c4b1acff6f
    domain: mobile_app
    type: notify
    title: Motion detected!
    message: Frontdoor camera detected motion
    data:
      attachment:
        content-type: jpeg
        url: /local/tmp/snapshot_doorcam.jpg
1 Like

:wink: that’s what I wrote/assumed but since I have never came across that name - just here, yours - I wasn’t sure if it would be a real name or some action hero character of which I know nothing.

From my FIPO (so that does work fine)

Uhm, now I’m looking like those cows who saw the first train pass by. :blush:
?in services?
There is nothing in the log
What I meant was that I don’t get an error message but have no clue what/if something is really happening. I just can’t find any image file.

Yes, I have Samba configured but also through SSH checked the contents.

Yes I do. Should have posted the whole section, sorry.
I commented those entries that don’t pass the YAML check.

homeassistant:
  auth_mfa_modules:
    - type: totp

  allowlist_external_dirs:
#    - /config/www/images
#    - /local
    - '/media'

I also did a test with HAOS, with the same settings and there the file is created but displaying it returns an empty popup. :grin:

Welcome to the party! :crazy_face:

I’m aware of that odd behavior, that’s why I wrote

Let’s assume I use the /tmp dir (so we all are on the same page).
Does it have to be inside /www or can I create it at the same level?
→ if at the same level: what would be the path to write into it and read from it?
→ what do I put in my allowlist_external_dirs?

Erm, it is me in a real life, now you know it), Actually, a typical russian name - look, tons of ildars walking on Red Square with bears & playing balalaikas.

Add “/config/www/images” then.

with /config/www/images

/images has FULL access to EVERYONE… :thinking:

one more probably silly idea - add just “/config”

1 Like

As far as I know it must be /config/www (==local); this folder is is publicly available by default (but a precise file-/folder-name must be used; if not you will get 403:forbidden / ERR_INVALID_RESPONSE).

But you are free to use any other foldername within www (this www folder is also used for lovelace to store its java scripts and/or theme data and that is why it must be generally available)

I write to
/config/www/tmp/snapshot_doorcam.jpg
and read from
/local/tmp/snapshot_doorcam.jpg

Nothing…at least, I didn’t set any ( i don’t even have it in my config)

1 Like

Back at it!
Of course I want this to work but I’m so curious to why it doesn’t work.

This passes the YAML check :+1:

That’s clear, :bowing_man:
This works on HAOS (test setup) but not on Core (main system).

I have been holding off to switch to OS and if possible to get the things done that I want, it will stay that way.
(It must have something to do with permissions - I think…) strike that, on second thought but for the sake of the test I set full permissions to /tmp (which sits in /www)

Writing: (doesn’t seem to work)

data:
  filename: /config/www/tmp/cam.jpg

Reading: (works as expected)

  content:
    type: picture
    image: /local/tmp/pic3.jpg # a file that I copied in there manually

Could this be due to using Core (venv) and how this ‘interacts’ with the system?

How do you set permissions?

chmod 777 tmp

Try the full address

http://ha-ip:8123/local/pic.jpg

Should have checked for the file first. It executes with a check mark from devtools but no image is created.

Works for reading/displaying, not for writing/snapshot action… :upside_down_face: