Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
hello
I want to create a script that will trigger outputs if the current date and time matches the date and time in an array, array size will be 365*7
I have six-times columns for each day *365 days
for each column of the six columns a different output will be triggered.
what is the most efficient way to do this and which kind of scripts should I use?
Best Regards,
Posts: 7759
Threads: 42
Joined: Jun 2015
Reputation:
447
Why don't you use schedulers for this?
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
08.11.2021, 09:41
(This post was last modified: 08.11.2021, 09:43 by khalil.)
(08.11.2021, 09:36)admin Wrote: Why don't you use schedulers for this?
do you think that schedule is the best for this?
I think in scripts because it's more flexible and can be edited easily.
edit: Also because I have a lot of entries I think the script will be easy, I will get the table as excel instead of entering the data manually.
Best Regards,
Posts: 7759
Threads: 42
Joined: Jun 2015
Reputation:
447
The question is where the schedule data comes from and if it should be editable by the end user. If the schedule is fixed then you can simply create a table with date/time and use a scheduled script that runs every minute to check if date/time matches.
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(08.11.2021, 09:45)admin Wrote: The question is where the schedule data comes from and if it should be editable by the end user. If the schedule is fixed then you can simply create a table with date/time and use a scheduled script that runs every minute to check if date/time matches.
thanks, admin
its a fixed date/time table
the date/time table represents the pray time for each day of the year.
I want to control the light and AC of the masjid (mosque) eg. turn on the light before azan time by x minutes if sunset.
I hope the description is clear now, what is your suggestion admin?
regards,
Best Regards,
Posts: 7759
Threads: 42
Joined: Jun 2015
Reputation:
447
Scheduled script that runs every minute. Fill schedule table with dates and times.
Code: schedule = {
['1/1'] = { '1:05', '2:10' },
-- ...
['12/31'] = { '1:11', '15:13' },
}
dtbl = os.date('*t')
date = string.format('%d/%d', dtbl.month, dtbl.day)
time = string.format('%d:%02d', dtbl.hour, dtbl.min)
schedtimes = schedule[ date ] or {}
for _, schedtime in ipairs(schedtimes) do
if schedtime == time then
-- execute action
end
end
I suppose there should be a formula for calculating times for each date. Might be easier to implement it instead of a fixed table.
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(08.11.2021, 13:19)admin Wrote: I suppose there should be a formula for calculating times for each date. Might be easier to implement it instead of a fixed table.
Thanks Admin
Yeah, there is a formula, but I didn't find the accurate one, so a fixed table will be an alternate way if I failed to find the accurate formula.
regards,
Best Regards,
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(08.11.2021, 13:19)admin Wrote: Scheduled script that runs every minute. Fill schedule table with dates and times.
Code: schedule = {
['1/1'] = { '1:05', '2:10' },
-- ...
['12/31'] = { '1:11', '15:13' },
}
dtbl = os.date('*t')
date = string.format('%d/%d', dtbl.month, dtbl.day)
time = string.format('%d:%02d', dtbl.hour, dtbl.min)
schedtimes = schedule[ date ] or {}
for _, schedtime in ipairs(schedtimes) do
if schedtime == time then
-- execute action
end
end
Hello Admin,
the Array will be defined every time the script Run? if yes how to define it once not run every cycle?
regards
Best Regards,
Posts: 7759
Threads: 42
Joined: Jun 2015
Reputation:
447
Script runs every minute and checks if there's a matching date/time inside the schedule table. The schedule is defined once with all dates and times for the year. Put your actions after the "-- execute action" line. It will only be executed for matching date and time.
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
13.11.2021, 11:23
(This post was last modified: 16.11.2021, 09:45 by khalil.)
Hello Admin
is there a chance that the schedule script miss the table time so the execution occurs before or after the desired time?
another question, I am trying to compare real time with the table time e.g. if nowTime (>,<,=) tableTime[Y] (+-) X then do something
Edit: This is what I did, any advice admin?
Code: dtbl = os.date('*t')
date = string.format('%d/%d', dtbl.day, dtbl.month)
time = string.format('%d:%02d', dtbl.hour, dtbl.min)
timeNum = (dtbl.hour-y)*60 + (dtbl.min-x) -- current time in minutes
c = 0 -- to know active table time (active pray)
schedtimes = schedule[ date ] or {}
for _, schedtime in ipairs(schedtimes) do
c=c+1
prayTimeAry = string.split(schedtime, ':')
prayNum = tonumber(prayTimeAry[1]*60) + tonumber(prayTimeAry[2])
if (prayNum - timeNum ) == 1 then ----edit
log ("amplifier CMD")
elseif schedtime == time then
log ('Azan CMD')
-- grp.write('1/0/37',true)
elseif (timeNum - prayNum) == 6 then
log("Turn OFF System")
end
end
Best Regards,
Posts: 7759
Threads: 42
Joined: Jun 2015
Reputation:
447
It's very unlikely that the scheduled script will miss its execution. It would be better to use a formula and create scheduler events for the current day one per day.
Have you seen this Python script? Should be quite easy to rewrite it into Lua:
http://praytimes.org/code/git/?a=viewblo...aytimes.py
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(15.11.2021, 07:57)admin Wrote: It's very unlikely that the scheduled script will miss its execution. It would be better to use a formula and create scheduler events for the current day one per day.
Have you seen this Python script? Should be quite easy to rewrite it into Lua:
http://praytimes.org/code/git/?a=viewblo...aytimes.py
thank you admin for your time,
I see such websites that used formula but in our region they used a table while there are several minutes different between the table and the formula (not in all days and not in all prays). So I will use the table because its the most reliable right now.
Best Regards,
|