Error time + day Topic is solved

Moderator: leecollings

Post Reply
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Error time + day

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error time + day

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Error time + day

Post by Hydci »

Okay not very intuitive so how would you do actions at certain times with specific days? What do you recommend?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error time + day

Post 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..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Error time + day

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests