MotionEye send to Telegram, done. How to transfer file to a NAS?

Hi all

I’m trying to send snapshots and records on MotionEye motion detection to Telegram and then send it via FTP (?) to my NAS drive.

I’m on Hassio on Docker in Ubuntu.

In the MotionEye Docker container I’ve created a python script that execute on every motion (“Run a command”)

The script just set to ON an MQTT binary sensor in this way

mosquitto_pub -h IP -u username -P password -t topic/Vialetto/motion -m "ON"

Then, with the “Run an End command” I set it to OFF

BTW, I’ve installed manually the mosquitto client within the motioneye container, via Portainer console.

In Node Red, when the binary sensor changes to on (at this moment I’m using a inject node to test it), I format date/time to add to the file name, take a snapshot and a record via HA commands camera.snapshot and camera.record on the right camera and send it to Telegram.

This is the Node-Red Flow

What I would like to do now is to transfer the files (jpg and mp4) to my NAS.

I’ve tried via FTP, using most of the FTP nodes in Manage Palette, but I haven’t succeded.

Any suggestion on how to transfer files from local to a NAS?

Thanks

PS:
I’ve also tried to upload the snapshot and video directly from the MotionEye interface via FTP and that is working, but then is there any way to get Telegram notification of the files uploaded?

I found this way to do it, but the issue is that the picture have to be saved always the same name overwriting the previously one, so there is no history.

I have done the same with a bit different approach

  1. Motion is detected on motionEye (I have 4 cameras)
  2. The recording is stored on the SD card (works with mapped drive as well)
  3. I send a webook to NodeRed including the filename (%f will include the full path)
  4. NR is receiving the webhook and extracting the filename
  5. I read the file and send it as Video-Message to Telegram
2 Likes

Hi @xx_Nexus_xx

Nice approach.

Can you share the webhook and the nodered flow?

Thanks

I’m currently travelling but will share in a few days when I’m back home

1 Like

can we get the webhook & nodered flow please

The webook to create a jpg and an mp4 file is what I’ve write in the first post

In the Motion Notification panel I call a .py script when ON and when off

the content of the .py script is

mosquitto_pub -h 192.xxx.xxx.xxx -u username -P "password" -t ipcam/Vialetto/motion -m "ON"

changing the “ON” to “OFF” for the off one

This is the Node-Red flow to send a picture and a short video to Telegram

[{"id":"b6152f71.37391","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"388e50c3.991bb","type":"mqtt in","z":"b6152f71.37391","name":"Filename Vialetto","topic":"ipcam/Vialetto/filename","qos":"0","datatype":"utf8","broker":"519ed97f.26f3a8","x":80,"y":220,"wires":[["d9d8bcae.ad2ff","d05ba662.4a1978"]]},{"id":"d9d8bcae.ad2ff","type":"string","z":"b6152f71.37391","name":"photo","methods":[{"name":"endsWith","params":[{"type":"str","value":"jpg"}]}],"prop":"payload","propout":"motioneye_photo_vialetto","object":"msg","objectout":"msg","x":250,"y":200,"wires":[["35899a78.df7ee6"]]},{"id":"d05ba662.4a1978","type":"string","z":"b6152f71.37391","name":"video","methods":[{"name":"endsWith","params":[{"type":"str","value":"mp4"}]}],"prop":"payload","propout":"motioneye_video_vialetto","object":"msg","objectout":"msg","x":250,"y":240,"wires":[["9d083cf2.17dbd"]]},{"id":"35899a78.df7ee6","type":"switch","z":"b6152f71.37391","name":"true","property":"motioneye_photo_vialetto","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":200,"wires":[["f4b2f8b8.7161a8"]]},{"id":"9d083cf2.17dbd","type":"switch","z":"b6152f71.37391","name":"true","property":"motioneye_video_vialetto","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":240,"wires":[["aafdfd86.e31c5"]]},{"id":"f4b2f8b8.7161a8","type":"change","z":"b6152f71.37391","name":"photo_vialetto","rules":[{"t":"set","p":"photo_vialetto","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"camera_vialetto","pt":"msg","to":"Vialetto","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":200,"wires":[["5b319e0b.a236d"]]},{"id":"aafdfd86.e31c5","type":"change","z":"b6152f71.37391","name":"video_vialetto","rules":[{"t":"set","p":"video_vialetto","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"camera_vialetto","pt":"msg","to":"Vialetto","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":240,"wires":[["b2744e87.be37a"]]},{"id":"5b319e0b.a236d","type":"function","z":"b6152f71.37391","name":"Send jpg to Telegram","func":"msg.payload = {chatId :xxxxxx, type : 'photo', content : msg.photo_vialetto, caption: \"Motion snapshot \"+msg.camera_vialetto+\"! \"}\nreturn msg;\n\n","outputs":1,"noerr":0,"x":720,"y":200,"wires":[["99f74ce1.cbda7"]]},{"id":"b2744e87.be37a","type":"delay","z":"b6152f71.37391","name":"5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":670,"y":240,"wires":[["95bb637c.db2e9"]]},{"id":"99f74ce1.cbda7","type":"telegram sender","z":"b6152f71.37391","name":"Telegram","bot":"","x":920,"y":200,"wires":[[]]},{"id":"95bb637c.db2e9","type":"function","z":"b6152f71.37391","name":"Send mp4 to Telegram","func":"msg.payload = {chatId :xxxxxx, type : 'video', content : msg.video_vialetto, caption: \"Motion video \"+msg.camera_vialetto+\"! \"}\nreturn msg;\n\n","outputs":1,"noerr":0,"x":840,"y":240,"wires":[["99f74ce1.cbda7"]]},{"id":"519ed97f.26f3a8","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

To load it into my NAS, I’ve enabled there the FTP server and in MotionEye the File Storage section looks like this

where in the Run a command

mosquitto_pub -h 192.xxx.xxx.xxx -u username -P "password" -t ipcam/Vialetto/filename -m "%f"

Sorry for the late reply but I was on an longer business trip.

Simple solution for webhook when detecting motion:

  • With this setting in FileStorage, all stored files will be announces to NR via webhook

  • I have enabled the MOVIE option so all motion detection will be recorded and stored

  • the webhook command is http://192.168.1.200:1880/detect?%f

  • NR (192.168.1…200) is now waiting for the webhook command

[{“id”:“b5626db9.79af9”,“type”:“http in”,“z”:“636198cf.864788”,“name”:“”,“url”:“/detect”,“method”:“post”,“upload”:true,“swaggerDoc”:“”,“x”:130,“y”:90,“wires”:[[“928aeb8.3a6ad18”,“bca47a46.d4be58”]]},{“id”:“928aeb8.3a6ad18”,“type”:“change”,“z”:“636198cf.864788”,“name”:“”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“req.url”,“tot”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:340,“y”:90,“wires”:[[“e09378ba.dc0ed8”]]},{“id”:“bca47a46.d4be58”,“type”:“debug”,“z”:“636198cf.864788”,“name”:“”,“active”:false,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:310,“y”:50,“wires”:},{“id”:“e09378ba.dc0ed8”,“type”:“string”,“z”:“636198cf.864788”,“name”:“”,“methods”:[{“name”:“getRightMost”,“params”:[{“type”:“str”,“value”:“output/”}]}],“prop”:“payload”,“propout”:“payload”,“object”:“msg”,“objectout”:“msg”,“x”:500,“y”:90,“wires”:[[“1a28684c.da8718”]]},{“id”:“9fc524e9.57a358”,“type”:“inject”,“z”:“636198cf.864788”,“name”:“”,“topic”:“”,“payload”:“”,“payloadType”:“date”,“repeat”:“”,“crontab”:“”,“once”:false,“onceDelay”:0.1,“x”:130,“y”:130,“wires”:[[“928aeb8.3a6ad18”]]},{“id”:“1a28684c.da8718”,“type”:“change”,“z”:“636198cf.864788”,“name”:“file”,“rules”:[{“t”:“set”,“p”:“file”,“pt”:“flow”,“to”:“…/motionEye/xxxx”,“tot”:“str”},{“t”:“change”,“p”:“file”,“pt”:“flow”,“from”:“xxxx”,“fromt”:“str”,“to”:“payload”,“tot”:“msg”},{“t”:“set”,“p”:“filename”,“pt”:“msg”,“to”:“file”,“tot”:“flow”},{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“file”,“tot”:“flow”},{“t”:“set”,“p”:“url”,“pt”:“msg”,“to”:“file”,“tot”:“flow”},{“t”:“delete”,“p”:“topic”,“pt”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:620,“y”:90,“wires”:[[“ef371c1f.8f5c48”]]},{“id”:“ef371c1f.8f5c48”,“type”:“q-gate”,“z”:“636198cf.864788”,“name”:“M-Queue”,“controlTopic”:“control”,“defaultState”:“open”,“openCmd”:“open”,“closeCmd”:“close”,“toggleCmd”:“toggle”,“queueCmd”:“queue”,“defaultCmd”:“default”,“triggerCmd”:“trigger”,“flushCmd”:“flush”,“resetCmd”:“reset”,“maxQueueLength”:“5”,“keepNewest”:false,“x”:790,“y”:90,“wires”:[[“17734516.d2097b”,“b2951f30.6ca1a”]]},{“id”:“17734516.d2097b”,“type”:“change”,“z”:“636198cf.864788”,“name”:“queue”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“queue”,“tot”:“str”},{“t”:“set”,“p”:“topic”,“pt”:“msg”,“to”:“control”,“tot”:“str”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:970,“y”:90,“wires”:[[“ef371c1f.8f5c48”]]},{“id”:“b2951f30.6ca1a”,“type”:“string”,“z”:“636198cf.864788”,“name”:“”,“methods”:[{“name”:“getRightMost”,“params”:[{“type”:“str”,“value”:“.”}]}],“prop”:“filename”,“propout”:“payload”,“object”:“msg”,“objectout”:“msg”,“x”:330,“y”:210,“wires”:[[“bdfbf7e9.958da8”,“95833bc8.6f8218”]]},{“id”:“b620cd28.897768”,“type”:“change”,“z”:“636198cf.864788”,“name”:“trigger”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“queue”,“tot”:“flow”},{“t”:“set”,“p”:“topic”,“pt”:“msg”,“to”:“control”,“tot”:“str”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:800,“y”:180,“wires”:[[“ef371c1f.8f5c48”]]},{“id”:“bdfbf7e9.958da8”,“type”:“switch”,“z”:“636198cf.864788”,“name”:“”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“jpg”,“vt”:“str”},{“t”:“eq”,“v”:“mp4”,“vt”:“str”},{“t”:“eq”,“v”:“mkv”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:3,“x”:490,“y”:210,“wires”:[[“e8888be5.2aaf38”],[“f54c88ef.115a38”],[“f54c88ef.115a38”]]},{“id”:“95833bc8.6f8218”,“type”:“debug”,“z”:“636198cf.864788”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:490,“y”:260,“wires”:},{“id”:“e8888be5.2aaf38”,“type”:“change”,“z”:“636198cf.864788”,“name”:“pic”,“rules”:[{“t”:“set”,“p”:“picture”,“pt”:“global”,“to”:“payload”,“tot”:“msg”},{“t”:“set”,“p”:“caption”,“pt”:“global”,“to”:“filename”,“tot”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:660,“y”:200,“wires”:[[“c687e392.5d9f2”,“b620cd28.897768”]]},{“id”:“f54c88ef.115a38”,“type”:“change”,“z”:“636198cf.864788”,“name”:“vid”,“rules”:[{“t”:“set”,“p”:“video”,“pt”:“global”,“to”:“payload”,“tot”:“msg”},{“t”:“set”,“p”:“caption”,“pt”:“global”,“to”:“filename”,“tot”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:660,“y”:230,“wires”:[[“5e3e02c0.50fb3c”,“b620cd28.897768”]]},{“id”:“92544308.8e67f”,“type”:“inject”,“z”:“636198cf.864788”,“name”:“”,“topic”:“”,“payload”:“”,“payloadType”:“date”,“repeat”:“”,“crontab”:“”,“once”:false,“onceDelay”:0.1,“x”:650,“y”:170,“wires”:[[“b620cd28.897768”]]},{“id”:“c687e392.5d9f2”,“type”:“link out”,“z”:“636198cf.864788”,“name”:“”,“links”:[“8657281d.7cbcb8”],“x”:865,“y”:210,“wires”:},{“id”:“5e3e02c0.50fb3c”,“type”:“link out”,“z”:“636198cf.864788”,“name”:“”,“links”:[“423e77f4.d1a7c8”],“x”:865,“y”:240,“wires”:}]

  • the /detect is choosen as command word by me
    NR_Post_detail
  • the %f parameter will contain the filename of the last save file including path
  • I have the best experience by sending MKV files
  • the flow will extract the filename and send the filename to Telegram.
  • the flow is detecting VIDEO and IMAGE file by the extension and sends the according command to Telegram
  • Telegram is able to load the filename and send it directly

Please let me know if you have any more questions. I hope this will help

I have a second camera for which I don’t save the picture and just getting a notification when a motion was detected !
MotionEye_Notification

[{“id”:“8e0d4acb.ff4138”,“type”:“http in”,“z”:“636198cf.864788”,“name”:“”,“url”:“/motion”,“method”:“post”,“upload”:true,“swaggerDoc”:“”,“x”:130,“y”:300,“wires”:[[“4da6f554.b2ed7c”]]},{“id”:“4da6f554.b2ed7c”,“type”:“string”,“z”:“636198cf.864788”,“name”:“”,“methods”:[{“name”:“delLeftMost”,“params”:[{“type”:“str”,“value”:“motion?”}]}],“prop”:“req.url”,“propout”:“payload”,“object”:“msg”,“objectout”:“msg”,“x”:310,“y”:300,“wires”:[[“c843bf63.a69db”]]},{“id”:“c843bf63.a69db”,“type”:“debug”,“z”:“636198cf.864788”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:710,“y”:300,“wires”:}]

4 Likes

Hi, you still use this. Trying to make it work but can’t.

For the moment trying to fix the motion alert without sendiong videos.

Is this the webhook URL in your example?

http://192.168.1.136:1880/motion?%

I am using motioneye inside HASSIO, does this change somethging? Like this??

http://192.168.1.136:8123/hassio/ingress/a0d7b954_motioneye/motion?%

This is the link when opening my Node-Red

http://192.168.1.136:1880

All webhook messages have to go to that link

To capture the command you just add the parameter

http://192.168.1.136:1880/motion?%

Unfortunately i do not have node-red on hassio anymore … but it should be easy to get the link

ok, when I click that link it asks for a username and password (even if in my HASSIO NODE-RED addon there is none), do you have a username and password set? How to add it in the link?

What is the link you are using for Node-red?

Use the same one … just at the motion part

In the motioneye folder, I use this. It waits until the file is finished then copies it where I want it and changes the name (so I can always send whatever the last capture was to telegram without worrying about folders and name changes)
You should be able to change it to your network location.

1 Like

@Kayhold
I have few questions and maybe you can help me.
My motioneye and home-assistant are on the same network at different IPs…how I can change the command to save the files to: [home-assistant IP]/config/cctv (cctv - folder in home-assistant /config for ex.)
Using the same name (lastmovie.mp4) will constantly overight the file ?
How I can do the same with still images in motioneye config?

thanks in advance for your time and help on this.

Dear all,

I can’t trigger the motion detection in Node Red for MotionEye. My motion Eye configuration is:

But for me is impossible to configure in Node Red the correct node to detect.

I try to select the following node:

image

image
and
image

But don’t works.

Please any help about this?.

Thanks in advance.

Jose

Jose, I’m going down this path myself. I have the name of the file coming through in the webhook if you look at the below difference in my webhook;

https://homeautomation.xyz:1880/apiv2/aasdkfjpoing?%f

I’m putting the ?%f at the end of the webhook in MotionEye. From here I can understand, almost, the filename in Node-RED but I’m not sure what I’m going to do with it.

After my webhook node I’m running this debug node - instead of pulling msg.object I’m finding the information in req._parsedUrl.search this gives me output like: “?/mnt/xstore/motion-porch/2020-11-28/17-50-15.mp4” from the URL called to NR.

What to do with the filename after stripping off the first few characters will be the challenge…

Edit: I think I solved it.

I mounted the location of the files with Node-RED’s docker container. I’m passing the image attribute to a node and it’s reading the file from the system.

@xx_Nexus_xx Salut, je sais que ton message date de quelques années mais est il possible de m’aider avec ton flow node red? Je n’arrive pas à recevoir mes vidéos de MotionEye sur mon telegram ou discord avec ton flow.
D’où l’erreur peux provenir: J’ai une erreur: