Jump to content

Program Order


Go to solution Solved by MrBill,

Recommended Posts

Posted

Program 1: The then statement in Program 1 runs/calls the If statement in Program 2

Program 2: Is disabled so the If statement only runs when called from program 1

Question: Program 2 has a wait in the Then statement.  If the program turns false during the Wait, will the Program continue running the Then because the If is disabled (program if condition is not reassessed) or will it run the Else in Program 2 at that point?

  • Solution
Posted

Program 1

If

then
      Run Program 2 (if)
else
 

Program 2  (Disabled)

If
   
then
    ....
    wait X
    ....
else
 

30 minutes ago, jwagner010 said:

If the program turns false during the Wait, will the Program continue running the Then because the If is disabled (program if condition is not reassessed)

If which Program turns false.  Assuming since "because the If is disabled" you mean Program 2-- because the If is disabled in program 2 the then body will continue.  If you mean Program 1, as written now nothing will happen if Program 1's If becomes false... However If Program 1 becomes true again (even without becoming false first).  then Program 2 will restart.  to avoid this make program 2 like this:

Program 2  (Disabled)

If
   
then
    Disable Program 1
    ....
    wait X
    ....
    Enable Program 1
else

 

41 minutes ago, jwagner010 said:

or will it run the Else in Program 2 at that point?

Nothing here will run the Else in Program 2.

 

  • Like 1
Posted (edited)

Similar question here concerning the following program. In this case, am I correct that if motion occurs while THEN is running, the THEN execution is canceled and the IF is subsquently re-evaluated the next time all conditions are true?

 

TVRoomEmpty - [ID 000E][Parent 0001]

If
        'Ceiling Motion Sensor' Status is Off
    And 'Wall Motion Sensor' Status is Off
    And 'Media Room Sensor' Motion State is No Motion
 
Then
        Wait  1 hour and 30 minutes 
        Resource 'MarantzOff'
        Send Notification to 'Bob' content 'TurnedOffAV'
 
Else
   - No Actions - (To add one, press 'Action')
 

 

Edited by landolfi
Posted
14 hours ago, landolfi said:

Similar question here concerning the following program. In this case, am I correct that if motion occurs while THEN is running, the THEN execution is canceled and the IF is subsquently re-evaluated the next time all conditions are true?

 

TVRoomEmpty - [ID 000E][Parent 0001]

If
        'Ceiling Motion Sensor' Status is Off
    And 'Wall Motion Sensor' Status is Off
    And 'Media Room Sensor' Motion State is No Motion
 
Then
        Wait  1 hour and 30 minutes 
        Resource 'MarantzOff'
        Send Notification to 'Bob' content 'TurnedOffAV'
 
Else
   - No Actions - (To add one, press 'Action')
 

 

Correct.  anytime there is motion, the no motion that follows resets starts the counter over. 

A better approach is to detect motion (rather than no motion) and let the counter continue to reset at each new motion.   With at least the first two sensors you should also switch to control rather than status (not sure what the 3rd sensor is and whether it will have that option).  (also swap the AND's to OR's)

TVRoomEmpty - [ID 000E][Parent 0001]

If
        'Ceiling Motion Sensor' is switched on
    Or 'Wall Motion Sensor' is switched on
    Or 'Media Room Sensor' Motion State is Motion
 
Then
        Wait  1 hour and 30 minutes
        Resource 'MarantzOff'
        Send Notification to 'Bob' content 'TurnedOffAV'
 
Else
   - No Actions - (To add one, press 'Action')

 In this scenario anytime motion is detected, the 90 minute counter will start over, the program won't get to the statement "Resource 'MarantzOff'" until there has been no motion for 90 minutes.  (of course the notification might not apply, because if you did turn everything off the program will send the off anyway after 90 minutes of no motion.  No harm done tho right?  turning the marantz off when it's already of nets no action.

If you absolutely want the notification then you'll need something like:

If
   {
    'Ceiling Motion Sensor' is switched on
    Or 'Wall Motion Sensor' is switched on
    Or 'Media Room Sensor' Motion State is Motion }
AND Matantz is on

but I don't know if ISY knows if Marantz is on.....

Posted
Quote

A better approach is to detect motion (rather than no motion) and let the counter continue to reset at each new motion.   With at least the first two sensors you should also switch to control rather than status (not sure what the 3rd sensor is and whether it will have that option).

 

Thanks Mr. Bill, for the as always excellent insight.

The Marantz is invisible to ISY, but as you said, sending it an off is no problem unless I'm in the room. The notification isn't important, that was a debugging relic when the Marantz would occasionally accidentally on purpose get turned off because I had sat still for too long.

My use case is to detect when the room hasn't seen motion for a while. I'm confused why detecting motion is better than not detecting any motion?  It seems to me that either way the timer gets reset when motion is detected. But maybe you mean detecting motion means I don't have to wait some arbitrary amount of time to determine whether the room is unoccupied?

I checked and the two motion sensors (one is an Aeotec multisensor and the other a Kaipule ix32 PIR ceiling motion sensor) both have a node "Basic Control". is that what you mean by control, and that gets set to 1 when motion is detected? The "Media Room Sensor" is a Yolink via node server and doesn't have a control node. Is "control" more reliable than motion detection?

 

 

Posted
5 hours ago, landolfi said:

I'm confused why detecting motion is better than not detecting any motion?

As I look again at this particular case, there is actually is little difference functionally.  One method uses AND's the other method uses OR's.   I was likely relating a good rule for dealing with lights controlled by motion, where there is both on and off functionality in the program-- for that you are best to react to motion to get the light on, and use the wait to turn it off again... the wait won't complete as long as there is motion, because each new motion detection the program will restart.. only with no new motion in whatever the WAIT period is will allow turn off. 

Since I tend to write programs with similar logic, in this case that means I would use an IF with OR's and not AND's, I would also use Control over Status if possible (see below).

5 hours ago, landolfi said:

I checked and the two motion sensors (one is an Aeotec multisensor and the other a Kaipule ix32 PIR ceiling motion sensor) both have a node "Basic Control". is that what you mean by control, and that gets set to 1 when motion is detected? The "Media Room Sensor" is a Yolink via node server and doesn't have a control node. Is "control" more reliable than motion detection?

Actually I must confess that I don't know those devices.  I made a bad assumption that the first two were Insteon Motions.... with that said tho:

Generally speaking the difference between Control and Status, meaning this choice: image.png.934c85acfcdbebd580c1fff8f6f83f01.png

is that Control is an "Event", whereas "Status" is whatever the ISY thinks the devices state is based on the last "Events" received from the device. 

Also note that Control is an instantaneous event that doesn't have memory, that is when the event is over (in millieseconds) the statement is no longer true-- stated another way it becomes true and then is immediately false again.

On the other hand, the Status will remain the status until it changes again.

again some of this may just be programming style but I only use Status for very simple programs where it's beneficial to use the ELSE to set the opposite condition.  Here's a good fictional usage example:

If
      ShowerFlowRate <> 0
Then
       Turn 'Showerlight' On
Else
        Turn 'Showerlight' Off

So when runs water, the light comes on, when they shut the water off the light goes off.

If the IF has Or's and And's tho, you've got to watch out because the Else will run more frequently than you expect it to.  Remember that if any element of the IF changes, the entire IF is re-evaluated and when that occurs any copy of the program that is currently running (i.e. waiting in Then or Else) that copy of the program will immediate stop and a new Then or Else will run.   Consider:

If
         Light Status is On
AND Humidity > 50.0%
AND Time is Sunset to Sunrise (next day)
Then
        Turn on vent
Else
        Turn off vent.

The problem is program will run correctly when the light is turned the humidity is >50 and it's after sunset.... but this program is going to create alot of junk traffic on whatever network (insteon, z-wave, etc) because everytime the humidity changes the Else body is going to run.  So we go get in the shower in the early morning before sunrise with the light on, the humidity rises, the light comes on but goes back off and on a few times as the humidity fluctuates 49.9, 50.0, 51.0, 49.6... etc... then the humidity stays above 50 and the vent just stays on... but then Sunrise time arrives and we are still in the shower with a steamy bathroom... again the Vent turns off because "Time is Sunset to Sunrise (next day)" is now false... and all day long everytime the ISY receives a new humidity reading its going to send traffic to the Vent switch to turn off.  As such we need to both write programs that don't use Else, which likely means we need two programs one for On and one for Off.

With motion sensors how long the status stays on depends on how the motion sensors is programmed.  Consider a motion detector that stays On for 10 minutes before Sending an Off, consider a motion detector that sends and an on followed by and off as soon as motion stops, or even consider the motion that will only Send an On when motion is detected and never send an Off.  For this reason it's simpler to deal with the Control Event rather than the Status if possible...

 

  • Like 1
Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37.1k
    • Total Posts
      371.6k
×
×
  • Create New...