New name for every picture

Hello ,

I am trying to give motion triggered pictures different names. I don't want them to be over written.

I have this flow which saves the pictures but couldn't figure out how to give different names.

[{"id":"4416b46d00b74e1d","type":"server-state-changed","z":"7aa5b5b5.c7c5f8","name":"Motion Sensor","server":"30307a46.24469a","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.192_168_50_60_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"2","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":60,"wires":[["ddcf9a5fdc523cf8"]]},{"id":"ddcf9a5fdc523cf8","type":"switch","z":"7aa5b5b5.c7c5f8","name":"Value > 60?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"60","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":60,"wires":[["48db04f7d334901b"]]},{"id":"48db04f7d334901b","type":"function","z":"7aa5b5b5.c7c5f8","name":"Take Picture","func":"msg.payload = {\n    \"data\": \"http://192.168.50.60:8080/shot.jpg\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":60,"wires":[["d9daf7507bf38e9f"]]},{"id":"d9daf7507bf38e9f","type":"http request","z":"7aa5b5b5.c7c5f8","name":"Get Picture","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.50.60:8080/photo.jpg","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"x":650,"y":60,"wires":[["9ca58ffd6eb64591"]]},{"id":"9ca58ffd6eb64591","type":"file","z":"7aa5b5b5.c7c5f8","name":"Save Picture","filename":"/media/Pictures/picture.jpg","filenameType":"str","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":830,"y":60,"wires":[[]]},{"id":"30307a46.24469a","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

You could add a timestamp to the end of the name or create a numeric flow variable and add one to it each time you take a picture and add that to the name.

p.s. your flow was not importable. The three back-tic's have to be on a separate line. I edited it for you.

You can use JSONata in the file write node path input. So you can append a datetime.
e.g.

[{"id":"9ca58ffd6eb64591","type":"file","z":"da8a6ef0b3c9a5c8","name":"Save Picture","filename":"\"/media/Pictures/picture\" & $moment().format(\"YYYYMMDD_HHmmss\") & \".jpg\"","filenameType":"jsonata","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":960,"y":4660,"wires":[[]]},{"id":"d9daf7507bf38e9f","type":"http request","z":"da8a6ef0b3c9a5c8","name":"Get Picture","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.50.60:8080/photo.jpg","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"credentials":{"user":"","password":""},"x":780,"y":4660,"wires":[["9ca58ffd6eb64591"]]},{"id":"48db04f7d334901b","type":"function","z":"da8a6ef0b3c9a5c8","name":"Take Picture","func":"msg.payload = {\n    \"data\": \"http://192.168.50.60:8080/shot.jpg\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":4660,"wires":[["d9daf7507bf38e9f"]]},{"id":"ddcf9a5fdc523cf8","type":"switch","z":"da8a6ef0b3c9a5c8","name":"Value > 60?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"60","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":4660,"wires":[["48db04f7d334901b"]]},{"id":"4416b46d00b74e1d","type":"server-state-changed","z":"da8a6ef0b3c9a5c8","name":"Motion Sensor","server":"30307a46.24469a","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.192_168_50_60_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"2","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":4660,"wires":[["ddcf9a5fdc523cf8"]]}]
2 Likes

Thank you very much. This worked very nice. wouldn't be able to figure out by my self.

I have an other issue.
Can I write these pictures to a network drive ? Because i managed to mount a network drive and i can access to that drive from the media in the side bar. But when i write filesin /media/pictures it end up in local /media/pictures/.

You will have to give it the full network path and you will have to have write access to that location

You mean like this ?
image
or something else ?

That’s a url. When you say network device, do you mean a device on your local network or some device out in the cloud?

To use the file-out node, you need to give the path to the location. How the path is defined depends on the device and your OS.

The setup is this,

Home assistant HAOS_OVA-9.4 is running on an Ubuntu in KVM.
All the drives are on Ubuntu shared with samba.
Ubuntu ip is 192.168.50.51, Home assistant ip is 192.168.50.52.

I have also mounted this network drive using this

shell_command: mount_nas_folder: mkdir -p /media/Pictures;mount -t cifs -o vers=3.0,noserverino,username=agas,password=***,file_mode=0777,dir_mode=0777,domain=WORKGROUP //192.168.50.51/300/Pictures /media/Pictures

and adding the automation to run this on every restart. I can see the mounted folder from the media in the sidepanel. But i cannot write to it when use /media/Pictures/picture.jpg. These pictures end up in local /media/Pictures/. I am doing something terribly wrong but cant figure out what.

And thank you a lot for helping.

Since you're using Home Assistant, I suggest you ask on the node00red section of the Home Assistant forum. Not many people here (including me) use Home Assistant so you might get an answer there.

Thank you