Blue Iris integration- HTTP binding, REST api

Thanks Rob! This would also mean all motion detection is off when the signal is 0. This would mean whilst I’m home, it wouldnt record any motion as the signal is red

Ill think about this a bit more . Thanks for the nice suggestion!

I have two profiles set up. 1 for home, 2 for away.

sendHttpGetRequest("http://192.168.1.xx:8585/admin?profile=1&user=xxxx&pw=xxxx")

This is how I force the change between my profiles.

Hi Paul,

Cool. I’ve created a rule to just disable motion when I’m home , using an existing gPresenceSensors group and also the vTimeOfDay. If its Day, and we are home, motion recording is switched off in Blue Iris.

If its anything else, ie: its night/evening and we are home, it will record as my IF condition is &&.

EDIT: Actually… thinking about this, that’s not going to work.

I still want certain cameras to be recording. Doh!!

Cool, yeah just set blue iris up so that its always recording (in the main settings for BI set up the Schedule page based on your Profiles). This will set up when it’s recording. You’ll want both Profiles to always be recording.

Then in each camera’s Properties you’ll want to set up the Alert settings for each different Profile. No alerts when in the Home profile, alert when Away. This way it’ll always record when home, but never alert.

1 Like

OK, so this is what I’ve done.

When either my partner or I are home (indicated by gPresenceSensors being ON) and the vTimeOfDay is Day, then this will disable Motion Recording on the inside and rear yard cameras. The rest of the cameras will still record (ones that monitor my gates, doors and rear lane)

Otherwise, all cameras are recording.

Here is some motion alerts which alert us at night time if the Carport or Garage are triggered:


rule "Blue Iris Motion Detection Alert - Garage"
when
    Item Motion_Garage received command
then
     if(Kris_MobileAP.state != "Garage" || Jodie_MobileAP.state != "Garage"){
         logInfo("Blue Iris", "There is motion in the Garage")
           Echo_Living_Room_TTS.sendCommand('There is motion in the Garage')
           Echo_Garage_TTS.sendCommand('The police have been called')
        sendBroadcastNotification("There is motion in the Garage")
}
end

rule "Blue Iris Motion Detection Alert - Carport"
when
    Item Motion_Carport received command
then
    if(Kris_MobileAP.state != "Garage" || Jodie_MobileAP.state != "Garage"){
     logInfo("Blue Iris", "There is motion in the Carport")
       Echo_Living_Room_TTS.sendCommand('There is motion in the Carport')
       Echo_Garage_TTS.sendCommand('The police have been called')
    sendBroadcastNotification("There is motion in the Carport")
}
end

And this is the one that enables/disables motion but its not working lol! The HTTP commands execute just find if I use a browser


rule "Turn off Blue Iris Motion Recording when we are Home"
when
        Item gPresenceSensors changed
then
        if(gPresenceSensors.state == ON && vTimeOfDay.state == "DAY"){   // If we are home and its day time, turn off Motion Recording
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=RearYard&motion=0&user=Kris&pw=XXXX")       // Disable Motion Recording in Rear Yard
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=LivingRoom&motion=0&user=Kris&pw=XXXX")     // Disable Motion Recording in Living Room
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=Alfresco&motion=0&user=Kris&pw=XXXX")       // Disable Motion Recording in Alfresco
        logInfo("Blue Iris", "Selective motion recording OFF because someone came home and its day")
}
        if(gPresenceSensors.state == ON && vTimeOfDay.state == "NIGHT"){   // If we are home and its night time, turn on Motion Recording
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=RearYard&motion=1&user=Kris&pw=XXXX")       // Enable Motion Recording in Rear Yard
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=LivingRoom&motion=1&user=Kris&pw=XXXX")     // Enable Motion Recording in Living Room
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=Alfresco&motion=1&user=Kris&pw=XXXX")       // Enable Motion Recording in Alfresco
        logInfo("Blue Iris", "It's night time so all motion recording ON")
}
        else (gPresenceSensors.state == OFF){
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=RearYard&motion=1&user=Kris&pw=XXXX")       // Enable Motion Recording in Rear Yard
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=LivingRoom&motion=1&user=Kris&pw=XXXX")     // Enable Motion Recording in Living Room
           sendHttpGetRequest("http://192.168.0.4:82/admin?camera=Alfresco&motion=1&user=Kris&pw=XXXX")       // Enable Motion Recording in Alfresco
        logInfo("Blue Iris", "Motion recording ON as no one is home")
}
end



It’s been a while since I’ve visited this thread, but wanted to share some updates on Blue Iris + openHAB integration.

I’ve been using BI’s motion detection + a separate hardware PIR to sense and confirm if someone is at the door. If there is, OH will send notifications through pushover. Pushover recently announced GIF support, so with some hacking, I’ve managed to adjust this to send an animated GIF of the recorded activity and include it in the notification.

Since it ties in a lot of different things (Blue Iris, FFMPEG, Pushover, OH2) the process is pretty hackish, but if anyone is interested, I can do a writeup.

Some sample images:

Converted GIF sample:
out

Pushover notification on phone (this is shown as animated GIF):

Linked live view:

2 Likes

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…

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