Triggering cameras from the command line using Python

General discussion about Blue Iris
Post Reply
adr14n
Posts: 2
Joined: Tue Mar 08, 2022 12:27 am

Triggering cameras from the command line using Python

Post by adr14n »

I spent several hours this evening trying to work out how to trigger a camera in Blue Iris from the command line without:
- reducing security for web access authentication
- sending passwords in URLs
- hard-coding any passwords in clear text in scripts

The only method I could find which met all 3 above requirements is using DDE. However there's not exactly a lot of documentation for how to do it. So after lots of trial and error, I came up with the following Python script which I can use to trigger one of my cameras.

Please feel free to comment on this - eg is there a better way. And please feel free to share it (if it's any good!).

Code: Select all

# BEWARE: This needs to be executed as administrator - eg from a command window run as administrator
#         or via a shortcut which runs as administrator, or invoked from an elevated program.
#
# I ran this from a 64-bit Python install. I don't know whether 32-bit will work or not given
# Blue Iris 5 is a 64-bit executable.
#
# From page 242 of the Blue Iris V5 manual...
#     DDE INTERFACE
#     A technology that is largely deprecated, yet a part of Blue Iris. A DDE service name BlueIris
#     is created to listen for commands:
#    
#     topic         item            data                function
#     global        signal          0, 1, or 2          set the shield icon to red, green, or yellow
#     camera        (shortname)     ptzpreset=x         move to PTZ preset position x
#                                   trigger             trigger the camera
#                                   snapshot            single snapshot to the database
#                                   record              toggle manual recording
#                                   recstart            start manual recording
#                                   recstop             stop manual recording
#                                   reset               reset camera
#                                   enable              enable camera
#                                   disable             disable camera
#                                   schedule=1 or 0     enable or disable camera schedule override
#                                   profile=x           temporarily set camera override profile
#     macro         1-999           (text)              set macro number to specified text

# To instal win32ui and dde:
#     pip install -U pypiwin32
import win32ui
import dde
import warnings

# Disable warning about: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
warnings.filterwarnings("ignore", category=DeprecationWarning) 

# We're running as a client, but we still create a server object.
# This is a PyDDEServer: http://timgolden.me.uk/pywin32-docs/PyDDEServer.html
server = dde.CreateServer()

# I don't think the name matters.
server.Create("BlueIrisClient")  

# This is a PyDDEConv: http://timgolden.me.uk/pywin32-docs/PyDDEConv.html
conversation = dde.CreateConversation(server)

# As documented above:
#     "BlueIris" is the service name.
#     "camera" is the topic we need to trigger a camera.
conversation.ConnectTo("BlueIris", "camera")

if not conversation.Connected() == 1:
    print("Connection failed")
    sys.exit(1)
    
print("Connection established")

# The camera name is the short name from its settings
camera = "Porch" # or "Driveway" or "Garden"

# Send the "trigger" command to the camera.
conversation.Poke(camera, "trigger")
print("Trigger command executed")

# Not sure whether these are needed, but probably best to be safe.
server.Shutdown()
server.Destroy()

print("Done.")
User avatar
YrbkMgr
Posts: 587
Joined: Sun Nov 24, 2019 12:56 am
Location: Chicagoland

Re: Triggering cameras from the command line using Python

Post by YrbkMgr »

That's a "nifty bit 'o kit" as they say. What's the use case? What problem were you trying to solve by using Python to trigger the camera?
  • "Whenever I take something apart to fix it and put it back together again, I end up with like six really important looking pieces left over" -Tim Allen
  • If you know what your after, you'll recognize it when you see it.
adr14n
Posts: 2
Joined: Tue Mar 08, 2022 12:27 am

Re: Triggering cameras from the command line using Python

Post by adr14n »

To answer YrbkMgr's question...

I want to see whether I can get an external IR motion sensor to trigger my cameras to reduce false positives. In particular, I understand some IR detectors are good at identifying people instead of inanimate objects, small pets, moving shadows, reflections off puddles, neighbours' security lights etc. Maybe I can do better with tweaking BI's motion settings, but I thought this worth a try too.

My first step was to see whether I can trigger BI with a script, as that will give me max freedom about what IR sensors I buy.

I've not got as far as investigating which sensors to purchase yet - that's for next weekend.
User avatar
YrbkMgr
Posts: 587
Joined: Sun Nov 24, 2019 12:56 am
Location: Chicagoland

Re: Triggering cameras from the command line using Python

Post by YrbkMgr »

Interesting project. I'm interested in how that works out and so if you're inclined to update us, that would be great
  • "Whenever I take something apart to fix it and put it back together again, I end up with like six really important looking pieces left over" -Tim Allen
  • If you know what your after, you'll recognize it when you see it.
MikeLud
Posts: 85
Joined: Sun Mar 21, 2021 3:29 am

Re: Triggering cameras from the command line using Python

Post by MikeLud »

adr14n wrote: Thu Mar 10, 2022 12:13 pm To answer YrbkMgr's question...

I want to see whether I can get an external IR motion sensor to trigger my cameras to reduce false positives. In particular, I understand some IR detectors are good at identifying people instead of inanimate objects, small pets, moving shadows, reflections off puddles, neighbours' security lights etc. Maybe I can do better with tweaking BI's motion settings, but I thought this worth a try too.

My first step was to see whether I can trigger BI with a script, as that will give me max freedom about what IR sensors I buy.

I've not got as far as investigating which sensors to purchase yet - that's for next weekend.
You can use the code in the below link. You need to change the line that send the JSON cliplist command to trigger command.

https://blueirissoftware.com/forum/view ... 1298#p5021
.
Screenshot 2022-03-10 211618.jpg
Screenshot 2022-03-10 211618.jpg (190.74 KiB) Viewed 1824 times
Post Reply