Page 1 of 1

Error time + day

Posted: Thursday 31 October 2019 17:31
by Hydci
Hello, I have an error that I can not solve I tried in several ways here is the simple script and the error if someone could tell me or I'm wrong thank you in advance

Code: Select all

	commandArray = {}
		
        time = os.date("%H","%M")
        local day=os.date("%A")
		-- Déclenchement tous les jours à 0:02
		if (heure == '17:17') and (day == 'thu') then
		commandArray['SAM']='On'
		
		end

	return commandArray
error:

Code: Select all

2019-10-31 17:17:00.300 Error: EventSystem: in Script #1: [string " commandArray = {} ..."]:3: bad argument #2 to 'date' (number expected, got string)

Re: Error time + day

Posted: Thursday 31 October 2019 18:05
by waaren
Hydci wrote: Thursday 31 October 2019 17:31 Hello, I have an error that I can not solve I tried in several ways here is the simple script and the error if someone could tell me or I'm wrong thank you in advance
Working with date/ time is not very intuitive in Lua...
but this script should do what you want.

Code: Select all

	commandArray = {}
	-- os.time() gets the current / date time as a number (seconds since 1970)
	-- os.date ('*t',  <number> ) returns a date / time table based on <number>
		
        local now = os.date('*t',os.time()) -- get current date / time in table now
        
        for key, value in pairs(now) do
		print (key .. ' ==>> ' .. tostring(value)) -- print content of table
	end

        -- Déclenchement tous les jours à 0:02
	if now.wday == 5 and now.hour == 17  and now.min == 55  then
	    commandArray['SAM']='On'
	end

	return commandArray

Re: Error time + day

Posted: Thursday 31 October 2019 18:08
by Hydci
Okay not very intuitive so how would you do actions at certain times with specific days? What do you recommend?

Re: Error time + day

Posted: Thursday 31 October 2019 18:23
by waaren
Hydci wrote: Thursday 31 October 2019 18:08 Okay not very intuitive so how would you do actions at certain times with specific days? What do you recommend?
I would use dzVents or if you don't want that something as I posted a couple of minutes ago..

Re: Error time + day

Posted: Thursday 31 October 2019 18:37
by Hydci
Ok thank you for the recommendation I will save your example if one day I need, so I will do as you suggested go through dzvent