Jump to content

Need programming help with timer logic


Noremac

Recommended Posts

Posted

Hi all,  I'm trying to start an otherwise simple timer with the following logic:

  1.  Turn on a scene/device at sunset (or relative to sunset);

  2.  OR, turn on the same scene/device at 7:00 pm, WHICHEVER COMES LAST (during the same day).

How would I go about expressing this logic?  Thanks!

Posted (edited)

If
   (
     time is sunset     <------- after 7:00 PM
    AND
     from 7:00 PM
     to 11:59 PM
    ) OR (
    time is 7:00 PM   <---- after sunset
    AND
    from sunset
    to sunset + 4 hours
    )

Then
   -------------

 

 

If
    (
    Time is 7:00 PM
   or
    Time is sunset
    )
AND
    $Variable > 0   <----can't be State type variable or will retrigger program
Then
    set $Variable = 0
    do whatever
Else
    set $Variable += 1

 

You may need a maintenance program for fringe cases
If
      time = midnight
Then
     set $Variable = 0

Edited by larryllix
Posted

Thanks, larryllix!  I assume you are offering two suggestions.  What would your choice be?  The second one that uses a variable seems more compact, but I'm not sure I understand it!

Posted

I don't think this needs to be complicated and should not require a variable.

 

How about:

if

time is from sunset to midnight <<<hopefully, later than latest sunsets

and

time is from 7:00pm to midnight

then

turn on light

else

nothing

  • Thanks 1
Posted (edited)
2 hours ago, Noremac said:

Thanks, larryllix!  I assume you are offering two suggestions.  What would your choice be?  The second one that uses a variable seems more compact, but I'm not sure I understand it!

I am not sure which one I would prefer. I like programs that don't use variables for this type of logic. (I use them profusely elsewhere) but the first one is more complex in understandable logic.

For the variable think of them as a drawer.
If one of the condition triggers happens, either sunset or 7:00 PM
only open the drawer, look inside and if it is empty,  drop a stone (1) into it.
If the drawer already has a stone (1) inside it, then take the stone out for next time (=0) and then do whatever you want it to do.

You are making sure both conditions have transpired by only marking the first condition when it happens.

Edited by larryllix
Posted
2 minutes ago, larryllix said:

You are making sure both conditions have transpired by only marking the first condition when it happens.

Or put another way, $Variable represents how many of your triggering events have happened.  When it's before 7pm and before sunset, $Variable is 0.  When the first triggering event happens (either 7pm or sunset, whichever comes first) $Variable becomes 1.  Then when the second triggering event happens, since $Variable is greater than 0, you reset $Variable to 0 and execute the desired action.

  • Thanks 1
Posted (edited)
10 minutes ago, kclenden said:

Or put another way, $Variable represents how many of your triggering events have happened.  When it's before 7pm and before sunset, $Variable is 0.  When the first triggering event happens (either 7pm or sunset, whichever comes first) $Variable becomes 1.  Then when the second triggering event happens, since $Variable is greater than 0, you reset $Variable to 0 and execute the desired action.

LOL! Sure! Think of the variable as a counter.

The funny part is, I hear people tell me all the time they have never dealt with variables and run away from them, like we were talking advanced calculus on matrix arrays. I guess I spent a lifetime dealing with them since grade four (about 1960) when we studied unknown quantities in arithmetic, and computer wise in 1971 when the first 8 bit CPUs were launched.  So I am very biased.

People. You can't really break your ISY. It's a playground for experimentation and can be a favourite toy.. If you screw something up, spend about 2 minutes and restore your backup. I just showed my 9 year old granddaughter how to write programs on my ISY using a buzzLinc (thanx Stu), an MS, and three wall Switchlincs. She picked up compound logic using ANDs and ORs with parenthesis, in about 60 minutes and had a riot guessing if her dancing would pass the three wall switch logic to activate the beeper. ISY is an educational toy. Play with it!

Edited by larryllix
Posted
On 9/30/2019 at 9:02 PM, larryllix said:

The funny part is, I hear people tell me all the time they have never dealt with variables and run away from them, like we were talking advanced calculus on matrix arrays.

On the other hand, I generally prefer to use variables only when other practical solutions don't exist and to use as few programs as possible to get the job done.  I believe that noremac's problem can be solved with a single program and no variable, so this would be the choice I would make if true.  It seems to me that many use variables where none are needed.

Posted
38 minutes ago, oberkc said:

On the other hand, I generally prefer to use variables only when other practical solutions don't exist and to use as few programs as possible to get the job done.  I believe that noremac's problem can be solved with a single program and no variable, so this would be the choice I would make if true.  It seems to me that many use variables where none are needed.

I wasn't referring to this case in particular, with my comment, but was based on general comments I keep hearing from the forum.
In view of your simpler, no variable needed logic, that would be the one I would prefer.

As I posted, I don't like to use variables for this type of logic but the program logic I posted, was way too twisted and did need to be simplified by more thought. You have demonstrated that well.

The last occurrence challenge was a good one.

Posted

 

9 minutes ago, larryllix said:

I wasn't referring to this case in particular, with my comment, but was based on general comments I keep hearing from the forum.

 I have not noticed that as much.  I guess I notice more the other side (my perception of overuse of variables).  Perhaps I am seeing what I want to see and the other side makes less of an impression?

First-world problems.

  • Haha 1
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...