UnifiProtect and Node Red

Hi,
I have an install with HACS UnifiProtect. It works great and I am able to see the camera live feeds on the dashboard.
I am working on integrating with Node-Red now. I started small and am able to trigger on presence from HA and turn a light on and off.
I am now starting to work on what i really want to do, which is take a snapshot from a camera. I have done a lot of research and I get what needs to happen, I am just not sure how to get it done.

  1. Create a service which is camera.snapshot for each camera
  2. From Node-Red, be able to trigger a snapshot based on an event. I am not using the inject node in Node-Red to test, but I am not sure how to trigger an action from Node-Red.

I tried to use the developer tools, and have this script:

service: camera.snapshot
target:
  entity_id: camera.back_patio
data:
  filename: /tmp/snapshot_{{ entity_id }}.jpg

I created the tmp folder at the same level as configuration.yaml.

when I run the service in the developer section, I get no pictures in the folder.
I am new at all of this, so i am trying to get up the speed quickly.
Has anyone done anything like this before? Any recommendations or articles you can point me to for help?
Thanks,
H-

So this is what I have so far in Node Red. This runs also, no errors, but I do not see a picture in the tmp folder.
image

The configuration of the svc node is the following:


The filename is the following:

{
   "filename" : "/tmp/snapshot_{{ entity_id.name }}.jpg"
}

I even tried to remove all templates from the filename and set it to that:

{
   "filename" : "snapshot.jpg"
}

and also read that the folder is mapped to /share/, but again, nothing there

Other things I tried are allowlist the directory…this is a bit foreign for me, but still did not work (assuming I did it right).

I added this in my configuration.yaml

homeassistant:
  allowlist_external_dirs:
    - /share
    - /tmp

Still working on debugging…none of the above work…

Your tmp folder should be one step up. In the same section as the config/homeassistant, share, backup etc folder.

If you want the tmp folder in the config folder (same as the config.yaml) you need:

/config/tmp/snapshot.jpg

Thanks for the reply. I just tried that. Created the folder under config, and changed my node red filename path as you stated above. No luck. No file shows up in the directory.
From what I read so far, I will just use the /share folder which already exists at the same level as config.
I feel like I am missing something small to get to that. There are a lot of threads about this, but I cannot get my finger on what I am missing to get this to work.
thanks,
H-

OK, solved. Was dumb really and I should have known.
I had to add the following to configuration.yaml

homeassistant:
  allowlist_external_dirs:
    - "/tmp"
    - "/share"
  media_dirs:
    media: "/media"
#    recordings: "/mnt/recordings"
  legacy_templates: false

Now I mentioned I tried it above, but the one thing missing was to restart the server to reload configuration after the changes. That did it. Now I can take a snapshot from a camera in NodeRed and have it saved in /share.
I am still going to try and find a solution on how to direct it to a mounted drive.

1 Like