Why the "if %systime% condition doesn't work both ways?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
GG42
New user
Posts: 3
Joined: 12 Apr 2021, 19:45

Why the "if %systime% condition doesn't work both ways?

#1 Post by GG42 » 12 Apr 2021, 20:08

My purpose is to have a kind of perpetual timer in a definite time slot.
The following rules work well when booted within the time slot and rightly stop at its end, BUT:
point 1: when booted before the time slot, it doesn't work, why? where is the mistake?
point2: when it runs properly, in case of current failure, it doesn't restart. Is it normal?

Code: Select all

on System#Boot do
  gpio,13,1  //to be sure it is OFF
  timerSet,3,1 
endon

on Rules#Timer=3 do

    if %systime%>19:02:00 and %systime%<19:56:00

          gpio,13,0               // switch ON
          timerSet,7,10           // ON during 10 sec
          endon
               
              on Rules#Timer=7 do
              gpio,13,1          // switch OFF
              timerSet,3,5       // OFF during 5 sec
              endon
         
     else
     gpio,13,1                   //out of time-range, switch OFF
     endif

endon
Last edited by TD-er on 12 Apr 2021, 20:40, edited 1 time in total.
Reason: Added code-tags to improve readability

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Why the "if %systime% condition doesn't work both ways?

#2 Post by TD-er » 12 Apr 2021, 20:43

I edited your post to add code wrappers, which makes it quite easy why your code does not work.

Each "if" should end with an "endif" and "on" should end with "endon".

Example taken from the rules documentation:

Code: Select all

on <trigger> do
 if <test>
   <action>
   <action>
 endif
endon

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Why the "if %systime% condition doesn't work both ways?

#3 Post by Ath » 12 Apr 2021, 20:51

GG42 wrote: 12 Apr 2021, 20:08 My purpose is to have a kind of perpetual timer in a definite time slot.
The following rules work well when booted within the time slot and rightly stop at its end, BUT:
point 1: when booted before the time slot, it doesn't work, why? where is the mistake?
point2: when it runs properly, in case of current failure, it doesn't restart. Is it normal?

on System#Boot do
gpio,13,1 //to be sure it is OFF
timerSet,3,1
endon

on Rules#Timer=3 do

if %systime%>19:02:00 and %systime%<19:56:00

gpio,13,0 // switch ON
timerSet,7,10 // ON during 10 sec
endon

on Rules#Timer=7 do
gpio,13,1 // switch OFF
timerSet,3,5 // OFF during 5 sec
endon

else
gpio,13,1 //out of time-range, switch OFF
endif

endon
- Your rules are to be between the 'on <test> do' and 'endon' statements, so no 'if' outside of that
- adding [ code ] [/ code ] (without the spaces) around the code will render it much more readable (TD-er did that for you :D)
- TimerSet only activates the timer once, and you haven't added a re-activate when the condition isn't met

Code: Select all

on System#Boot do
  gpio,13,1  //to be sure it is OFF
  timerSet,3,1 
endon

on Rules#Timer=3 do
  if %systime%>19:02:00 and %systime%<19:56:00
    gpio,13,0               // switch ON
    timerSet,7,10           // ON during 10 sec
  else
    gpio,13,1                   //out of time-range, switch OFF
    TimerSet,3,60 // check again after 60 seconds
  endif
endon

on Rules#Timer=7 do
  gpio,13,1          // switch OFF
  timerSet,3,5       // OFF during 5 sec
endon
NB: This is only one way to tackle this challenge.
/Ton (PayPal.me)

GG42
New user
Posts: 3
Joined: 12 Apr 2021, 19:45

Re: Why the "if %systime% condition doesn't work both ways?

#4 Post by GG42 » 12 Apr 2021, 22:49

Many thanks Ath, it works well now, however with the exception of a dozen of "1-0-1-0..." just after the boot. But I don't know if there is a way to solve that!

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests