Using Indigo to Toggle Sighthound Video Rules

Posted on
Sun Jan 17, 2016 12:02 am
simplyahobby offline
Posts: 6
Joined: Jan 05, 2016

Using Indigo to Toggle Sighthound Video Rules

I've been using Indigo and Sighthound video for several years. Enabling an "away" mode for Indigo has been easy using the Touch app but doing the same with Sighthound, to turn on or off certain rules, has not. The Sighthound app provides the ability to turn cameras on or off from my phone but not to enable or disable specific rules instead.

I have some cameras that are always recording but that have certain rules that are only enabled when I plan to be away, which trigger notifications. For some time I've have wanted to find a way to update away mode in Indigo that can also enable certain rules in Sighthound Video. Thanks to some work by others I've found a way to do exactly this in Indigo.

The groundwork can be found in this Sighthound Video forum post: Automation: Enabling cameras from the command-line

In order to setup Indigo to control rules for a camera you will need to know the full name of the rule that you want to control. You'll need to have remote access enabled and also be comfortable with including your username and password for Sighthound unencrypted in text files (shell scripts).

I'm using Indigo 6.1.4 running on Mac OS X 10.10.5. You'll need cURL but I found that it was included in my version of OS X.

In this post I'll be referring to a Kitchen Camera with a rule named "Vacation Away in Kitchen".

Outside of Indigo, in a path of your choosing, you'll be creating four files. Two of these are XML files and two are shell scripts. There is one of each file for turning the rule off and one for turning it on.

The first thing to do is to create the XML files.

<?xml version="1.0"?><methodCall>
<methodName>remoteEnableRule</methodName>
<params>
<param>
<value>
<string>Vacation Away in Kitchen</string>
</value>
</param>
<param>
<value>
<boolean>1</boolean>
</value>
</param>
</params>
</methodCall>


The only two values that you would change for your own needs should be bolded in the example above.

Next just create a copy of the first file and then change the boolean value from 1 to 0. A value of 1 will enable a rule and a value of 0 will disable a rule. It may be helpful to include ON or OFF in the filename of the appropriate file.

The next set of files will serve to run cURL and deliver the XML files to Sighthound. For this method they should have a ".sh" extension.

Here's the code from the script that I used to turn the rule on:

#!/bin/bash
curl --user username:password --header "Content-Type: application/xml" -X POST -d@/Users/username/Documents/Kitchen-Vacation-Away-ON.xml 'http://localhost:9000/xmlrpc/'


Note that "username:password" should be replaced with the username and password that you have configured for remote access in Sighthound. The path after "-d@" is for one of the XML files for toggling the rule. The use of "localhost" assumes that Sighthound is on the same system as Indigo. If you changed the default port make sure to change "9000" to match.

Note that both shell scripts need to be made executable, which can be done from the terminal in the same directory as the shell scripts. For example:

chmod +x away-kitchen-on.sh


At this point I recommend testing the scripts from the terminal to ensure that they will execute properly. From this point on everything else was done in Indigo.

In Indigo I first created a variable for storing the cameras state (camKitchenON), with false representing OFF and true representing ON.

Then I created an Action Group for each state of the camera (one for ON and one for OFF). In each Action Group I added only one action, which runs the corresponding shell script to turn the rule on or off.

Next, I created a Virtual Device named "Kitchen Camera". The Action Groups that I previously created are then used for the virtual devices "ON Group" and "OFF Group". In the configuration I enabled "Supports Status" and then chose camKitchenON as the "Status Variable".

Image

Once finished, I can now toggle the rule in Sighthound video.

Note that when executed the checkbox in the Sighthound GUI for the rule may not update until you click away from the camera and then back to it, though you will see the camera feed start if it was not enabled by another rule.

Also note that in this method I am not checking the status of the rule itself; simply sending a command. However, cURL will receive an XML response so I imagine that verifying the state is not a difficult task for someone with more scripting knowledge and time.

I have multiple cameras, all of which are setup so that I can toggle a rule from Indigo. I am only toggling rules from Indigo; not actually stopping or starting cameras in Sighthound though that is also certainly possible and can even be done with this information and what is provided in the Sighthound Video forum link included above.

Originally I had my away mode set as a Virtual Device that changed the state of multiple camera Virtual Devices but that did not work; perhaps I simply missed something minor or there is an issue with having one Virtual Device directly modify another one. To work around this I simply had the away mode Virtual Device execute the camera action groups instead of the camera Virtual Devices themselves though each camera still has its own Virtual Device so I can toggle the rules independent of a specific mode.

I hope others find this useful. I regret that I am unable to write a plugin to automate most of this (and add more features) but I have yet to find time even to simply learn Python.
Last edited by simplyahobby on Mon Jan 22, 2018 12:43 pm, edited 1 time in total.

Posted on
Sun Jan 17, 2016 9:22 am
jay (support) offline
Site Admin
User avatar
Posts: 16767
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Using Indigo to Toggle Sighthound Video Rules

Nice!

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 01, 2016 12:31 pm
RonA offline
Posts: 30
Joined: Aug 19, 2013

Re: Using Indigo to Toggle Sighthound Video Rules

I have been doing this for a few years now since Vitamin D, the method I use is python to talk to XMLRPC port, first finding out the current port (it has changed before) then making the connection and sending the commands (In my case Sighthound is running on the same Mac as Indigo). Not a programmer, so my script is most certainly amateur, but this is an example for turning off cameras, 0 is disable, 1 is enable. Same method can be used for rules:

>>>>>>>Camera Script
import xmlrpclib

file = open('/Users/sysadmin/Library/Application Support/Sighthound Video/port', 'r')
port1 = file.readlines()
port2 = str(port1[0:1])
port = ''.join([i for i in port2 if i.isdigit()])
proxy = xmlrpclib.ServerProxy("http://127.0.0.1:"+ port +"/")
proxy.enableCamera("IN FrontHall", 0)
proxy.enableCamera("IN Kitchen", 0)
proxy.enableCamera("IN LivingRoom", 0)

>>>>>>Rules Script
import xmlrpclib

file = open('/Users/sysadmin/Library/Application Support/Sighthound Video/port', 'r')
port1 = file.readlines()
port2 = str(port1[0:1])
port = ''.join([i for i in port2 if i.isdigit()])
proxy = xmlrpclib.ServerProxy("http://127.0.0.1:"+ port +"/")
proxy.enableRule("Back Garden PTZ Cam", 0)
proxy.enableRule("BackGardenNoAlerts3", 1)
proxy.enableRule("BackporchAlerts", 0)
proxy.enableRule("BackporchNOAlerts", 1)
proxy.enableRule("BackGardenDSAlerts", 0)
proxy.enableRule("BackGardenDSNoAlerts", 1)

Posted on
Mon Aug 29, 2016 4:06 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

Since Indigo is Python, Plugins are Python and Sighthound is written in Python.... I would think integration would be simpler.

https://www.sighthound.com/forums/topic12398

As for me, I have yet to write any python code.... just applescript. (I Haven't taken the plunge yet).

I think I will have to learn because I have been using applescript out of Sighthound to update variables.... but there is a bug in Indigo / OS X that causes the script to fail.

Has anyone attempted to write a plugin for Sighthound?

Bill
My Plugin: My People

Posted on
Mon Aug 29, 2016 4:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 16767
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Using Indigo to Toggle Sighthound Video Rules

FYI - Indigo (server, Mac client, iOS client) isn't Python. Plugins are however.

But just because something is implemented in the same language doesn't automatically mean that they can work better together. They are running as separate processes, so there has to be some way to communicate between those processes. Usually an API of some kind.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Aug 29, 2016 5:10 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

jay (support) wrote:
FYI - Indigo (server, Mac client, iOS client) isn't Python. Plugins are however..


Thank you Jay. I knew there was a reason I wanted to learn Python.... and I knew it was an Indigo reason. :-)

I wrote to Sighthound and begged for an API or assistance with a plugin. That didn't work, No API on the horizon. But they did say if I want to give the trial a shot again in the future, they will let me play with it some more.

@ simplyahobby & RonA . I like the work you guys have put into this. I like how you have gotten Indigo to talk to Sighthound. How do you have Sighthound talk back to Indigo?

I've done the "Run Command" thing which would execute an applescript .app to update a variable that a trigger would watch..... but that was causing a flareup of a bug (-600 error something, bla bla bla.). What was your solution?

Bill
My Plugin: My People

Posted on
Wed Aug 31, 2016 3:10 pm
RonA offline
Posts: 30
Joined: Aug 19, 2013

Re: Using Indigo to Toggle Sighthound Video Rules

I am using the run command also, example below to modify a variable to which I have additional triggers. I have seen no issues.

osascript -e 'tell application "indigoserver" to set value of variable "MovementinFrontGarden" to "true"'

Posted on
Wed Aug 31, 2016 4:17 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

RonA wrote:
osascript -e 'tell application "indigoserver" to set value of variable "MovementinFrontGarden" to "true"'


You just put that directly in the "Run Command" space in Sighthound? or is that saved as a script on your hard drive?

I didn't get an error, but I didn't get a change either...

Code: Select all
osascript -e 'tell application "indigoserver" to set value of variable "Sighthound" to "Hello"
^Using my variable.

Also tried substituting "osascript" with indigohost and followed the tutorial on http://wiki.indigodomo.com/doku.php?id=indigo_5_documentation:plugin_scripting_tutorial#executing_indigo_commands_directly

I'm missing something stupid somewhere.

Bill
My Plugin: My People

Posted on
Wed Aug 31, 2016 5:45 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

RonA,
Thank you for taking the time to help work on this with me and for PMing me on this for the past hour or so.

Unfortunately, my Mac is plagued with the dreaded "Application isn't running -600" bug. Sudo commands and restarts suck. Thankfully, Jay and Matt expanded the restful URL stuff and I think going that route should be trouble free for me.

This is verbatim what I'm using in the "Run the Command:" line in Sighthound

Code: Select all
curl http://10.0.6.10:8176/variables/Sighthound?_method=put&value=test


Where "Sighthound" is the name of the variable
Where "Test" gets substituted with "Camera_Rule"

triggers and stuff in indigo do the rest of the work.

Bill
My Plugin: My People

Posted on
Thu Sep 01, 2016 12:49 am
RonA offline
Posts: 30
Joined: Aug 19, 2013

Re: Using Indigo to Toggle Sighthound Video Rules

Seems like a good solution, I didn't think of that.


Sent from my iPhone using Tapatalk

Posted on
Sun May 26, 2019 10:40 pm
simplyahobby offline
Posts: 6
Joined: Jan 05, 2016

Re: Using Indigo to Toggle Sighthound Video Rules

I've been setting all of this back up again and there's one important change that I encountered. In more recent versions of Sighthound Video, since I initially posted this, they've switched to using SSL. It's a good change but prevents the above solution from working. To continue using curl for this part you'll need to change the URL to use https, instead of http, and to add the --insecure or -k option to handle the certificate warning.

Posted on
Fri Sep 27, 2019 6:58 pm
hamw offline
Posts: 1213
Joined: Mar 31, 2008

Re: Using Indigo to Toggle Sighthound Video Rules

I also have Sighthound, running on a different computer from Indigo. Would it be possible to use IFTTT or some other LAN comm to send “people detected” “vehicles detected” or other rules-based notifications from Sighthound to my Indigo Mac to trigger and execute an automated picture grab and send? The picture grab and send is already set up and currently I use triggers that are based on unreliable motion detectors. So lots of false alarms.

Posted on
Fri Sep 27, 2019 7:30 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

I think so.... I'm using a different sort of work around to bridge CCTV tech (2 NVRs) and Indigo via the SMTPd Plugin. It took a little tinkering to figure it out... but it's now pretty solid.
viewtopic.php?f=216&t=16348

It basically sets up an SMTP server on your Indigo MAC. You use the credentials for that server in Sighthound for when it sends an email based on whatever rule (person, object, unknown, etc.).

The email doesn't actually go or get stored anywhere... it just gets reviewed by the SMTP plugin for triggers.


The rest of the setup.
Devices:
I set up a timer for each SMTP Camera. The initial time is how long the timer will run (indicating that motion was detected)

Variables:
I set up a variable for each SMTP Camera. "SMTP_CameraName_Motion" Triggers update the status.


Triggers:
CameraName - SMTP Message received (Condition VMD Variable On, SMTP Message to = CameraName) Action = Restart timer, set variable to True

CameraName - Motion Timer End (Timer expired) Action = set variable to False


Other tidbits. I set up my cameras and detection types with rules... so outside detection, inside detection and video motion detection (VMD). Those are all virtual devices. So my camera actions look at a conditions list... if outside is on, but VMD is off, then only triggers based on actual motion detectors or doors etc will fire things off. If I flip on the VMD switch, then that will increase my notifications.

To avoid having low priority events trump high priority.... (Like someone rings the doorbell... that can quickly be trumped by kids and dogs scurrying around the house).... so I've assigned priorities to triggers with timers. So, outside motion is Priority 3 which sets a variable and a priority timer so for the next 5 minutes, any lower priority event is ignored. (Inside motion is Priority 4... 2 is access control devices and 1 is the DCS alarm and 5 is weather. - When the priority timer expires, a trigger changes the priority variable back to 5. So a inside motion event (priority 4) would have a condition.... if Priority is greater than 3.

I hope this helps or gets you going in a good direction.

Bill
My Plugin: My People

Posted on
Sat Sep 28, 2019 8:52 am
hamw offline
Posts: 1213
Joined: Mar 31, 2008

Re: Using Indigo to Toggle Sighthound Video Rules

whmoorejr: I'm using sighthound, as you are. An advantage of SH is that it has rules based detection, and now can identify vehicles, people, animals, etc. Does your solution use the SH rules with email sent from SH to Indigo via the plugin, or are you just using the built in motion detection in the cameras?

Posted on
Sat Sep 28, 2019 3:20 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Using Indigo to Toggle Sighthound Video Rules

Currently I'm just using the motion detection in the cameras and in the NVR to trigger indigo via email. Since it is an internal email thing... it's instant.

I moved away from Sighthound mostly because I moved all CCTV video processing off of my computer.

I was curious about how you want to implement this, so I tried it on my end but I received an authentication error from the sighthound application when trying to send test emails using the SMTPd plugin. To get this working properly with Sighthound, you may have to ping FlyingDiver (Dude that wrote the SMTPd plugin.). He's very responsive and helped tweak the plugin to get it working for me with my Amcrest cameras.

If I were to go back to using Sighthound, this is the route I would go to implement it into Indigo. Sighthound lets you customize the email to and Subject line for each rule, then you can set up SMTPd triggers based on the either the email to, email from, subject or message.

The downside is that you have to change your global email setting to use the SMTP server as your outgoing email server.... so you can only use email from that point forward for triggering SMTPd plugin stuff, not to send actual emails.

Bill
My Plugin: My People

Who is online

Users browsing this forum: No registered users and 2 guests

cron