SmartThings Community

Blue Iris camera trigger from smart things

I do something very similar but instead of trying to get smartthings and blueiris to work together I just use SightHound.com which has very good people detection with nearly no false alerts.

Are you using sighthound as a stand alone system or with Smartthings?

Mostly standalone, it does integrate with IFTTT and I’ve been experimenting with different scenarios where I’ve had it turn a light on via Smartthings if a person was detected loitering in one area for a certain period of time.

@Jbell - I have written a SmartApp that I think I could pretty quickly turn into something that would do what you’re after. Do you still need something like this?

edit: Nevermind, I had a few minutes to burn so I went and made something that might work. I don’t have Blue Iris setup, so I have no way to test this. It does however appear to send an HTTP GET formatted like the strong above.

Check it out and let me know if it works (if you still need it)

Luma, thank you so much for putting this together!! I’ve been trying to get this up and going for myself but cannot get it to work. Do you know how I would go about discovering exactly what http string is being sent by the app?
Again, thank you for your time & efforts!
Justyn

I’ve updated the code to offer some more detailed logging. Install with this new version, select your devices, open Live Logging, and trigger one or more of your contacts or motion sensors. You should see something like the following:

debug biRestCommand: admin%3Fcamera%3DFront1%26trigger%26user%3DUser%26pw%3Dpassword
debug biRawCommand: admin?camera=Front1&trigger&user=User&pw=password
debug biHost: 192.168.1.136:81
debug processed event motion from device Simulated Motion Sensor with value active and data {"microDeviceTile":{"type":"standard","icon":"st.motion.motion.active","backgroundColor":"#53a7c0"}}

Do the results look right to you in the log? If this still doesn’t work I might install Blue Iris if they have a demo version and try and get it working against the actual software on my end.

edit: I’ve gone and installed Blue Iris and I am seeing the same behavior. It is constructing the URL correctly but there’s something about how the Blue Iris webserver is handling it that is different than a browser. If I use Chrome to issue the command it triggers the camera. If I use cURL from the command line with the same URL, it doesn’t.

This is probably going to involve some Wiresharking.

Sound like you’re making some great progress. Much appreciated!

1 Like

OK man, I think I have this working correctly. I had the HTTP request a little out of compliance which worked with my test web server but wouldn’t work with Blue Iris. A little time with Wireshark got to the bottom of this pretty quickly.

I order for this to work you will need to disable authentication on the Blue Iris web server. In Blue Iris settings > Web Server > Advanced > Authentication select “Non-LAN only” (preferred) or “No” to disable authentication altogether.

I’ve updated the master on Github, so try the 0.0.3 version and let me know how it goes.

2 Likes

Luma, You did it, it works like it should. Thanks so much for your time and effort! This is exactly what I needed!!

1 Like

There’s actually a story here behind all of this. I’ve been looking for a way to trigger a motion sensor in ST from an outside application, essentially the exact opposite of what you’re trying to accomplish. I had been searching for ideas of how to handle this without success for weeks. I just started a nearly month-long vacation and was gearing myself up to dig into ST enough to finally sort that out. It was during this search that I ran into your post. Coming up empty-handed (once again), I decided to take a stab at your request just to take my mind off of my own project.

After I created the first version of the application, I happened to click on the SmartApp Ideas forum and saw your other post on this topic which I clicked just out of idle interest. That led me to this post from @Kristopher that met my own needs exactly. Like, had I actually written out a design document, this SmartApp would have met every single requirement.

So, in a very real way, writing this app for you allowed me to finally find the app that I needed myself. It’s not too often that Karma pays off that quickly :smiley:

2 Likes

@luma,

Is there any way to modify this to send a PTZ preset? For example, I have a PTZ camera in between room1 and room2, if the motion sensor in room2 senses motion, have it send a https://outside.server.name/cam/shortname/pos=8:8443 (7+1 for the first preset, 1-7 are used for short movements). If an outside door contact sensor is opened in room1, then send a https://outside.server.name/cam/shortname/pos=9:8443.

Are you currently having smartthings send directly to the server internally, so it would only need the local name and port and no authentication?

This is connecting to the Blue Iris server locally, so the hub will contact your local BI server directly. My Blue Iris trial has expired so I can’t test this myself at this point. However, if you take a look at the code around line 82 you’ll see something like this: def biRawCommand = "/admin?camera=${settings.biCamera}&trigger&user=${settings.biUser}&pw=${settings.biPass}"

This is creating that URL command that will be sent to the BI server you define in the app settings. Specifically, it creates the string “/admin?camera=Camera1&trigger&user=admin&pw=password” where “Camera1”, “admin”, and “password” are values defined when you installed the app. If you take a look at the code you can see how this is assembled, using “${settings.biCamera}” to insert the camera name, and “${settings.biUser}”/"${settings.biPass}" are the username/password string.

You can modify the code yourself to create whatever kind of command string you want. Give it a shot, and if it doesn’t work post your result here and we can take a look at it.

Given that you suggested to make it so LAN does not authenticate (setting in BI), would it even need the username/password string?

Maybe? Modify the code to test it without the user/pass details and let us know what happens! Follow the logging for the application instance to see what it’s calling, the app is setup to print the URL it’s attempting to reach to the logs in a pretty readable manner.

Its sending this (showing it in the log):
9:18:09 AM: debug sending GET to URL http://host.domain.com:81/cam/CameraName/pos=9
but nothing happens (I changed the internal FQDN name and camera name in the string above from my actual ones).

If I copy and paste the exact url to my browser window, the PTZ preset works. I also tried using the IP address instead of the FQDN.

@luma, Blue Iris is logging the Anonymous (local) login from both smartthings hub and the pc that I’m testing from by going to the same url in a browser…

The trouble with using your browser to test these commands is that it saves cookies and authentication. Can you try with WGET or cURL?

@luma It worked via command line using wget. I had already tried using incognito, which worked as well. Blue Iris logged both connections as anonymous as expected.

@luma
I replaced: def biRawCommand = "cam/${settings.biCamera}/pos=${settings.biPreset}"
with
def biRawCommand = "cam/ShortCamName/pos=9"
to remove any possibility that my strings were messed up and ran it through the IDE simulator using a virtual motion. It logs into my BI server as anonymous (BI shows me the IP of the hub) when I tell the virtual motion to “see motion”, logging from the IDE shows:
4899d99c-7abe-4697-a409-55a999990b1c 1:53:58 PM: debug sending GET to URL http://192.168.1.100:81/cam/ShortCamName/pos=8
(I changed the ids, ips, and cam names on this post to fake ones)

Yet, it doesn’t work… could it be the httpMethod?

Below is how I’ve edited your script so far:

definition(
name: “Send a Preset to Blue Iris”,
namespace: “aderusha”,
author: “aderusha”,
description: “Trigger Blue Iris camera preset in response to SmartThings events”,
category: “Convenience”,
iconUrl: “https://raw.githubusercontent.com/aderusha/SmartThings/master/resources/BlueIris_logo.png”,
iconX2Url: “https://raw.githubusercontent.com/aderusha/SmartThings/master/resources/BlueIris_logo%402x.png
)

preferences {
section(“Blue Iris server details”){
input “biServer”, “text”, title: “Server”, description: “Blue Iris web server IP”, required: true
input “biPort”, “number”, title: “Port”, description: “Blue Iris web server port”, required: true
input “biPreset”, “number”, title: “Preset#”, description: “7+preset number”, required: true
}
section(“Blue Iris Camera Name”){
input “biCamera”, “text”, title: “Camera Name”, required: true
}
section(“Select events to be sent to Blue Iris”){
input “myMotion”, “capability.motionSensor”, title: “Motion Sensors”, required: false, multiple: true
input “myContact”, “capability.contactSensor”, title: “Contact Sensors”, required: false, multiple: true
}
}

def installed() {
log.debug "Installed with settings: ${settings}"
subscribeToEvents()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribeToEvents()
}

def subscribeToEvents() {
subscribe(myMotion, “motion”, eventHandlerBinary)
subscribe(myContact, “contact”, eventHandlerBinary)
}

def eventHandlerBinary(evt) {
if ((evt.value == “active”) || (evt.value == “open”)) {
log.debug "processed event ${evt.name} from device ${evt.displayName} with value ${evt.value} and data ${evt.data}"
def biHost = "${settings.biServer}:${settings.biPort}"
def biRawCommand = "cam/${settings.biCamera}/pos=${settings.biPreset}"
log.debug "sending GET to URL http://$biHost/$biRawCommand"
def httpMethod = "GET"
def httpRequest = [
method: httpMethod,
path: biRawCommand,
headers: [
HOST: biHost,
Accept: “/”,
]
]
def hubAction = new physicalgraph.device.HubAction(httpRequest)
sendHubCommand(hubAction)
}
}

@blazenmp From the code you’ve posted it looks like you might have been working on an earlier version of the code (0.0.1 or 0.0.2, neither of which worked). Specifically, the biRawCommand needs a leading “/” character which you’re missing (and I also had missing until 0.0.3). I’d strongly recommend checking the GitHub for the latest version (0.0.3) and working from that, as it was the first version to actually work.