Cant save snapshot from camera

using Dev Tools/Services tab, i have:
service: camera.snapshot
entity: camera.armcrest_camera
data: entity_id: camera.amcrest_camera
filename: ‘/tmp/armcrest_camera_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg’

i was expecting to see the file here: /home/tung/.homeassistant/tmp
BUT
error log shows: Can’t write /tmp/armcrest_camera_20200117-142600.jpg, no access to path!

i put this in config yaml as well but it did not help:
whitelist_external_dirs:
- /tmp/

this is on ubuntu with HA installed via Python venv. all the tutorials i saw was for HassIO

Is this folder permission issue on server

I agree with @tmjpugh. This is probably a file permissions issue at the OS level.

How are you running HA? As a unique user? If so, you have to make sure that user can write files to that location.

I can tell you the camera.snapshot service works with the amcrest integration. I use it myself. And, FYI, I just submitted a PR to significantly improve the robustness of the amcrest integration. One issue I’ve had for a while is sometimes the snapshot would fail with communication errors. That should be eliminated by the PR.

using FTP or Putty, i can log in as user “tung”
and i can upload anything to this directory using that user: /home/tung/.homeassistant/tmp

in Putty, i use this command to restart HA as needed: sudo systemctl restart [email protected]

not sure if that answers your question.

@tung256, I would try to save it to your www folder in HA. You can create whatever folder you like in www and have access to it.

same error unfortunately:
Can’t write ‘/www/armcrest_camera_20200117-221128.jpg’, no access to path!

From that it looks like you’re running HA as user tung. So if you can write to that directory while logged in as tung, then HA should be able to write to it, too. And since you’ve added the folder to the whitelist…

Wait. Why is the filename /tmp/... in the service call, but you said the folder is /home/tung/.homeassistant/tmp? You should use /home/tung/.homeassistant/tmp/... in the service call.

i use the full path as you advised but HA refuses to work:
filename: ‘/home/tung/.homeassistant/tmp/armcrest_camera_{{ now().strftime(“%Y%m%d-%H%M%S”) }}.jpg’
filename: ‘/home/tung/.homeassistant/www/armcrest_camera_{{ now().strftime(“%Y%m%d-%H%M%S”) }}.jpg’

you can see i can upload to “tmp” folder. but no jpg files exist when i try to use the snapshot feature

I just tried the camera.snapshot service using the following for Service Data on the SERVICES tab of the Developer Tools page:

entity_id: camera.hf_ipc
filename: '/home/homeassistant/.homeassistant/www/armcrest_camera_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg'

It worked just fine. The only thing I changed from your last attempt was to use proper quotes and I changed tung to homeassistant because in my case HA is run as that user.

thank you for your sample! it works.
my syntax with the quotes were wrong. not sure where i copied it from.

1 Like

did you ever use Telegram with amcrest snapshot?

this code works with telegram bot send photo for my Hikvision cam:
url: ‘http://admin:[email protected]/ISAPI/Streaming/channels/102/picture

and if i manually paste this into my browser for Amcrest cam, it works:
url: ‘http://admin:[email protected]/cgi-bin/snapshot.cgi

BUT using my Amcrest code with telegram results in error: Can’t send file with kwargs

another suggested using telegram bot send message with this format:
message: “door Snapshot
but i got error: Error sending message: Forbidden: bot can’t send messages to bots.

I have not used Telegram and I really don’t know anything about it.

You should not try to access the camera directly using its HTTP API from another source when it is being controlled by the amcrest integration in HA. You’re asking for trouble, especially if you do this with the snapshot command. That command takes longer than most, and does not allow more than one simultaneously. If the HA amcrest integration happens to try and get a snapshot while you’re doing the same from another system with the same camera, you’re likely to see errors.

I don’t know what that means. Can you clarify / provide more details?

to send snapshot with Amcrest cam via Telegram, i got it working using very cumbersome code as seen here:

- id: '1579721342697'
  alias: alert doorbell sent telegram amcrest photo
  description: ''
  trigger:
  - entity_id: sensor.doorbell
    from: unknown
    platform: state
    to: Ding
  condition: []
  action:
  - data:
      entity_id: camera.amcrest_camera
      filename: /home/tung/.homeassistant/www/armcrest_{{ now().strftime("%Y%m%d-%H%M")
        }}.jpg
    service: camera.snapshot
  - delay: 00:00:01
  - data:
      caption: person at the front door
      file: /home/tung/.homeassistant/www/armcrest_{{ now().strftime("%Y%m%d-%H%M")
        }}.jpg
      target: 54641xxxx
    service: telegram_bot.send_photo

with Hikvision, all i had to do was send the URL. no need to take snapshot and send file.
hope this helps someone out there.

Are you saying that you tried to use that URL somehow directly with telegram, but it resulted in errors when it tried to use that URL? If so, maybe telegram doesn’t support Digest Authentication (like your browser, and the HA amcrest integration, do.) AFAIK, all Amcrest cameras now require Digest Authentication, and maybe your Hikvision camera can use Basic Authentication.

Regarding your automation, that will work, unless…

  1. It takes longer than one second for the snapshot to complete. I’ve had to use a 3 second delay to make sure it’s always done before trying to use the file.
  2. It doesn’t just happen to take the picture right before the minute changes, otherwise the filenames used to take the picture, and to retrieve the picture, won’t match. (E.g., 20200122-14:48 & 20200122-14:49).

you are right. i finally got it working via URL. someone posted his sample of Digest Authentication but his syntax was wrong and i couldnt figure it out myself till now. this working code is much cleaner and efficient:

- id: '1579721342697'
  alias: alert doorbell sent telegram amcrest photo
  description: ''
  trigger:
  - entity_id: sensor.doorbell
    from: unknown
    platform: state
    to: Ding
  condition: []
  action:
  - data:
      authentication: digest
      password: password1
      target: 54641xxxx
      url: http://192.168.1.252/cgi-bin/snapshot.cgi
      username: admin
    service: telegram_bot.send_photo
2 Likes