Jump to content

Whats wrong with this code?


markgam

Recommended Posts

Posted

Ok, this is what I want to do when the garage light is turned on manually (flicking the switch) I want the light to stay on for 25 minutes and then turn off, here is my program:

 

If

Control 'Garage Light' is switched On

And Status 'Garage Light' is On

 

Then

Wait 25 minutes

Set 'Garage Light' On

 

Else

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

 

When I flick the switch on the program doesn't run. THe following program runs fine:

 

 

If

Status '1 Floor / Garage / Garage Light' is On

 

Then

Wait 25 minutes

Set '1 Floor / Garage / Garage Light' On

 

Else

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

Posted

Well there are two problems:

 

1) "Control 'Garage Light' is switched On And Status 'Garage Light' is On" - I assume you are doing this to try to kill the WAIT if the garage light is subsequently turned off manually. However, If the Garage Light is off, and a command to turn the light on is received, the ISY may not have updated the status of the Garage Light yet, so the If statement would resolve to false everytime the Garage Light is off and then switched on. Why not just "Control 'Garage Light' is switched On", and then turn it off after 25 minutes, even if it is already off. If someone turns it back on, then the timer will reset.

 

2) In the Then section, shouldn't that be "Set 'Garage Light' Off"?

Posted

Thank you for your post. Let me further explain what I am trying to do. In my Garage I have a motion detector (2420m) which turns on the garage light when someone enters. I have the light automatically turn off after 5 minutes. Now what I want to do is to manually active the Garage light and have the light stay on for 20 mintues by bypassing the Motion Dector's program.

 

So I am assuming that I need to some how bypass the Motion detector's program so how, any ideas?

Posted
Control 'Garage Light' is switched On

And Status 'Garage Light' is On

 

I am unsure about the timing of this, but I suspect this never turns true. If at the time the control is recieved the light is off, the status is false and the condition evaluates false. If the light (switch status) was already on from the motion sensor, then turning the switch on manually does nothing. (I don't believe it sends another on signal.)

 

You can confirm this by opening the event viewer. Turn your garage light on. See if you see the command in the event viewer. While the light is still on, try switching it on again. If my understanding is true, you will not see another on event in the event viewer.

 

I am concerned that there is not way to activate a program or event by attempting to turn on a switch that is already on. Hopefully, someone can confirm this.

 

Wait 25 minutes 
Set 'Garage Light' On 

 

Are you sure you want to set garage light "on"? Would this not be "off"?

Posted

If the Motion Sensor is linked to the Garage Light switch the Motion Sensor will send an Off command to the Garage Light switch. No way to override that direct link unless you set the Motion Sensor to On commands only mode. You can remove that direct link and run an ISY Program that triggers from a Motion Sensor On command. Then have the logic in ISY Programs decide whether the last On command to the Garage Light switch came from the Motion Sensor On command triggered Program in which case it turns Off the switch after some delay value. If the last On command comes from the Garage Light switch (manual On) then a different delay value is used. There is some technique that uses the true/false state of another Program to act as a logical indicator whether the last On condition came from the Motion Sensor or from a manual On from the Garage Light switch itself. Unfortunately I cannot tell you how to code the technique of using another Program true/false state as a logical switch but there are multiple references to the technique in various forum topics.

Posted

Thanks everyone, I think I finally figured it out after intergrating your suggestions into my programs. Now, if the Motion Detector turns on the light and then the Lght switch is turned on the "Light Switch turned On" program over rides the "Motion Detector turned on" program. This is exactly what I was looking for, here is the code:

 

''Motion Detector turned on
If
       Control 'Garage PIR-Sensor' is switched On
   And Control 'Garage Light' is not switched On

Then
       Set 'Garage Light' On
       Wait  5 minutes
       Set 'Garage Light' Off

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

 

''Light Switch turned On
If
       Control 'Garage Light' is switched On
   And Control 'Garage PIR-Sensor' is not switched On

Then
       Set 'Garage Light' On
               Wait  25 minutes
       Set 'Garage Light' Off

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

Also, I had a typo in my original post:

 

Wait 25 minutes 
Set 'Garage Light' On

 

I should have had this instead:

 

Wait 25 minutes 
Set 'Garage Light' Off

Posted

Im not sure that your program is doing exactly what you expect. In your conditions section you have this type of logic.

        Control 'Garage PIR-Sensor' is switched On 
   And Control 'Garage Light' is not switched On 

As I understand control conditions they are only evaluated when the control is actuated. When you have 2 control conditions and'ed together you have a condition that cannot possible occur because you cannot receive 2 commands at the same time. Sometimes this still works because the control conditions remember their last state. Or'ing multiple control conditions will work fine.

 

I would think you want the garage light to come on when motion is detected and automatically turn off 5 minutes after the last motion was detected. If during that time you turn the light on manually the 5 minute timeout should be aborted and a new timeout of 25 minutes should be started. Also any time the garage light is turned on you want it to turn off after 25 minutes. I would modifiy the programs as follows.

 

This program turns the garage light on then off 5 minutes after the last motion is detected only if 'Manual Auto Off' program is not true

Motion Auto Off 
If 
       Control 'Garage PIR-Sensor' is switched On 
   And Program 'Manual Auto Off' is False

Then 
       Set 'Garage Light' On 
       Wait  5 minutes 
       Set 'Garage Light' Off 

This program turns the garage light on then off after 25 minutes. It also stops the motion program timeout.

Manual Auto Off 
If 
       Control 'Garage Light' is switched On

Then 
       Set 'Garage Light' On 
       Run Program 'Motion Auto Off' (If)
       Wait  25 minutes 
       Set 'Garage Light' Off
       Run Program 'Manual Auto Off' (If)

Notice that the 'Manual Auto Off' program runs its own 'If' when the timeout is done and the light is turned off. Programs that look for single control events are always true after the first time a control event occurs. Unless forced, programs like this are only evaluated when the control event occurs and since the if is checking the same event the program is always true. When the 'Manual Auto Off' program runs itself the if condition will always be false thus the program status will change to false. The 'Manual Auto Off' program status is used as a state variable in the 'Motion Auto Off' program. When the 'Manual Auto Off' timeout is in progress the 'Motion Auto Off' will not run.

 

Keep in mind that the 'Manual Auto Off' program above only works if you actuated the switch to produce the 'On' command. If you double clicked (Fast On) or pressed and help (Fade Up) the program will not run. You can modify the program to catch these conditions also.

Manual Auto Off 
If 
       Control 'Garage Light' is switched On
    Or Control 'Garage Light' is switched Fast On
    Or Control 'Garage Light' is switched Fade Stop

Then 
       Set 'Garage Light' On 
       Run Program 'Motion Auto Off' (If)
       Wait  25 minutes 
       Set 'Garage Light' Off
       Run Program 'Manual Auto Off' (If)

Posted

Lawr,

 

I noticed one thing that after the light switch was actuated to the Off position the "Manual Auto Off" program continues to run. So, I created a new program as follows:

 

 

 

Manual Auto Off - switched Off

If
       Control 'Garage Light' is switched Off

Then
       Set 'Garage Light' Off
       Run Program 'Manual Auto Off' (Else Path)

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

 

This seems to stop the process from running

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...