Page 1 of 1

Converting Security script to Python

PostPosted: Wed Oct 28, 2020 4:51 am
by macpro
I've been using an ancient version of the Security script for many years. And it looks like it is the last speedbump on my way to Indigo 7.4.

Basically I need to convert this to Python:

Code: Select all
using terms from application "IndigoServer"
   on receive security event of eventType with code devID
      bla bla bla
   end receive security event
end using terms from      


How can I do this?

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 7:09 am
by FlyingDiver
What's a security event?

Or, a better question is, what does this actually do? If you disable this script, what happens (or doesn't happen)?

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 7:24 am
by macpro
See https://wiki.indigodomo.com/doku.php?id=x10_security_events for some details.
Basically it allows a running AppleScript to respond to events from X10 Security devices, like door/window sensors.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 7:27 am
by FlyingDiver
Ok, so what's the answer to the second part of the question? What devices do you have that generate these events?

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 7:56 am
by macpro
X10 Security devices. Look door/window sensors, motion detectors etc..
They are not visible in Indigo as devices.

And when I disable that script, Indigo will no longer know if doors/windows are open or closed.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 8:54 am
by WagnerOne
I'm going to be in this same boat when I try to upgrade. I am still using that old Security Script too. I looked into switching to Switchboard a few times, but never got around to it.

I have upwards of 20 EagleEye/ActiveEye MS13A/MS16A X10 motion sensors in my system. I've been replacing them slowly with z-wave sensors, but the types I have and want more of (I'm looking at you Dome) all seem to be in short/no supply the past many months.

All my X10 motion/door/etc. sensors talk to Indigo via a dedicated W800RF32 interface.

I used to have some DS10A dry contact sensors talking to the W800 too, but I've retired all those at this point. I basically cut the leads off the dry contacts I was using and wired in a Z-Wave Ecolink door/window sensors.

Other cheap X10 sensors like the MS10A worked with that script too.

This setup has been bulletproof and working flawlessly for decades at this point. The X10 sensors are super small/discrete, battery operated via 2xAAA batteries and are indoor/outdoor. Most importantly they are very inexpensive. Why would I want to pay for a "multi" sensor that I never use anything more than the motion capabilities of for $40 each when I can get 3 of these old X10 motion sensors for $20.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 9:25 am
by FlyingDiver
Turns out there's an example plugin in the SDK that shows how to do this, sort of. Here's the relevant code:

Code: Select all

################################################################################
class Plugin(indigo.PluginBase):
   ########################################
   def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
      super(Plugin, self).__init__(pluginId, pluginDisplayName, pluginVersion, pluginPrefs)
      self.debug = True

   ########################################
   def startup(self):
      self.debugLog(u"startup called -- subscribing to all X10 and INSTEON commands")
      indigo.insteon.subscribeToIncoming()
      indigo.insteon.subscribeToOutgoing()
      indigo.x10.subscribeToIncoming()
      indigo.x10.subscribeToOutgoing()

   def shutdown(self):
      self.debugLog(u"shutdown called")

   ########################################
   def insteonCommandReceived(self, cmd):
      self.debugLog(u"insteonCommandReceived: \n" + str(cmd))

   def insteonCommandSent(self, cmd):
      self.debugLog(u"insteonCommandSent: \n" + str(cmd))

   ########################################
   def x10CommandReceived(self, cmd):
      self.debugLog(u"x10CommandReceived: \n" + str(cmd))

      if cmd.cmdType == "sec":   # or "x10" for power line commands
         if cmd.secCodeId == 6:
            if cmd.secFunc == "sensor alert (max delay)":
               indigo.server.log(u"SENSOR OPEN")
            elif cmd.secFunc == "sensor normal (max delay)":
               indigo.server.log(u"SENSOR CLOSED")

   def x10CommandSent(self, cmd):
      self.debugLog(u"x10CommandSent: \n" + str(cmd))



I don't know if the
Code: Select all
indigo.x10.subscribeToIncoming()
call can be made in an external (always running) script, or if it has to be a plugin.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 9:34 am
by macpro
Thanks. Will give that a go.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 9:50 am
by jay (support)
FlyingDiver wrote:
I don't know if the
Code: Select all
indigo.x10.subscribeToIncoming()
call can be made in an external (always running) script, or if it has to be a plugin.


It has to be a plugin.

The Switchboard is available on Benjamin's github repo. I think it still works but I've never personally used it.

Re: Converting Security script to Python

PostPosted: Wed Oct 28, 2020 1:07 pm
by macpro
I've found the Switchboard plugin (thanks to Jay) and it seems to do the trick.
Still figuring out how to configure everything, but it looks like a can use it to replace the old Security script.