How To Send Blue Iris Images to Telegram

by Danny
7 comments

READING TIME: 8 MINUTES

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:

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.

This image has an empty alt attribute; its file name is image-132.png

Once you’ve received the message, you can now add the URL to Blue Iris.


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.

Don’t forget to include the – in the Chat ID!

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.

The full list of server components I use can be found on my Equipment List page.

7 comments

You may also like

7 comments

Ian Butcher August 19, 2021 - 11:53 am

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?

Reply
Danny September 1, 2021 - 4:12 am

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!

Reply
Ian September 1, 2021 - 7:21 am

Hi Danny

Yes, I managed to work it out, but thanks anyway!

Reply
Jeff August 21, 2021 - 3:51 pm

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?

Reply
Danny September 1, 2021 - 4:10 am

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.

Reply
Michael September 5, 2021 - 4:06 am

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!

Reply
Danny September 5, 2021 - 10:00 am

You’re welcome Michael, I’m glad it helped you send images to Telegram!

Reply

Leave a Comment