Condition: If Device has been off for at least 1 minute

Posted on
Sat Jun 29, 2013 8:19 pm
boonebytes offline
Posts: 3
Joined: Jun 29, 2013
Location: St. John's, NL, Canada

Condition: If Device has been off for at least 1 minute

Hi,

I'm currently evaluating Indigo as a possible replacement for the product I'm currently using on my Windows PC (HomeSeer). I have a trial installed and working; everything is looking good so far.

I'm using a WGL W800USB for X10 EagleEye motion/darkness sensors, door sensors, and a panic button. I'm also using a Z-Troller to control all my Z-Wave devices (mostly light dimmers, plus a fan switch and two plug-in Smart-Switches). I'm living in a rented basement apartment, so I can't make structure changes (ie. drill holes / run wires to put the W800 antenna in an optimal position). Both computer modules are located on my computer desk, along with my tower PC, Mac Mini, Time Capsule (acting as wireless base station), router, printer, etc.

I have motion sensors in each room that (in HomeSeer) turn the light on as soon as it detects motion. Due to the chance of missing the only OFF signal sent from my EagleEye motion sensors, it currently responds to the "M[1,3,5...] ON" command, not the "device status changed" event. To work around a problem where the light would turn itself on as I left a room (after I turned it off manually), I put a condition on the "Turn light on" events. Basically, the light will only turn on if it has been off for at least a minute.

My question: How can I configure Indigo to only turn on a light only if that light has been off for more than a minute...or is this possible? Also, is there a alternate way for me to be doing this?

In case it helps: I'm a technical user comfortable working in the Terminal app, and I program PCs and websites for a living. I haven't done much AppleScript programming yet, but it seems quite simple to work with.

Thanks in advance!

Jeff

Posted on
Sun Jun 30, 2013 8:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18229
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Condition: If Device has been off for at least 1 minute

Welcome to the Indigo and the forums.

Let me restate the problem just to make sure I have it right. You want a motion sensor to turn on/off a light. You have a trigger that turns on the light when it gets the ON command. You don't want the light to turn on again after you manually turn it off. Right?

A couple questions:

  1. I assume you have corresponding trigger that turns off the light when it sees an OFF command - and the pair of triggers is used rather than device state changes because sometimes the OFF command is lost. Is that right?
  2. Many X10 motion sensors just send repeated ON commands while it's detecting motion. Indigo can be configured to use this fact to control the on device state of the motion sensor - after N minutes from the last ON we'll set the device state to off. If you can configure the EagleEye to work that way then that may be your easiest solution. In this case it wouldn't matter whether one of the ON commands gets lost (like your OFF command sometimes does) because the next one probably wouldn't.

Ok - assuming I have the scenario right and you can't change the behavior of the EagleEye, let's get back to the question of how can you track how long a light's been off. There are a bunch of different ways to do this - many without any scripts and one with a script.

Because we don't yet expose the "last updated" of a device as a device state (we probably will some day), the solution isn't as simple as using that in the condition. Being a programmer, I'd just write a little Python script as the action that would first check to see if the last updated from the light was older than a minute and the light was off - if those are true then turn the light on. I added this little script to the scripting tutorial since it's a simple example of how to use the device's lastChanged property. BTW, if you don't already know AppleScript then I highly recommend that you learn Python instead. It's our primary scripting language moving forward (AppleScript is legacy). If you already know a language with C-like syntax then Python is a cinch.

The non-scripting way of doing it, in rough terms, would be to add a couple more triggers and a variable: the variable would be true if the light can be turned on (it's over a minute since it was last turned off) or false otherwise. You would set the variable to "true" whenever the light went OFF and add a delay of 1 minute to the action. You would then set the variable to "false" when the light goes on and cancel any delayed actions for the light (so if you quickly toggled the light it wouldn't set the variable). You would then use that variable in the condition to your motion trigger. It's more moving parts, but no scripting required.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 30, 2013 4:53 pm
boonebytes offline
Posts: 3
Joined: Jun 29, 2013
Location: St. John's, NL, Canada

Re: Condition: If Device has been off for at least 1 minute

Hi Jay,

We're almost on the same page... close enough that your advice is "dead-on" for what I was trying to accomplish! :)

My goal is to avoid a "race-condition": If I manually turn off the light switch on the way out of a room, the light should tell Indigo that it has turned off. Then, as I start moving to leave the room, the motion sensor will tell Indigo that it has sensed motion. With an "M1 ON" trigger, this would turn the light back on, unless Indigo recognizes that I'm on the way out of the room.

My EagleEyes work the way you have described: They send the ON command repeatedly, but only one OFF command. When the first ON command isn't received, it's a minor inconvinence, but it's only another few seconds before it sends the ON command again.

I like the script approach and example you mentioned. It looks a lot easier to manage/debug than the trigger-based alternative. I haven't used Python yet, but I had a brief glance at its syntax. It looks relatively straight-forward, perhaps even easier for me than AppleScript. I mainly work in PHP/VB/VB.NET, with a little bit of C# (if that even counts, of course :)).

As I have 5 different sensors, is there a way to do this as a function and just pass the target device's identifier as a parameter? If not, it's no big deal; just thinking of my OCD with programming :)

Thanks again,

Jeff

Posted on
Sun Jun 30, 2013 5:32 pm
jay (support) offline
Site Admin
User avatar
Posts: 18229
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Condition: If Device has been off for at least 1 minute

Definitely - just define it as a Python method in a file in the standard Python library path. See this section of the scripting tutorial for details.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 01, 2013 12:40 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Condition: If Device has been off for at least 1 minute

boonebytes wrote:
I haven't used Python yet, but I had a brief glance at its syntax. It looks relatively straight-forward, perhaps even easier for me than AppleScript.

Before Indigo 5, I didn't know any Python but had enough PHP, shell, and AppleScript experience to be dangerous. Having now released a number of Indigo plugins (which are all written in Python), I can vouch for the ease of picking up the Python syntax and learning the Indigo Object Model conventions. It's still useful to know some AppleScript for use in more complex trigger condition scripting (Indigo currently only supports AppleScript if you want to write a script as a trigger condition), but Python is more powerful for most other scripting needs. The advantage of Indigo supporting both AppleScript and Python is that you can use Python for a broad range of software and device integration and AppleScript for Mac OS X application scripting integration. Many Mac OS X applications include their own AppleScript "dictionaries" (as does Indigo), so you can use Indigo to automate other Mac OS X apps using AppleScript.

Posted on
Mon Jul 01, 2013 10:11 am
jay (support) offline
Site Admin
User avatar
Posts: 18229
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Condition: If Device has been off for at least 1 minute

And you can also use Python scripts as conditions, just not on the conditions tab.

How?

Add all the actions you want to execute into an Action Group rather than directly on the trigger/schedule. Then, have the action on the trigger be a Python script that performs the conditional logic and if it passes then execute the action group. It's not exactly the same as using Conditions (the trigger/schedule will show as executing in the event log every time) but for all practical purposes it's the same.

At some point we'll add Python conditions - but it's going to require more work than we can afford for the foreseeable future particularly when there's a pretty straight-forward workaround available.

AppleScript, IMO, is really only useful when you need to integrate some other Mac app. Appscript, which allows you to talk to scriptable apps in Python, is pretty difficult to explore/use effectively (thought it does work - the Airfoil plugin uses it). If I'm doing something custom along those lines I'll write it in AppleScript. But I find that's happening a LOT less in the last several years.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 01, 2013 6:42 pm
boonebytes offline
Posts: 3
Joined: Jun 29, 2013
Location: St. John's, NL, Canada

Re: Condition: If Device has been off for at least 1 minute

Awesome, thanks guys!

FYI: I have my automation equipment connected to my Mac, and I'll see how it handles full-time :)

I managed to get the motion sensors working with a Python function I wrote... It's really not hard at all, once you know what you're doing! I think the hardest stumbling block I hit was trying to concatenate a string and an integer to log the delta-seconds (for debugging); and that solution was just a call to the str() function.

It took me a second to find the option to let Indigo turn off the device when it stops receiving ON commands for x minutes, but it was pretty clear when I found it. :)

I downloaded Switchboard for my door sensor. Took me a second to realize that "The Device Is On - Becomes True" means that the door has opened, but that's nothing.

I've hit a new issue now... my KR15A panic button's X10 Security trigger (what happens when I hold it down until the light is on steady; supposed to "panic" the security system) seems to be "glitching". I'm getting the error "Illegal security code byte 03". It's a different issue, so I'll probably just start a new thread when I have a moment tomorrow afternoon :)

Thanks again for all your help!

Jeff

Posted on
Mon Jul 01, 2013 7:05 pm
jay (support) offline
Site Admin
User avatar
Posts: 18229
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Condition: If Device has been off for at least 1 minute

Always glad to help users get the most out of Indigo.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest