Script running certain days of the week

Moderator: leecollings

Post Reply
hmjgriffon
Posts: 8
Joined: Friday 20 January 2017 21:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script running certain days of the week

Post 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.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Script running certain days of the week

Post 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.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Script running certain days of the week

Post 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
hmjgriffon
Posts: 8
Joined: Friday 20 January 2017 21:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script running certain days of the week

Post by hmjgriffon »

thanks man, works perfect!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest