X10 with Applescript & Indigo

Posted on
Tue Jul 17, 2007 2:09 pm
NebENG offline
Posts: 3
Joined: Jul 16, 2007
Location: Omaha, NE

X10 with Applescript & Indigo

I'm going to try and make this as clear as possible, but I'm new with the terminology in regards to Indigo/Applescript, so bear with me.

In an office space, I have a basic setup using motion sensors and Indigo to control the lighting in this space. But now I want to try something using an X10 wireless remote pad with basic on/off switches. Here's the situation:

Pretend I am occupying this office with the motion sensors controlling the lights, and I want to optimize the amount of time that the lights are on and there's no one in the room. Say I have the time delay on the countdown in Indigo (next action in:) set to 5 minutes. I want the occupant of the office to be able to hit the ON button on this keypad, and when they do that, the time delay countdown will reset and the lights will come back on. AND on top of that, reset the time delay at an increment of thirty seconds.

So hypothetically, the lights turn off on me while I'm sitting still for too long, I hit the key pad and they come back on and the time delay automatically adjusts to 5 minutes and 30 seconds. If I hit it again, it will reset to 6 minutes, and so on.

A couple other things I'd like it to do:
-Have a ceiling of ten minutes for the time delay
-neglect a rapid succession of button presses (if the occupant gets frustrated and hits the button 20 times in a row, only account for the 1st 3)
-After 2 weeks, the delay gradually comes down from the ceiling in 10 second increments every day (or week) (ex: after 2 weeks, the time delay drops to 00:05:50, after another week it goes to 00:05:40, and so on)


I feel that all of these things are possible from my observations the past couple of weeks, but my skills and knowledge of Indigo and Applescript aren't up to par to make this happen. I've gathered some insight by reading some other threads on this site, I just can't seem to make it all come together. I know a lot of the basic stuff in Indigo especially, but I lack in the programming ability with Applescript.

Can anyone give me some insight or coding tips? And if you could, speak simply? I would GREATLY appreciate it.

Sincerely,

Kevin

Posted on
Wed Jul 25, 2007 8:31 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: X10 with Applescript & Indigo

Hello Kevin,

Welcome to the group!

I think what you want to do should be possible to accomplish via AppleScript and Indigo. That said, it will be more than just a couple of lines of AppleScript which may be why no one has jumped forward with a solution yet. :-)

Why don't you take it one piece at a time and give it a try with AppleScript and post your results? I think folks will be able to guide you to the correct solution more easily if it the goal is broken down into smaller problems and we see what you have tried first.

Regards,
Matt

Posted on
Wed Jul 25, 2007 11:49 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

You can start by taking a look at my timer solution for Indigo.
It will give you the foundation for your requirements and enhancing it in Indigo will be easy.

I'm using my timer solution at home to make sure lights don't stay on to long. It works by resetting a timer every time motion is detected. So as long as there is movement, the timer will never reach zero.
And yes, it supports your hypothetical situation! :wink:

Posted on
Tue Jul 31, 2007 1:13 pm
NebENG offline
Posts: 3
Joined: Jul 16, 2007
Location: Omaha, NE

(No subject)

I appreciate the guidance with your previous solution. I have a quick question though.

Before I started trying to solve this dynamic reset problem, I was already using Indigo to do, pretty much exactly what you created your timer solution for. I set up trigger actions to fire when the motion sensors detected motion, via they would broadcast their X10 signal which would set into motion a trigger action that would turn the lights on. Also, I would enact the "auto-off after" to 5 minutes. Hence, everytime motion is detected, the auto-off countdown would reset to 5 minutes. So I have no problem setting this up in Indigo.

Now, when I examined your solution, I became very confused. It seems as though you're trying to take that "auto-off" countdown sequence and break it down into simpler steps using applescript, thus making it more versatile and easier to manipulate (which is exactly what I need). So here's my question.

You somewhat skipped over your setup steps in Indigo that accompany the applescript code. I could really use some elaboration on those first steps where you created all those triggers and action groups, just some of the simple details.

My problem comes because when just using Indigo, it's a little easier to get all the actions and triggers to correlate, because that's what it's set up to do. But now trying to analyze your Applescript implementation, and get everything to tie together, I'm struggling because of my inexperience with the software.

Any detail and elaboration would be much appreciated!

Sincerely,

Kevin

Posted on
Wed Aug 01, 2007 11:28 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

No problem. I've added some extra info to the timers topic.
You can read it here.

Posted on
Wed Aug 08, 2007 2:00 pm
NebENG offline
Posts: 3
Joined: Jul 16, 2007
Location: Omaha, NE

(No subject)

I just had a break through yesterday! I got your timer solution to work, and all I had it doing in Indigo is turning on/off a hypothetical desk lamp. This way I could examine what exactly it was doing.

Then, I was using an X-10 remote keypad with simple ON and OFF buttons to dynamically reset the Timer variable I had created in Indigo (the same Timer I had the motion sensors resetting as well) to increase it by 30 seconds every time the ON button was pressed. The problem was this: the motion sensors in combination with your timer solution could only reset the timer value to the SAME NUMBER every time motion was sensed. But I wanted the occupant in the room to be able to use this X-10 keypad to INCREMENT the timer value, and have it stay at that value even with motion still going on in the room, every time the ON button was pressed. So here's what I did:

I created another variable in Indigo called "BaseTime", and used the following code:
-Here's what applescript would fire when motion was detected by one of the three sensors:
Code: Select all
tell application "IndigoServer"
   set (value of variable "Timer") to (value of variable "BaseTime")
end tell

This would reset the Timer variable to whatever the BaseTime was set to.

-Then, if the occupant wanted to increase that Timer value, they could press the remote pad and the following applescript would fire:
Code: Select all
tell application "IndigoServer"
   if (value of variable "BaseTime") < 600 then
      set Y to (value of variable "BaseTime")
      set Y to Y + 30
      set (value of variable "BaseTime") to Y
      
      set X to (value of variable "BaseTime")
      set (value of variable "Timer") to X
   end if
   
   log "This is the new incremented BaseTime (in seconds)"
   log Y
end tell


I set a ceiling at 10 minutes(600 seconds) for my own reasons, but all in all, this code retrieves the value of BaseTime, then increments it by 30 seconds, and resets the Timer variable to the new BaseTime. All the while, your background task timer code is counting down the value of the variable Timer. And of course, there's a trigger for when "Timer" reaches zero which turns OFF the lights.

What's the whole point you ask? To optimize the amount of time that the lights are on in a room and NO ONE is in the room, but for a particular individual.

Thanks again for the timer code! I wouldn't have been able to accomplish this without it![/code]

Sincerely,

Kevin

Posted on
Wed Aug 08, 2007 2:20 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

Glad I could help. And good to see that you are using your own creativity to enhance the timer solution to your own situation.
That is what I like about Indigo and what makes it so powerful and flexible.

By the way: there's an error in your script. I think it should be like this:

Code: Select all
tell application "IndigoServer"
   if (value of variable "BaseTime") < 600 then
      set Y to (value of variable "BaseTime")
      set Y to Y + 30
      set (value of variable "BaseTime") to Y
   end if
       
   set X to (value of variable "BaseTime")
   set (value of variable "Timer") to X
   
   log "This is the new incremented BaseTime (in seconds)"
   log Y
end tell

Posted on
Wed Aug 08, 2007 2:28 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: X10 with Applescript & Indigo

NebENG wrote:
-After 2 weeks, the delay gradually comes down from the ceiling in 10 second increments every day (or week) (ex: after 2 weeks, the time delay drops to 00:05:50, after another week it goes to 00:05:40, and so on)

This can be solved using another timer. Just define a variable "TimerDelay" and set it's value to 1209600 (that's 2 weeks in seconds) everytime you set a new "BaseTime".
When "TimerDelay" reaches 0, you decrease "BaseTime" with 10 seconds and give "TimerDelay" a new value.

Then all you have to do is wait for two weeks without touching the buttons to test if it works. That will be the hardest part because those buttons will be screaming "HIT ME!!!" every single day. :lol:

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests