In this guide, I’m going to show you how to send motion alerts (analyzed by Deepstack) from your Blue Iris NVR to Telegram (Option 1). I will also show you how to attach a Deepstack-analyzed photo of your tracked object and send it to Telegram (Option 2).
One of the biggest advantages of using a Telegram bot for Blue Iris alerts is that it will show you a history of every alert that has ever been triggered with the included image.
Prerequisites
You will need the following items setup:
- Blue Iris installed
- Telegram app installed on your phone
- A Telegram account
- Telegram group and bot created
Once you have those items ready to go, you can continue following this guide.
Set Up Telegram Bot
Before you can get Telegram alerts from Blue Iris, you first need to create a Telegram bot to get your API key and Chat ID.
Option 1: Send Generic Text Message to Telegram
Create & Test Telegram Message
Before we start messing around in Blue Iris to receive motion alerts, we should first check to make sure you can receive ANY alerts at all in Telegram from a web request.
To test, create a Telegram HTTP Web Request URL.
https://api.telegram.org/botTelegramAPIKey/sendMessage?chat_id=ChatID&text=Motion detected in Driveway!
Once you replace the API key and Chat ID with your own, paste the URL into a browser. You should receive a Telegram text notification with a generic “Motion detected in Driveway!” message.
Once you’ve received the message, you can now add the URL to Blue Iris.
If your ChatID came with a hyphen – use it. If it doesn’t have a hyphen, don’t add it at the front like I did.
Edit Blue Iris Camera Alert
Next, log into your Blue Iris server.
Right-click a camera > Camera Settings.
Click the Alerts tab > On Alert.
Click the + button > Web request or MQTT.
Switch to https://
and then paste the URL from the previous step. Leave out the https:// as it’s already in the dropdown.
Test Sending Motion Alerts to Telegram
Now, you can simply walk in front of your camera. Within a second or two, you should receive a text alert in Telegram!
Once you verify that this works for one camera, you can set the alerts for each camera. The only thing you’ll need to change is the message (For example, change Motion detected in Driveway to Patio).
Option 2: Send Deepstack-analyzed images from Blue Iris to Telegram
Step 1: Download CURL
Download CURL for Windows on your Blue Iris server.
Choose 64 bit.
Right click the zip > Extract to your Downloads folder.
Step 2: Create 2 new Windows Folders
Next, create two new folders in your parent “BlueIris” folder (This is the Windows folder where you already have New, Alerts, Stored, and db folders). Name them:
- Telegram_Alerts
- Telegram_Upload
Your parent BlueIris folder should now look like this:
Step 3: Copy BIN folder to Telegram_Upload folder
Click into your extracted CURL folder. The folder should be named something like curl-7.78.0-win64-mingw
.
Copy the entire BIN directory to the S:\BlueIris\Telegram_Upload folder.
Step 4: Add Telegram_Alerts folder to Blue Iris
For this step, we are adding a new folder to Blue Iris. We are doing this so Blue Iris will copy JPEG images (that Deepstack has already analyzed and detected as a “person” object) into the Telegram_Alerts folder.
Within Blue Iris Admin, click the gear at the very top to edit the global settings.
Click the Clips and archiving tab.
Under Folders, choose one your spare Aux folders (Aux 1). Then, add the path to your Telegram_Alerts folder. (S:\BlueIris\Telegram_Alerts
). Then click OK.
Step 5: Edit camera settings (to save JPEG files to new folder)
Log into your Blue Iris server. Right-click a camera > camera settings.
Switch to the Record tab.
Check the box for JPEGs, set it to When Alerted, change the folder to Aux 1, and set the quality to 100%. If you have 4k cameras, you might want to adjust the quality and/or resize it so it uploads quicker.
Now, whenever Blue Iris/Deepstack detects motion, it will place the image in your Telegram_Alerts folder, which is exactly what we need for the next step. The next step will have you create a command to copy the latest image in that folder & send it to Telegram.
Step 6: Create Telegram_upload.cmd file
Open Notepad on your Blue Iris server. Paste in the command below. Edit the paths in green, the Telegram API key in red, and the Chat ID in orange.
Reminder: If your ChatID came with a hyphen – use it. If it doesn’t have a hyphen, don’t add it at the front like I did.
IMPORTANT NOTE 12/16/22: The CURL command below needs to be on 1 line. When you copy it from below, it copies it as two, so make sure to fix the formatting.
SET PICFolder=S:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%%i
rem for /f %i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%i
CURL https://api.telegram.org/botTelegramAPIkey/sendphoto -F chat_id=-ChatID -F photo=@S:\BlueIris\Telegram_Alerts\%LAST%
Then go to File > Save As. Name the file Telegram_Upload.cmd
and save it to your S:\BlueIris\Telegram_Upload
folder.
Final Step: Create Blue Iris Camera Alert to run command
Edit your camera again. Switch to the Alerts tab.
Under the Actions section, click On alert.
Click the + button to create a new alert. For the action, select Run program/script and point it to the path of your Telegram_upload.cmd file.
Then click OK on all the camera settings screens to save everything.
Testing it Out
Now, simply walk in front of your camera. If all goes well, the command should run and you should receive the latest image from the S:\BlueIris\Telegram_Alerts folder directly in Telegram!
Hint: As long as there is at least 1 image in the Telegram_Alerts folder, you can also simply run the Telegram_Upload.cmd file by clicking it. That way you don’t have to run in front of your camera a bunch of times. If you receive the image, then you know it worked!
Optional Tweaks
If you notice it’s taking a while to get the image in Telegram, you might want to change the quality/resolution from 100% to 50% so the filesize is smaller. 4k cameras obviously have a much larger file size and will take the longest to upload to Telegram. For reference, my images are 1080p. I receive text messages almost immediately, and pictures within 5-10 seconds.
If you are receiving too many alerts, you can edit that as well. Camera > Camera Settings > Alerts tab. Check the box for “minimum wait time between alerts” and set a threshold.
If you would like to include a message with your picture, then create both Option 1 and Option 2. You will have 2 alerts configured for each camera. You will first receive the text message letting you know which camera was triggered, and then a few seconds later you’ll get the corresponding picture.
If you would like to only receive alerts during a specified time frame (such as overnight), you can create a 2nd script with a set time frame that calls the Telegram_Upload.cmd file. If between the hours you specify, the script runs. If it doesn’t meet your criteria, it doesn’t. Here’s how to set that up: https://smarthomepursuits.com/run-batch-file-during-certain-time-window/
Wrapping Up
This guide took me way too long to figure out and script together, so if it worked for you – please let me know in the comments below and share it in any forums/threads where you see others requesting how to do this.
Good luck, and hopefully this helps you send pictures to your Telegram bot when Blue Iris and Deepstack detects motion!
My Homelab Equipment
Here is some of the gear I use in my Homelab. I highly recommend each of them.
- Server 2019 w/ Hyper-V
- Case: Fractal Design Node 804
- Graphics Card: NVIDEA Quadro K600
- CPU: AMD Ryzen 7 2700
The full list of server components I use can be found on my Equipment List page.
Hi Danny
Great write up thank you – this is exactly what I wanted to do, using inbuilt deepstack and push images to an app (other than the BlueIris app)
I wonder if you can help though – it’s not quite working. I’m getting the picture in the Telegram_Alerts directory, and the alert is triggering, but the response from the script is giving me the following error:
{“ok”:false,”error_code”:404,”description”:”Not Found”}
This means I am not getting the message with the picture attached.
Any ideas?
Sorry for the late response! I just realized my replies were never sending out to commenters.
Hey Ian,
I received that error several times when writing the script, but it was usually due a bad path.
Just in case you hadn’t figured it out yet, I was missing the word “bot” in my command. Put bot before the TelegramAPIkey. I’ve also updated my guide with the correct syntax for you. Let me know if that works!
Hi Danny
Yes, I managed to work it out, but thanks anyway!
I just followed the steps and got it working, was wondering if it’s possible to get the Deepstack analyzed images? Would I have to copy it from the alerts folder?
That’s exactly what it does already. If you look in your current Alerts folder, it contains all images – both images taken every few seconds and the Deepstack ones. I basically just configured Deepstack to copy the “alerted” files to separate folder for use with Telegram image messages.
Thank you very much for this good description on how to get telegram working with BlueIris. It must have been a lot of work for you!
You’re welcome Michael, I’m glad it helped you send images to Telegram!
Very good article. The only issue I have is that the script is sometimes sending the same image twice, as BI hasn’t sent the new alert JPEG to the folder yet.
Thank you for this write up! Got it working as it should, although there’s a slight flaw with the script I wonder if you can assist with. I have an issue where an alert will take place, but the last image is sent again. So I end up with many copies of the same image alert. Is there a way to adjust the script so this doesn’t happen?
Thanks again!
Great! I’m glad you got it working following my guide.
I do occasionally get double images, but I haven’t looked into why yet. I think a few possible things you can look into are:
1. Reducing image size/quality so Deepstack can process them quicker.
2. In the Alerts tab of the camera, look at the Timer settings. I’m not sure if the Timer settings also affect the Action settings, but if it does – maybe set the “Wait until triggered at least” option to 2 or 3.
3. You could add a “SLEEP 5” or something like that to the top of the .CMD file, but then it’ll delay ALL alerts by a few seconds, so idk if that’s something you’d want to do. I actually think what you’d have to do is create a 2nd batch file (Telegram_Upload_Wait.cmd) that calls the Telegram_Upload.cmd using an if/then statement. If Telegram_Upload.cmd hasn’t ran in the last 5 seconds, then call it. If not, do nothing.
If you do figure out a good solution or script, let me know and I’ll test it out!
Thanks for the fantastic tutorial.
I’ve been working on this for a few hours and couldn’t get the picture to come through only the text.
I’ve even installed BlueIris on another PC just to try something else. My problem was my chat ID didn’t come with a hyphen “-“. In your tutorial you specifically say to remember the hyphen for the chat ID “…id=-ChatID…” . Maybe just add a sentence there to say that: “if your ChatID came with a hyphen use it, if it didn’t come with a hyphen don’t add it at the front”.
Thanks for the fantastic tutorial!
Oh interesting, I assumed everyone’s chat ID included a hyphen. I will definitely update my post – thanks so much for the tip on that and I’m glad you got it working!
Awesome tutorial. I got this working for 2 days and it stopped working. Deepstack is still creating the files in the “Alerts” folder, but nothing is being copied into the “Telegram_Alerts” folder since 10/21. The bin folder is still in the “Telegram_Upload” folder and so is the cmd file. The trigger settings haven’t been changed in Blue Iris either. If I manually run the command file it pushes the old file from 10/21 through Telegram within a second or 2 without an issue. I think Curl might be the issue, but I’m not sure how Curl helps with copying the images from “Alerts” into “Telegram_Alerts”. Have you experienced this? Thanks
If it’s not copying new files to the Telegram_Alerts folder, then it’s got to be an issue with step 4 or 5. You’re right; the CURL command isn’t in play for the copy, and you’ve confirmed that the CURL command still works when running manually.
It could also be a random issue with BI or Windows, have you tried restarting the application or host computer to see if that helps?
Hi Danny,
I wonder if possible if you can perhaps login to my pc and help setup,i do get alerts via telegram but no pictures.Followed you step by step but missing something.Please if you can.
Yeah, I’ve restarted Windows. Blue Iris is up to date as of today as well. It’s strange because the settings haven’t changed and it was working. It just stopped on its own on 10/21 at night. I haven’t tried disabling the JPEG setting and enabling it again. Maybe just BI glitching.
Hi Danny,
I wonder if possible if you can perhaps login to my pc and help setup,i do get alerts via telegram but no pictures.Followed you step by step but missing something.Please if you can.
if you add the following string to any notification (sms, email, Telegram), it will create a link at the end of the message to Ui3 >> &WAN/ui3.htm?rec=&ALERT_DB&maximize=1
https://ipcamtalk.com/threads/how-to-stream-blue-iris-alerts-directly-in-ui3-on-any-device.54886/
Morning
is this still working as described above, I have followed the steps exactly and the images are being fed to the correct folder, but when running the cmd, it doesn’t upload to telegram, have created the bot and made a group, including the – at the front. I suppose we exclude the hashtag. got the word bot at the front of the api key
Mine is still working perfectly, no changes made since I wrote this.
Can you trigger a generic message from Option 1? Just wondering if it’s images only that aren’t sending or nothing at all.
Also – if your API key doesn’t have a dash, then remove it. Here’s my exact .cmd file (numbers changed, obviously):
SET PICFolder=S:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%%i
rem for /f %i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%i
CURL https://api.telegram.org/bot19777777777:BHFfRJjqL-V-xtGFJIUWorydlc31P3BiNwQ/sendphoto -F chat_id=-78656754 -F photo=@S:\BlueIris\Telegram_Alerts\%LAST%
SET PICFolder=C:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i
CURL https://api.telegram.org/bot5117555087:AAGT5JSPGVb3Rj26TXXXXXXXXX/sendphoto -F chat_id=-XXXXXXXXX -F photo=@C:\BlueIris\Telegram_Alerts\%LAST%
this is my command, do you see any issues?
SET PICFolder=C:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i
CURL https://api.telegram.org/bot5117555087:AAGT5JSPGVb3Rj26TXXXXXXXXX/sendphoto -F chat_id=-XXXXXXXXX -F photo=@C:\BlueIris\Telegram_Alerts\%LAST%
this is my command, do you see any issues?
the message option does go through to the group
I copied both your code and my code into Notepad++ and ran Compare. When you switch between the two files you’ll notice the apostrophes, quotes, and parenthesis are slightly different (some are bolder, more italicized, etc.) The results of Compare also show these two files are different because of the quotes/parenthesis being different, too. I wonder if that has something to do with it.
I wish I knew how to explain this better, but here’s a screenshot: https://imgur.com/a/VDoSXjz
Understood, strange that it did that in notepad as I copy-pasted your code directly into it, perhaps it’s a region thing and windows adjust accordingly. will alter and let you know.
So after checking this it doesnt appear to be a formatting issue, see attached screenshots of my entire setup, not sure what happened as to why you see it differently on your side than I do when copy pasting.
https://ibb.co/swyF8BK
https://ibb.co/WfS8zBg
https://ibb.co/kgk8Skp
https://ibb.co/sg8K1WT
https://ibb.co/DtmZWn6
https://ibb.co/QQtqYhB
Seems like everything is working except I get the following error when curl tries to send the photo to Telegram:
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) – The revocation function was unable to check revocation for the certificate.
Seems to be an issue with certificate
Add –ssl-no-revoke to the CURL command. I had the same issue & this worked for me.
At first I was setting TLS error, which was fixed by running: “[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12”
However, now I’m getting either of these errors (with or without “‘s)
CURL : {“ok”:false,”error_code”:404,”description”:”Not Found”}
Invoke-WebRequest : A parameter cannot be found that matches parameter name ‘F’
SET PICFolder=D:\Blue Iris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i
CURL https://api.telegram.org/bot5598689928:AAHskBrTfp1894dpgQpnFUjIxwBHWoIx0tE/sendphoto -F chat_id=-754844202 -F photo=@D:\Blue Iris\Telegram_Alerts\%LAST%
i get error curl: (26) Failed to open/read local data from file/application
curl: (26) Failed to open/read local data from file/application
how to fix this error
Hi
I tested my web browsers on both PCs, 1 at work and 1 at home, both browsers cannot load the
pictures / diagrams.
Can you fix the links to the pictures, there are not loading up.
Thank you.
Regards,
Marcus
Thanks for letting me know. I just fixed the caching issue, pics are now showing up correctly again.
Thanks, Danny the pics are loading now!
Hi Danny,
I double-check the path is correct = C:\BlueIris\Telegram_Upload\Telegram_Upload.cmd
All profiles: 1 to 7 are turned on (no grey out).
I tested the command: Telegram_Upload.cmd in the Action Set window, by pressing the “thunder” icon.
I get a response from Blue Iris: Web: HTTP/1..1 200 ok, I pressed OK button to close the window.
I do get notifications on my Telegram Bot.
I have double-checked there are lots of photos in Telegram_Alerts.
I have double-checked the command syntax is correct.
But I don’t get any photos sent to my Telegram Bot. I only received messages.
What could be the reason of not get the photos sent?
Thank you.
For anyone receiving doubles of images in their feed.
I fixed this by simply putting a timeout at the beginning of the curl script.
Timeout /t 5
I found that the alert was being sent out before my cpu could process the deepstack image and place it in the alerts folder. Therefore it was grabbing the previous image from an earlier time.
By delaying the entire script by 5 seconds it gave my cpu enough time to process the new image.
Hope this helps
Confirmed – I was sometimes getting duplicates myself, but adding that fixed it for me.
I had the issue with images not being uploaded.The cause seems to be simple
CURL https://api.telegram.org/botTelegramAPIkey/sendphoto -F chat_id=-ChatID -F photo=@S:\BlueIris\Telegram_Alerts\%LAST%
should be in a SINGLE LINE in the cmd file created
due to formatting in this website it comes in two seperate lines which possible caused a syntax error.
Good tip! I didn’t realize that, I updated the guide to include that note.
I actually need to send the last 2 images since I have thermal hybrid cameras and the visual camera then thermal is alerting. Can you show me the script code for this? Also, your script may bork if multiple cameras are set off at same time on the property, sending same images, may need some code to determine if an image was sent already, that would also solve my first problem actually.
Any ideas or code for me?
Hi Danny, thank you so much for the instructions. It works great! I have 6 separate scripts because I have 6 cameras. The only issue that I am facing is that when the alert is triggered and the script is ran, it sends out the last but one image. Seems there is a delay with blueiris actually copying that last analyzed image to the folder. Any way I can delay running the script maybe by a second or two so it always gets the last? Or do i need to lower down the resolution of the image or do some settings in blueiris? Much appreciated!
Hello, after a few hours of trying out what is going wrong… i think i can use some help.
Text message’s sending works perfect.
For the pictures, i double checked everything.
My script looks like this:
SET PICFolder=D:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i
CURL https://api.telegram.org/bot1234567890:AAF5cMH6zghhsggjfYTFm0byCM19Yn7gger/sendphoto -F chat_id=123456789 -F photo=@D:\BlueIris\Telegram_Alerts\%LAST%
-The curl is on one line.
-All zones and profiles are active.
-Bin and CMD are in folder D:\Blue Iris\Telegram_upload
-Pictures are in folder D:\Blue Iris\Telegram_Alerts (and the folder is filling with new pictures)
Any idea what i can do to troubleshoot?
Thanks for the help.
Hello,
So i noticed…. my BI folder was named ‘Blue Iris’ instead of ‘BlueIris’
I made a new folder in D: , named it BlueIris, dragged everything into it and voila, everyhting is working now. Maybe this helps for some people who cant get pictures upload to work.
While testing this on my 10 cam setup i noticed that sometimes the cam that starts the cmd, shows the picture of another cam. Since it takes the last picture, when 2 cams are busy, it only shows the last one. Can de script be modified with (a part) of the name of the camera in it? This so that the cam that starts the alert only calls the last picture of that specific cam. For example, last picture with “cam1, cam2, cam3 etc” in it. Would be great, but I’m not a codewriter haha.
I’ve been playing with this for days, and I was getting pics from some cameras, and no pics or other messages from other cameras. I haven’t read every comment in this thread, but I figured out why. Putting a required element in your “On Alert” message will cancel both notifications except when actually executing. To test it I would right-click and click Trigger now, but it would never send. All the AI-required elements can only be in the Trigger->Artificial Intelligence Box. I hope this helps someone.
If anyone is still monitoring this thread, I’m having issue with getting Codeproject AI analyzed images uploaded. It grabs them, they are in my BlueIris Alerts Folder, but the images ending up in the Telegram_Alerts are not analyzed, and of a different timestamp in the name, not a -1 image like in the Alerts folder. Where is it grabbing them from? Shouldn’t the folder in the Record tab for alerts be pointing to the Alerts folder, not the Telegram_Alerts folder? I’m not a scripter, so I don’t understand all that the Curl script is doing. Any help please!