Community discussions

 
gotsprings
Forum Veteran
Forum Veteran
Topic Author
Posts: 735
Joined: Mon May 14, 2012 9:30 pm

Making a GUEST WiFI Schedule in Script

Wed Jul 11, 2018 7:34 am

I have been working on a Scheduler...\

I came up with a time test that works...
:local timetest [/system clock get time]
:local GST
:if (($timetest>09:00:00)and($timetest<21:20:00)) do={set $GST "1"} else= {set $GST "0"}
:log info "GST Status = $GST"
This is one of the 2 variables I need to monitor.
The problem is that time range needs to be different for each day of the week.

I found this script...
# Calculates day of the week for a givien date
# Month: jan,feb ... nov,dec   (must be lower-case)
# Day: 1 - 31
# Year: 1900 - 2999
# mmm/dd/yyyy   same format as [/system clock get date]
# (ex. jul/22/2009)

:local date [/system clock get date]



# Math Calculation here
:local result ""
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
:local monthtbl [:toarray "0,3,3,6,1,4,6,2,5,0,3,5"]
:local daytbl [:toarray "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"]

:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]

# if the first char is a 0 (zero) only read last char, else script fails
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do=[:set year ($yearc)]

:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
  :if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }
}
:set sum ($sum - (($sum / 7) * 7))
:set result [:pick $daytbl $sum]

# END Math Calculation

:put ([:pick $date 0 3] . "/" . [:pick $date 4 6] . "/" . [:pick $date 7 9] . [:pick $date 9 11] . " is on a " . $result)

:log info "Today is $result."
That let me get a day of the week.

What i need is the ability to set my time range per day.
Then the script needs to put that in to the line to monitor it.

I tried making a global variable... then calling it.
:global $GuestSchedule
When i hit
:log info $GuestSchedule
I get
($timetest>09:00:00)and($timetest<21:25:00)

/system script environment> print
# NAME VALUE
0 GuestSchedule ($timetest>09:00:00)and($timetest<21:25:00)

Why does this fail?
:if ($GuestSchedule) do={set $GST "1"} else= {set $GST "0"}
I feel like I am missing something small.
Last edited by gotsprings on Sat Jul 14, 2018 2:55 pm, edited 2 times in total.
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so."
Mark Twain
 
lambert
Long time Member
Long time Member
Posts: 526
Joined: Fri Jul 23, 2010 1:09 am

Re: Making a scheduler...

Wed Jul 11, 2018 7:48 am

I'm not sure what you're trying to do. Maybe it needs to be this complicated.

I would create a separate schedule for each day which sets $GST=1 at the start each time period and another schedule setting $GST=0 at the end of the time period.

If necessary, the schedule can flip the value of the variable then launch the complex logic script.
 
gotsprings
Forum Veteran
Forum Veteran
Topic Author
Posts: 735
Joined: Mon May 14, 2012 9:30 pm

Re: Making a scheduler...

Wed Jul 11, 2018 7:57 am

Problem 1. Unit is off at start of schedule.
GST not set.

Problem 2. Time change takes effect.
GST not set.

Problem 3. Night before schedule extends into next day... ala open till 2 on Saturday. Then reopens at 11 Sunday. Open till 4 then closed till 7. Open till 9PM
More and more schedulers needed. Rather right the || statements.

I am monitoring 2 variables... Time range and active gateway.
If either one is False or out of range... Condition = 0.
If BOTH are True... Condition = 1.

As the gateway could go up or down whenever... its pretty clean to check the time and then check the gateway.
Use :put ($GST*$Gate) You only get a 1 if both conditions are true.
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so."
Mark Twain
 
gotsprings
Forum Veteran
Forum Veteran
Topic Author
Posts: 735
Joined: Mon May 14, 2012 9:30 pm

Re: Making a scheduler...

Thu Jul 12, 2018 6:46 am

When I call the global variable...
It is brought into the script. It is not executed thou. SO I am not getting a result but just the unexecuted command back.
(($timetest>09:00:00)and($timetest<21:00:00))

Am I missing a :put and :return or something?
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so."
Mark Twain

Who is online

Users browsing this forum: No registered users and 7 guests