Jump to content

Question regarding if condition and open/close sensor


mserrar

Recommended Posts

Hi,

I got an open/close sensor. Here is what I wanted to do:

 

If the sensor is open then turn on Light 1 and Light 2.

When the sensor close then turn off Light 1 and Light 2.

 

I created 2 programs:

-------------------------------------

Program Sensor Open

 

If

  Status 'sensor' is On

  And $var1 is 0

 

Then

  Set 'Light 1' On

  Set 'Light 2' On

  $var1 = 1

 

 

Program Sensor Closed

 

If

  Status 'sensor' is off

  And $var1 is 1

 

Then

  Set 'Light 1' Off

  Set 'Light 2' Off

  $var1 = 0

---------------------------

 

The 2 programs works fine, however , I think that maybe there might be a way to make it better or use only 1 program instead of 2, so here are few questions that might help me:

 

1- Is there a way to have nested if conditions?

2- I really would like to have the option that if 'Light 1' was On before then sensor is open, so when sensor close, I would like the 'Light 1' to stay On. (Basically to keep its previous status)

 

Any help from you is appreciated.

Thank you again.

Link to comment

 

2- I really would like to have the option that if 'Light 1' was On before then sensor is open, so when sensor close, I would like the 'Light 1' to stay On. (Basically to keep its previous status)

 

Since Light 2 follows the status of the sensor, create a scene for that light. Then follow the status of Light 1 only.

Link to comment

I don't believe there are "nested" conditions.

 

Out of curiosity, what is the purpose of the variable?  Is it a state or integer variable?

 

What is wrong with a simpler program, sans variable:

 

if

If

  Status 'sensor' is On

Then

  Set 'Light 1' On

  Set 'Light 2' On

Else

  Set 'Light 1' Off

  Set 'Light 2' Off

Link to comment

If all you want to do is turn some lights on when the sensor status changes to ON, and turn some lights off when the sensor status changes to OFF, then I suspect my little program would work.  If you have additional constraints or conditions, let us know.

 

One thing you can use as a program condition is the status of a program (true or false).  The program I posted itself can, thus, act as a status indicator for your sensor.  This program will evaluate TRUE (then clause last ran) when the sensor is on, and FALSE (else clause last ran) when the sensor is off.  There is little need to create a variable for this if you don't want to.

Link to comment

I should probably clarify the use of variable versus program as a status indicator.  There could be a difference in using programs versus variables as a program condition, depending on whether you want to use that condition as a program trigger.  Depending on whether your variable is integer or state, it can act as a trigger or not.  Programs as a condition do trigger, I believe, a program evaluation upon change of state.

Link to comment

mmmm thank you for your answer.

I should explain clearly my constraints.

When sensor is on, I would like to turn on 2-3 lights, and when sensor turns off, I would like to turn off 2-3 lights. (it might be 2 or 3 lights , I am still not decided)

But let's say for example, I have this case:

 

Sensor is Off

Light 1, 2, 3 are all Off.

 

Then I turn on manually Light 1 and 3.

 

Then When Sensor is On, it will turn On only Light 2 (because light 1 and 3 were turned on before)

 

Then when Sensor is turned Off, it will turn Off Light 1,2 and 3. (I would like it not to turn off the Light 1 and 3 if they previous status was On). It should be turned Off only if it was turned On by the sensor.

 

Makes sense?

Link to comment

I think this can be accomplished but it will take a series of 9 programs and 3 variables to make it happen.  Something like this:

 

Define 3 integer variables:

i.Light1.Status

i.Light2.Status

i.Light3.Status

 

Create 3 programs to monitor the controls for the 3 lights:

 

Program: Light1Monitor

If
   Control 'Light1' is Switched On
  and Control 'Light1' is not switched Off

Then
   i.Light1.Status = 1

Else
   i.Light1.Status = 0

Duplicate the above and edit for Lights 2 and 3.

 

 

Now, we need 3 more programs that monitor the sensor and turn on the lights when the door opens:

If 
   Control 'Door Sensor' is switched On
   and i.Light1.Status = 0

Then
   Set scene 'Light1' On

Duplicate and edit for Lights 2 & 3

 

and Lastly, three more for turning off the lights when the door closes:

If 
   Control 'Door Sensor' is switched Off
   and i.Light1.Status = 0

Then
   Set scene 'Light1' Off

Duplicate and edit for lights 2 & 3

 

Place all of these programs in one folder.  That way if you want to disable the automatic lights, you can simply disable the folder with a false condition.

 

Hope this helps.

 

-Xathros

 

EDITED: to correct variable values (Thanks oberkc!)

Link to comment
I should explain clearly my constraints.

 

mmmmm...do you think?  One of the difficulties I see here often is that folks post a program and ask why it doesn't work, without stating clearly what it is that they want it to do.  It is difficult answering such questions without an understanding of the purpose of the program.  Sometimes, you find out, they really haven't given it enough thought.  I am glad you have thought about your requirements to this level of detail.

 

xatrhros' response was near exactly what I would have suggested, except for a few trivial variations.  Your requirements were certainly more complicated than I had first envisioned.

 

One question...

 

xathros:

 

Should your "lastly" program variable condition be equal to 0 rather 1, to indicate that the switch was not manually turned on?

Link to comment

One question...

 

xathros:

 

Should your "lastly" program variable condition be equal to 0 rather 1, to indicate that the switch was not manually turned on?

Nice catch!  Yes - both the Open and Close should have read 0 instead of 1.  Thanks.

 

-Xathros

Link to comment

What if a light is turned on by the switch then turned off by something other than the switch, say another scene such as an all off. Then it does not look like the variable will reset to zero so next time you open the door the light will not turn on. If you have any such scenes take that into consideration.

Or are more programs needed.

If status light is off

then set variable = 0

E

Link to comment

What if a light is turned on by the switch then turned off by something other than the switch, say another scene such as an all off. Then it does not look like the variable will reset to zero so next time you open the door the light will not turn on. If you have any such scenes take that into consideration.

 

All interesting questions, but this was not part of the stated requirements.  In my mind, questions like this are good to ask oneself when deciding how you want your system to respond.

 

Without thinking too much, I would be concerned about using status for the variable trigger, because the sensor program itself is going to cause a status change.  Since mserrar only wanted to disable the response when the switches were directly controlled, I think "control" is the better approach at this point.

Link to comment

Oberkc, I understand your point in the earlier post regarding knowing what the op wants. If the op did use an all off function then his variable would be out of sync. The status program I suggested would be in addition to the other programs to be sure the variable=0 for a light that is turned on by a local switch and then turned off by an all off, timer, etc.

E

Link to comment

Oberkc, I understand your point in the earlier post regarding knowing what the op wants. If the op did use an all off function then his variable would be out of sync. The status program I suggested would be in addition to the other programs to be sure the variable=0 for a light that is turned on by a local switch and then turned off by an all off, timer, etc.

E

This is true.  In such a case, the OP would need to consider that and reset the vars in the all off program if so desired.

 

-Xathros

Link to comment

Thank you all for your answers.

 

All interesting questions, but this was not part of the stated requirements. 

 

 

oberkc, let me disagree with you on that. It was stated in the requirements. Like I mentioned in my requirements (Then I turn on manually Light 1 and 3.) 'Manually' means it could be turned on by pressing a scene button that controls these lights.

 

Thank you Xathros for taking the time and explain the program, I had this idea in mind to use a variable for each light status, but it wasn't an option for me, because I gave here an example for 3 lights, but this will be used with many lights/devices, and I see it as being a nightmare to create variable for each and also dealing with these variable inside scene programs.

 

I thought I can get away with something that's already in the system keeping the previous status of a device (being status change with pressing manually the switch or being changed by a scene)

I guess such variable doesn't exist in the system and I will have to create one for each device and take care of resetting it for each status change.

 

Thank you for your help anyway :)

Link to comment

oberkc, let me disagree with you on that. It was stated in the requirements. Like I mentioned in my requirements (Then I turn on manually Light 1 and 3.) 'Manually' means it could be turned on by pressing a scene button that controls these lights.

 

not so much a disagreement but misunderstanding on my part.  I did not understand your meaning of "manually".

 

As I believe you have figured out, I think you will find xathros' suggested program will not toggle a variable change when the Light1/2/3 are changed as a result of a scene command.  Consequently, you will need additional conditions for this.

 

I guess such variable doesn't exist in the system and I will have to create one for each device and take care of resetting it for each status change.

 

 

Yes, there is a STATUS condition which would trigger upon any CHANGE in status, regardless of reason (whether direct control, scene control, program, etc).  Unfortunately, it would also trigger when the sensor program triggers a change in status, which is something that one needs to avoid in this type of scenario.  It is not the lack of a global condition that is the problem, rather, it is because of the need to be more specific about which causes of status change should trigger a variable change.  Because you want the variable to change only when someone physically pushes a button (either directly, or through a scene relationship) and NOT via the door sensor program, STATUS would not work here.  Furthermore, use of CONTROL has the benefit that it would restart the timer should the sensor send another ON command during a wait period.

Link to comment

I understand. I think I will just lower my requirements, and accept the fact that if the light is turned off by the sensor, I will just have to turn it back on :)

Thank you for taking the time in helping me.

Sorry to keep jumping in since I am not nearly as good with programming as Xathros and oberkc.  I do not think you should give up on this.  The ISY should be able to handle your initial requirements.  

I do not see why a tenth program like this would not work.  

If
        Status  Light1 is Off
     Or Time is  1:15:00AM
 
Then
        $i.Light1  = 0
 
Else
   - No Actions - (To add one, press 'Action')

So if the light, say light1, is turned off by any means, then the status is off, the program runs and sets the variable to zero.  I added a time so maybe at night if you want the light to turn off by closing the door it will.  if you had an all off button you could add that to the if section.

However, I am not sure about the second set of programs that Xathros posted.  For turning the light on it does not really matter what the variable is.  You only want the variable to determine if conditions are met to keep the light on or to turn it off when the door closes.  

If 
   Control 'Door Sensor' is switched On
   and i.Light1.Status = 0

Then
   Set scene 'Light1' On

If the variable = 0, the scene turns on.  If the variable =1, well the scene is already on.  So the program is useful in that it does not allow a scene that is already on to turn on.

I think you should try these things out to see how they work.

Eric

Link to comment
 I do not think you should give up on this.  The ISY should be able to handle your initial requirements. 

 

There is not doubt in my mind that the ISY can handle this.  I think, too, that you will find that it is not so hard to create these programs.  I have a couple that are very similar.

 

I do not see why a tenth program like this would not work.  

 

There is already a series of programs that turn the variable to zero when the switch is manually turned off.  Expanding that series to include other switches as input conidions would work.  Alternatively, I could see a program such as this one working, (at least for zeroing out the variable), but you would still need similar programs to the original series to set the variable to 1.  I simply see this as an extra program...but, yes, it could work. 

 

For turning the light on it does not really matter what the variable is.

 

I tend to agree with this, but some tend to want to minimize insteon communication traffic. 

 

If the variable = 0, the scene turns on.  If the variable =1, well the scene is already on

 

This may be where we depart.  There needs (in my mind) to be three variables, for three lights.  I thought we wanted to judge to turn the lights off on an individual basis, if one was on originally and the door closes, turn off the other two and leave the one on.  This is why there are three programs...on for each light. 

Link to comment

Yes, you need all of the programs. My point was simply that you do not need to have the line for the variable in this program, unless it is to reduce signal traffic. You always want the light to turn on when the door is opened. I hope you got things working well.

If

Control 'Door Sensor' is switched On

and i.Light1.Status = 0

 

Then

Set scene 'Light1' On

Link to comment

Archived

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


×
×
  • Create New...