Jump to content

Is there a smarter way to write this timing function ?


satwar

Recommended Posts

Posted

What are you trying to do?

 

My understanding is that your program will only run twice a day:  The "Then" clause runs at 9pm and the "Else" clause runs at 9 am.

 

So it is not processor intensive, but it probably isn't doing what you want.

Posted (edited)

Don't worry about ISY being CPU bound. The pro can have 1000 programs and it's the same firmware and CPU

 

Are you having some problem with it working?

 

 

Main Bedroom Humidifier - [iD 0002][Parent 000C]

If
        From     9:00:00PM
        To       9:00:00AM (next day)
 
Then
        Set 'Main Bedroom / Bedroom Humidifier' 100%
        Wait  1 minute                                                <----- this line has no program function
 
Else
        Set 'Main Bedroom / Bedroom Humidifier' Off
        Wait  1 minute                                               <---- this line has no program function
 

Edited by larryllix
Posted

No trouble with it working, just wondering if the program could be more efficient.  I'm also wondering what the WAIT 1 minute was doing.  Sounds like it could run without it.  I'll give it a try.

Posted

What are you trying to do?

 

My understanding is that your program will only run twice a day:  The "Then" clause runs at 9pm and the "Else" clause runs at 9 am.

 

So it is not processor intensive, but it probably isn't doing what you want.

 

The program turns an appliance on at 9 pm and turns it off at 9 am.  It works but just wondering if there's a more efficient way ?

Posted (edited)

No trouble with it working, just wondering if the program could be more efficient.  I'm also wondering what the WAIT 1 minute was doing.  Sounds like it could run without it.  I'll give it a try.

You have to imagine yourself as the computer walking through the instructions and doing each line, one at a time, in order.

 

When you get to the Wait 1 minute, what are you waiting for? There is nothing else to do after that.

 

 

With only one line per section it's about efficient as it can get for the ISY CPU.

Edited by larryllix
Posted

You have to imagine yourself as the computer walking through the instructions and doing each line, one at a time, in order.

 

When you get to the Wait 1 minute, what are you waiting for? There is nothing else to do after that.

 

 

With only one line per section it's about efficient as it can get for the ISY CPU.

 

Doesn't wait in the else clause put this program in a perpetual 1 minute run cycle?

 

 

Jon...

Posted

No. At the end of the interval the program will terminate.

Posted

Doesn't wait in the else clause put this program in a perpetual 1 minute run cycle?

 

 

Jon...

The ISY is event-based; it will not "busy-wait".  Basically, the upon encountering the "wait one minute" it will schedule that program to wake up in one minute, and go do something else, and if there's nothing else to do, it will go watch "Judge Judy" on TV or whatever it is that the ISY CPU does when it's idle...

Posted

The ISY is event-based; it will not "busy-wait".  Basically, the upon encountering the "wait one minute" it will schedule that program to wake up in one minute, and go do something else, and if there's nothing else to do, it will go watch "Judge Judy" on TV or whatever it is that the ISY CPU does when it's idle...

 

What's confusing me is I had thought "wait" caused a reevaluation of the condition?  I'm thinking now that if the status of the program (true/false) changes before "wait" period completes then it (wait) is terminated?

 

a statement like "if time is 0600am" will never become false so wait will complete.  A statement like "if time is from 0600am to 0900am" will be true within that period so within that period "wait" will complete up until the statement becomes false.

 

 

 

 

Jon...

Posted

a statement like "if time is 0600am" will never become false so wait will complete.

 

The statement will be true at 0600am.

 

Run 'program_name' will re-evaluate the condition(s). The only thing a Wait statement does is bide time until the interval has elapsed, then the program will continue. If no statements follow the wait, then the program will terminate.

Posted

The statement will be true at 0600am.

 

Run 'program_name' will re-evaluate the condition(s). The only thing a Wait statement does is bide time until the interval has elapsed, then the program will continue. If no statements follow the wait, then the program will terminate.

 

Ok.. I'm was being a little facetious :-J  My question however is earnest.  Does wait cause a reevaluation of the condition?

 

The following program allows wait to complete.

New Program - [ID 00DB][Parent 00CC]

If
        Time is  6:43:30PM
 
Then
        Set 'Light Media Room' On
        Wait  2 minutes and 15 seconds
        Set 'Light Media Room' Off
 
Else
   - No Actions - (To add one, press 'Action')
 


The following program does not allow wait to complete...

New Program Copy - [ID 00E9][Parent 00CC]

If
        From     6:50:00PM
        To       6:51:00PM (same day)
 
Then
        Set 'Light Media Room' On
        Wait  2 minutes and 15 seconds
        Set 'Light Media Room' Off
 
Else
   - No Actions - (To add one, press 'Action')
 


Jon...

Posted

Here's another example...

 

I used an integer variable so it wouldn't change the status.  The program was triggered and the light turned on.  I then changed the variable (i.Test) to "0" so the condition then became false but the status of the program didn't change and wait completed.  If wait reevaluated the condition then wouldn't it stop as the variable had changed?

New Program Copy Copy - [ID 00EA][Parent 00CC]

If
        From     7:17:00PM
        To       7:20:00PM (same day)
    And $i.Test is 1
 
Then
        Set 'Light Media Room' On
        Wait  1 minute and 15 seconds
        Set 'Light Media Room' Off
 
Else
   - No Actions - (To add one, press 'Action')
 


Jon...

Posted (edited)

The Wait and Repeat do not cause the If to be reevaluated.   The Wait and Repeat allow the If to be reevaluated.  Normal rules for what triggers an If apply.

Edited by LeeG
Posted

The Wait and Repeat do not cause the If to be reevaluated.   The Wait and Repeat allow the If to be reevaluated.  Normal rules for what triggers an If apply.

 

Thanks LeeG... The Wiki needs to be changed.. "The 'Wait' command, when encountered during program execution, will cause the program's conditions to be reevaluated."

 

so I believe this statement is true... Wait used within Then will execute as long as the program status is true.  Wait used within Else will execute as long as the program status is False?

 

and so the same should be true for the "Repeat" command?

 

 

Jon...

Posted

jerlands

 

Can you point me to the Wiki section that has that information.  I got this from Wait/Repeat description.

 

http://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Action

 

Wait

 

Waits for the specified amount of time. If the Random checkbox is checked, then a random value from 0 to the specified time is used.

  • A wait stops when the conditions change.

Repeat

 

Continuously repeats at this interval, as follows:

  • A repeat stops when the conditions change.
  • To break a Repeat sequence, add a "Repeat 1 times". Actions after this Repeat will only run once (that is to say, they won't repeat at all). This is useful when you want some Actions repeated, but then want to continue on with more Actions that should not be repeated.
  • The Repeat and Wait actions have a "Random" option. This is set by selecting the Random check box. A Random value from 1 to the entered value will be randomly chosen each time the action is run. 
Posted

 

jerlands

 

Can you point me to the Wiki section that has that information.  I got this from Wait/Repeat description.

 

http://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Action

 

Wait

 

Waits for the specified amount of time. If the Random checkbox is checked, then a random value from 0 to the specified time is used.

  • A wait stops when the conditions change.

Repeat

 

Continuously repeats at this interval, as follows:

  • A repeat stops when the conditions change.
  • To break a Repeat sequence, add a "Repeat 1 times". Actions after this Repeat will only run once (that is to say, they won't repeat at all). This is useful when you want some Actions repeated, but then want to continue on with more Actions that should not be repeated.
  • The Repeat and Wait actions have a "Random" option. This is set by selecting the Random check box. A Random value from 1 to the entered value will be randomly chosen each time the action is run. 

 

 

This link and scroll to "Wait Command." 

 

A wait stops when the conditions change. <-- This statement does not appear correct to me either as it seems to require a program status change (true/false state of program.)

 

I understand the new (ver 5) and old options for wait and repeat but I believe they terminate whenever the program status changes.

 

 

Jon..

Posted (edited)

My understanding is that a Wait allows the OS to do it's system homework and evaluate ALL triggers if another event has happened.

 

IOW: Wait and Repeat is a program's way of giving up it's time slice for a finite amount of time. If no Wait or Repeat is encountered that program hogs the PLC part of the CPU time. Nobody else get a chance to run until it is done.

Edited by larryllix
Posted

 and evaluate ALL triggers

 

I don't even think it evaluates but I believe "triggers" is key.  It just seems to be reliant upon the status of the program.  If an integer variable is part of the condition and that variable changes it makes no matter to the wait or repeat.

 

 

Jon...

Posted

I don't even think it evaluates but I believe "triggers" is key.  It just seems to be reliant upon the status of the program.  If an integer variable is part of the condition and that variable changes it makes no matter to the wait or repeat.

 

 

Jon...

Out of context. The whole phrase was " allows (the OS to do it's system homework and evaluate ALL triggers)" Parenthesise were implied. English! :)

 

If none of the trigger elements change there is nothing to run. A program needs to be executing a wait or repeat, or no programs are running (system at rest)  for ISY to even evaluate this.

 

I believe if we write  a program with 1000 lines of code and no Wait or Repeat included no other triggers or programs could run during this code  running time. possibly no Insteon signals would be sent or received ones processed either.

Posted

I don't even think it evaluates but I believe "triggers" is key.  It just seems to be reliant upon the status of the program.  If an integer variable is part of the condition and that variable changes it makes no matter to the wait or repeat.

 

 

Jon...

LOL.  Confusion here.

You are discussing the condition affecting the Wait line while I am discussing the Wait affecting condition lines. :)

Posted

LOL.  Confusion here.

You are discussing the condition affecting the Wait line while I am discussing the Wait affecting condition lines. :)

 

I forgot.. you write those long extended programs :)

 

 

Jon...

Posted (edited)

Thanks LeeG... The Wiki needs to be changed.. "The 'Wait' command, when encountered during program execution, will cause the program's conditions to be reevaluated."

 

so I believe this statement is true... Wait used within Then will execute as long as the program status is true.  Wait used within Else will execute as long as the program status is False?

 

and so the same should be true for the "Repeat" command?

 

From the Wiki:

 

"What this means [wrt/Wait or Repeat] is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or the Then clause)."

 

Program conditions are usually evaluated as soon as a change occurs unless there's a Wait or Repeat at the end of which the program conditions are evaluated. But, that's only for statements following the Wait or Repeat clause. In you original example, there are no statements following the Wait, so the program will terminate at the end of the Wait duration and will not be evaluated again (until the next trigger).

Edited by stusviews
Posted (edited)

From the Wiki:

 

"What this means [wrt/Wait or Repeat] is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or the Then clause)."

Nice.

But it still has holes in it causing confusion

 

"What this means [wrt/Wait or Repeat] is that if anything a program's Then clause changes a condition which causes the program's overall condition to become false while the program's Then then clause is running (or if anything the program's Else clause changes a condition which causes the program's overall condition to become true, while the program's False clause is running), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or the Then clause)."

Edited by larryllix
Posted

Nope.

 

"A series of statements within a Then clause (or within an Else clause), up to the next Wait or Repeat statement, are atomic. In other words, all such statements are executed before the conditions of the program are retested. The program's conditions are reevaluated each time a Wait or Repeat statement is encountered, and at the end of each iteration of a Repeat loop."

Guest
This topic is now closed to further replies.

×
×
  • Create New...