Page 1 of 1

Script running certain days of the week

Posted: Wednesday 08 February 2017 3:53
by hmjgriffon
I've got a lua script I would like to only run Sunday through Thursday, so not Friday or Saturday. I've figured out how to make it run on weekdays, but not specific days, my script is below:

time = os.date("*t")
weekday = os.date("%A")

commandArray = {}
if (time.hour == 22) and (time.min == 30) and (weekday ~= 'Weekend') then
commandArray['Armed Home'] = "On"

end
return commandArray

I have literally never used Lua before a few days ago and I am not a programmer or even really a scripter, I pieced this together looking at other scripts. Any help is highly appreciated.

Re: Script running certain days of the week

Posted: Wednesday 08 February 2017 6:58
by jannl
Weekday is a number. I thought from 0 to 6 or from 1 to 7. You can compare them against the days you whish to run the script. I use this to differ the time my curtains open in the morning. (Later in the weekends).
I can not look in my script right now for the exact syntax.

Re: Script running certain days of the week

Posted: Wednesday 08 February 2017 8:38
by Nautilus
hmjgriffon wrote:I've got a lua script I would like to only run Sunday through Thursday, so not Friday or Saturday. I've figured out how to make it run on weekdays, but not specific days, my script is below:

time = os.date("*t")
weekday = os.date("%A")

commandArray = {}
if (time.hour == 22) and (time.min == 30) and (weekday ~= 'Weekend') then
commandArray['Armed Home'] = "On"

end
return commandArray

I have literally never used Lua before a few days ago and I am not a programmer or even really a scripter, I pieced this together looking at other scripts. Any help is highly appreciated.
As janni mentioned, your weekday variable gets a value 0-6 (Sun-Sat) so this condition weekday ~= 'Weekend' is always true. You need something like this:

Code: Select all

time = os.date("*t")
weekday = os.date("%A")

commandArray = {}
if time.hour == 22 and time.min == 30 and weekday < 5 then
	commandArray['Armed Home'] = "On"
end
return commandArray

Re: Script running certain days of the week

Posted: Sunday 05 March 2017 18:11
by hmjgriffon
thanks man, works perfect!