Blue Iris integration- HTTP binding, REST api

Id love to be able to put live images into my Android notification when someones at my door. How did you do that? Great!

The writeup will be a bit long so Iā€™ll try to find some time in the next few days to post it.

In the meantime, to answer your question in the other thread, yes, the pushover binding has supported images since OH1. The only new thing added (on the pushover side) is support for animated GIFs. As far as I can tell, nothing needs to change in OH to get this working, so all versions should support it.

3 Likes

Thank you!

Summary
Send animated GIFs from Blue Iris to your phone.

Overview
Blue Iris gives you tons of different ways to work with your videos. I chose to animate JPEGs instead of video since I assume most people on Blue Iris use the proprietary *.bvr format and JPEGs are easier to convert. The JPEG method has the benefit of being less disruptive for most BI users. On the other hand, if you record in MP4 in BI, there are probably more efficient ways to create GIF files.

In my example below, GIF conversion is done on my BlueIris server since it has the most horsepower in my environment. I am using FFmpeg to do the processing since it works on Windows, the standalone binary is easy to use, lightweight, and can be run without a full-blown installation. The *.BAT files are written with FFmpeg in mind. If you want to do it on a linux environment, you can use imagemagick and the shell script would be cleaner.

This process follows several steps:

  1. Configure Blue Iris to save JPEGs from video triggers
  2. Convert them into animated GIFs. This process can be done with any number of methods.
  3. Send converted GIF to Pushover for mobile notifications.
  4. Bonus - link the notification to a live view of your camera feed.

Requirements

Configuration for BI server to capture JPEGsunnamed :

  • Create a subfolder for Blue Iris to store JPEG alert images. For example: D:\BlueIris\New\frontdoor
  • Inside the folder above, create another subfolder to temporarily stage JPEGs for conversion
    In my case, Iā€™m using D:\BlueIris\New\frontdoor\gif_processing
  • On the camera you want to capture, go to camera properties - record.
  • Check JPEG snapshot each
  • Change snapshot time to match whatever framerate you want for your GIF. Iā€™m using .5 seconds.
  • Check only when triggered
  • Create capture path to match the location of the folder you created above (i.e. frontdoor)

You should now have a set of JPEGs automatically generated and stored in D:\BlueIris\New\frontdoor whenever blueiris triggers for your camera. Repeat process for other cameras, but remember to set your alert paths accordingly. I suggest keeping separate folders for easier processing.

Create BAT files on BI server for GIF generation and trigger openHAB
Download FFmpeg to the BI server and store ffmpeg.exe somewhere in your path or in the same folder as your bat files. For the purpose of this example, Iā€™m going to assume everything in this section (ffmpeg.exe and bat files) is saved to D:\BlueIris\Alert\

DOS scripting is terrible, and Iā€™m terrible at it, but hereā€™s the best I could come up with quickly. I was not able to get the DOS-based loop to break properly, so you need all 3 bat files for now (I will go back and refactor this to just one script or maybe change to powershell in the future)

front_door_motion.bat
This will call either on or off actions based on BI alerts

@echo off

IF "%1"=="" (
   call front_door_motion_on.bat
) else (
   call front_door_motion_off.bat
)

front_door_motion_on.bat
When the camera detects motion, this script copies the latest 8 JPEGs from the snapshot folder above, creates the animated GIF in D:\BlueIris\Alert\out.gif, and alerts openHAB of the trigger via legacy call. Iā€™m using ping as a wait command to give BI enough time to generate the image files. Adjust those variables for your own environment. This method has a drawback in that it takes about 10-15 seconds before it alerts OH.

Make sure you have a switch item setup in openHAB to accept the trigger call from wget. In my case, Iā€™m using MotionSensorFrontDoorCameraTripped. Item file listed below.

@echo off

PING 127.0.0.1 -n 5

setlocal EnableDelayedExpansion
CALL :ProcessJPGS

:ProcessJPGS
set i=8
for /f %%a in ('dir /b/a-d/o-d/t:w D:\BlueIris\New\frontdoor\*.jpg') do (
  copy "D:\BlueIris\New\frontdoor\%%a" "D:\BlueIris\New\frontdoor\gif_processing\"!i!".jpg"
  set /a i-=1
  if !i!==0 (
	echo y|del D:\BlueIris\Alert\out.gif
	echo y|ffmpeg.exe -f image2 -framerate 5 -i D:\BlueIris\New\frontdoor\gif_processing\%%d.jpg -vf scale=480x270 "D:\BlueIris\Alert\out.gif"
	PING 127.0.0.1 -n 3
	wget.exe "http://<OHserver>:<OHport>/classicui/CMD?MotionSensorFrontDoorCameraTripped=ON" -O nul
	goto :eof
  )

)

front_door_motion_off.bat
Reset OH item and clean up staging files

@echo off

    wget.exe "http://<OHserver>:<OHport>/classicui/CMD?MotionSensorFrontDoorCameraTripped=OFF" -O nul
    echo y|del "D:\BlueIris\New\frontdoor\gif_processing\*.jpg"   

Configure BI to run the BAT files you just created

Under camera properties - alerts

  • check Run a program or execute a script
  • Configure as follows:
    Capture

openHAB setup

Set up your OH server with a CIFS mount (or samba share if you want to go the other direction) to access D:\BlueIris\Alert\ on the blueiris machine. The rule below assumes this mount point is /mnt/blueirisalerts/.

To reduce false positives, the OH rule is set to only trigger if both the camera and PIR sensor detect motion at the same time. My production version expands this to compare times and only trigger if the camera trips first. This way it only records one-way traffic (people leaving the house donā€™t trigger an alert).

camera.items

Switch     MotionSensorFrontDoorCameraTripped "Front Door Camera Motion" 
Contact    FrontDoorMotionTripped "Front Door PIR sensor Tripped [MAP(en.map):%s]" {mios="unit:vera,device:28/service/SecuritySensor1/Tripped"}

frontdoorbell.rules

var String PushOverAPIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
var String PushOverUserKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx"

rule "FrontDoorActivity"
when
  Item MotionSensorFrontDoorCameraTripped changed from OFF to ON
  or Item FrontDoorMotionTripped changed from CLOSED to OPEN
then

  if (FrontDoorMotionTripped.state.toString == "OPEN" && MotionSensorFrontDoorCameraTripped.state.toString == "ON") { //camera tripped first = arrival or both sensors tripped
	sendPushoverMessage(pushoverBuilder("Someone's at the front door").withApiKey(PushOverAPIKey).withDevice(PushOverUserKey).withTitle("Front Door").withAttachment("/mnt/blueirisalerts/out.gif").withUrl("https://yyyyy.com").withUrlTitle("Live"))
  }
	
end
7 Likes

@roy_liao
Thanks for posting this as I bumped into this thread looking for which push methods could send an animated gif to my phone.

The next build of the ipcamera binding will have a easier to implement and use method to create animated GIF files and a mechanism to inform Openhab when the file is created and ready to be used. I have looked at your ffmpeg command and can recommend you change it to use 2 pass encoding as it greatly improves the picture quality by creating a custom palette for the colours in the GIF. If interested I can suggest some changes to the ffmpeg command which will remove the cross/pixel look from the output that you will be getting.

Also are there any size limitations that pushover can send to your phone in an alert?

1 Like

@matt1

Yeah, Iā€™d love some tips! Any optimizations you can suggest would be great.

I did a quick search for size limits on pushover binary but couldnā€™t find any (Iā€™m sure there must be). In my own environment, I havenā€™t run into any limits yet.

This should give you better picture quality with zero extra file size at the expense of slightly more time to encode due to the need to do a second pass. Also the -2 in the Scale option will mean it wont stretch different aspect ratio cameras, it auto changes the value to suit and keeps it at a round number.

This is what I use with a live stream as the inputā€¦

-filter_complex fps=2,scale=480:-2:flags=lanczos,setpts=0.5*PTS,split[o1][o2];[o1]palettegen[p];[o2]fifo[o3];[o3][p]paletteuse

So try something like this on the command line to trial if it gives you the desired effectā€¦

ffmpeg.exe -y -f image2 -framerate 5 -i D:\BlueIris\New\frontdoor\gif_processing\%%d.jpg -filter_complex fps=5,scale=480:-2:flags=lanczos,split[o1][o2];[o1]palettegen[p];[o2]fifo[o3];[o3][p]paletteuse D:\BlueIris\Alert\out.gif

It works great on standard Linux ffmpeg builds, but it gave me an error under windows which when googled means you need to compile the ffmpeg to enable a certain option.

You can see side by side comparisons here at this linkā€¦

https://medium.com/@colten_jackson/doing-the-gif-thing-on-debian-82b9760a8483

Thanks!

I just gave it a quick test, but youā€™re right. The existing standalone binary doesnā€™t support these arguments. Got the following. When I get a chance later, iā€™ll look into either using a full install, pre-compiling another windows binary, or maybe just finding a nix machine to run it on.

No such filter: 'fps=5,scale=480:-2:flags=lanczos,split[o1][o2];[o1]palettegen[p];[o2]fifo[o3];[o3][p]paletteuse'
Error initializing complex filters.
Invalid argument

@roy_liao
I just tested under windows with the default ffmpeg and it worked after removing the single quotes. Did not have a windows machine to test when I posted before. I edited my previous post to correct the format so worth giving it another bash.

I have released the updated ipcamera binding which can do this directly from a camera without BI by using the cameras RTSP or http feed directly.

1 Like

Right again! I tried it with no apostrophes and it works!

The image quality is definitely much better now (but yes, slightly slower as well). Iā€™m on mobile now, but will update the instructions above to reflect your suggestions. Thanks!

1 Like

Hi All
Has anyone had any recent issues sending HTTP commands to BI?

This rule runs fine, as I see the log entries but it fails to switch the profiles. If i run the HTTP command , copied from the rule into a browser it works just fine.

Any thoughts as to why that is so?

THanks

rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
        Item gPresenceSensors changed or
        Item vTimeOfDay changed
then
        if(vTimeOfDay.state == "DAY" && gPresenceSensors.state == ON){                                              // If we are home and its day time, turn
           sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=")
        logInfo("Blue Iris", "Selective motion recording ON because someone came home and its day")
}
        if(vTimeOfDay.state == "NIGHT" && gPresenceSensors.state == ON){                                            // If we are home and its night time, tu
           sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=")
        logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
        if(vTimeOfDay.state == "EVENING" && gPresenceSensors.state == ON){                                          // If we are home and its evening, turn
           sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=")
        logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
end

Hi everyone hoping for a tip

entering this command in my web browser changes the profile of blueiris sucessfully but i cant get it too change using openhab any ideas ?

rule "BlueIris Test"
when
        Item TestSwitch1 changed to ON
then
        sendHttpGetRequest("http://USER:PASS@192.168.0.8:81/admin?profile=0")
end

Http binding installed and working for other items I use

I have also tried the different version posted but that doesnā€™t change the profile blueiris is using either

sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=")

I followed the post for getting the motion status from the cameras works perfectly thanks for that although I had too use the rest api version

@dastrix80 did you work out what was wrong with the rule did you get it working again?

Change the rule, instead of

changed to ON

, use

received command ON

Hi @dastrix80 thanks for the reply

Still the same blueiris doesnā€™t change its profile

Am I right in assuming that you donā€™t need an item linked too the command it can just be triggered by a rule?

Did you manage too solve your problem you can now send commands too your BI server what version of BI are you running im running V5

Iā€™m using V4. Yes, you need an item called TestSwitch1

I know I need an item called test switch one :sweat_smile: lol its an item I created ages ago too easily fire test rules

I mean nothing linked too the http binding

Will put the http binding in debug mode see if I can see anything reported there might have too post on the BI forum see what they say

Maby itā€™s problem between the different versions :thinking: but it does work when using a browser just not when OH sends it using the HTTP binding

Iā€™m switching to a schedule, not a profile, and mine works very reliably. My openhab machine is trusted by the Blueiris instance so I donā€™t need to authenticate.

rule "Motion Sensor Armed"
    when
        Item Motion_Sensor_Arm changed to ON 
    then 
        sendHttpGetRequest("http://192.168.n.nn:81/admin?schedule=Vacation")
end 
2 Likes

Hi @Timothy_Ingle thanks for the reply

I will look into that now maby blue iris is dropping the connection maby it doesnā€™t trust openhab do you know where that setting is?

It wasnā€™t working because that was checked turning it off allows OH too control BI im not sure how i feel i think i have just made my BI setup less secure

Does anyone know how too receive the active profile from BI and display in OH?

Hi,

I have not used OH before. However you can use a command line tool to ask BI for information via http and BI Json Api. You can control BI as well this way. You have a few options here. I have written a Java command line tool on Github: https://github.com/jurek1oo/blueiriscmdj.
You can use the too as a command line or integrate it with Java app. I use it with my Raspberry PI 3, which controls BI.
Let me know if you need and help. Jurek