Jump to content

another quick programming question


ixlr8

Recommended Posts

I have a quick programming question. What I am trying to do is, if garage door opens between sunset and sunrise, lights come on in the house and stay on for 20 minutes then go off. I wrote the following program and the light turns on, but it does not go off after 20 min... what did I do wrong?

 

Thanks-- Jim

 

If

Status 'Garage-House-Sensor' is On

And Status 'LR Table Lamp' is Off

And From Sunset

To Sunrise (next day)

 

Then

Set 'LR Table Lamp' On

Wait 20 minutes

Set 'LR Table Lamp' Off

 

Else

- No Actions - (To add one, press 'Action')

Link to comment

Hi Jim,

 

A program will re-evaluate itself after a wait command.

So after the 20 minute wait, if all the if condtions are still not true, then the program jumps to else instead off turning the lamp off.

 

Your best bet is to accomplish this by using 2 programs, one latching a second executing program.

Link to comment
Hi Jim,

 

Your best bet is to accomplish this by using 2 programs, one latching a second executing program.

Thanks for the reply... but to be honest, I have no idea what you mean when you say "one latching a second executing program". I have zero programming experience, I am just stumbling my way through this.

 

Jim

Link to comment

A running program in a WAIT will be prempted (i.e. old instance stopped in favor of the new instance) if the trigger conditions for the program occur again, thus causing the program to execute again.

 

You are using status conditions for both the garage door sensor and the lamp. Status conditions will trigger the program any time the status changes. So, assuming between sunset and sunrise, the lamp is OFF, and the garage door is opened (garage-house-sensor is turned ON), your program will run the THEN branch. The first thing that your program does is turn the lamp ON then enter a WAIT.

 

But, hold-on a second, the status of the lamp has now changed to ON, which will kick-off a new instance of the program, causing the old instance of the program in the WAIT to end. The new instance of the program will run the ELSE branch (the lamp is ON) and thus nothing will happen. Your program never makes it to the Set Lamp OFF command.

 

Also, the same thing would happen if somebody closed the garage door in the 20 minute interval, because the status of the gargage-house-sensor would change to off, thus re-running the program and killing the WAIT, thus never turning off the lamp.

 

There are all kinds of convoluted solutions to this issue that you will find all over these forums. My recommendation is to remove the Lamp is OFF status condition, and change the garage-house-sensor condition to a control condition, i.e. "If Control 'Garage-House-Sensor' is turned On." This way, if the garage door is opened between sunset and sunrise, the lamp will turn on and then turn off in 20 minutes, even if the garage door is subsequently closed or the lamp is turned off in the mean time.

 

You are still left with the boundary condition of Sunrise. If Sunrise occurs during the 20 minute interval, i.e. while the program is in the WAIT, the program will again be pre-empted by a new instance, and the lamp will not be turned off.

 

Note that I have long advocated seperating trigger conditions for a program from the conditions in an IF statement. This comes up again and again in programming questions. I wish others would take up the cause and we could get this changed.

Link to comment

By the way, here is what the other poster meant by "latching" a second program.

 

In your first program, instead of the THEN branch containing:

 

Set 'LR Table Lamp' On

Wait 20 minutes

Set 'LR Table Lamp' Off

 

change it to:

 

Run Program 'LampOn20Minutes' (Then Path)

 

The program LampOn20Minutes would contain no ?IF conditions and the following in Then branch :

 

Set 'LR Table Lamp' On

Wait 20 minutes

Set 'LR Table Lamp' Off

 

The LampOn20Minutes program would be executed by the first program when the conditions were met and run independently of the first program. Therefore, it would not be preempted by subsequent runs of the first program when the conditions change. When I do this, I often put a "Set 'LR Table Lamp' Off" or the like in the Else branch of the second pgoram as well, just to have a cleanup branch of the program to call, if needed.

Link to comment

kingwr- Thank you for taking the time to try and explain this in all the detail you did. I have read it about 5 times... I think it is starting to make some sense. Lots of subtleties to all this. I am off to try your suggestions... will report back tomorrow.

Link to comment
........

 

change it to:

 

Run Program 'LampOn20Minutes' (Then Path)

 

The program LampOn20Minutes would contain no ?IF conditions and the following in Then branch :

 

Hmmm... not sure what you mean by "(Then Path)"

I have done a tiny bit of simple X-10 programming and most of this stuff is WAY over my head. The programming power in the ISY is more than I will ever learn... thank you for your help in getting started.

 

Jim

Link to comment

kingwr - interesting... looks like your trying to do something VERY similar to me. I just dove into programming the ISY yesterday (it just arrived) and I can say its WAY simpler than some of the other things Ive tried.

 

http://forum.universal-devices.com/view ... highlight=

 

My attempts to incorporate an IOLinc to the kitchen dimmer are above - pretty simple, but plenty to frustrate you until the language sinks in a bit.

 

If there was only a decent manual / PDF with some bang up examples somewhere. I might try to author one - there are some excellent code snippets in the forums. Anyway, Ive already found the community here to be VERY helpful.

Link to comment

Archived

This topic is now archived and is closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      36.9k
    • Total Posts
      370.2k
×
×
  • Create New...