Page 1 of 1

Lua scripts suddenly not working anymore

Posted: Friday 06 January 2023 17:21
by S10NL
Today i noticed that many of my lua script suddenly aren't working anymore after a reboot
All the scripts haven't been changed recently, but they all have one thing in common: They use a function to determine if the current time is between a given time frame.

Code: Select all

function timebetween(s,e)
	timenow = os.date("*t")
	year = timenow.year
	month = timenow.month
	day = timenow.day
	s = s .. ":00"  -- add seconds in case only hh:mm is supplied
	e = e .. ":00"
	shour = string.sub(s, 1, 2)
	sminutes = string.sub(s, 4, 5)
	sseconds = string.sub(s, 7, 8)
	ehour = string.sub(e, 1, 2)
	eminutes = string.sub(e, 4, 5)
	eseconds = string.sub(e, 7, 8)
    --Srise = domoticz.variables('Sunrise').value -- Sensor showing current setpoint
	t1 = os.time()
	t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
	t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds}
	sdifference = os.difftime (t1, t2)
	edifference = os.difftime (t1, t3)
	isbetween = false
	if sdifference >= 0 and edifference <= 0 then
		isbetween = true
	end
    --print(" s:" .. s  .. "  e:" .. e .. "  sdifference:" .. sdifference.. "  edifference:" .. edifference)
	return isbetween
end

commandArray = {}
    Srise = otherdevices['Sunrise']
    Sset = otherdevices['Sunset']

if timebetween(Srise,Sset) and tonumber(otherdevices['Lux woonkamer']) <= tonumber(13000) and otherdevices['Verlichting - Eettafel dimmer'] == 'On' and otherdevices['Verlichting - TV'] == 'Off' and otherdevices['Verlichting - Piano'] == 'Off' and otherdevices['Verlichting - Bank'] == 'Off' then
            commandArray['Verlichting - TV'] = 'On'
            commandArray['Verlichting - Piano'] = 'On'
            commandArray['Verlichting - Bank'] = 'On' 
        print("Low light, turn on other lights") 
elseif timebetween(Srise,Sset) and tonumber(otherdevices['Lux woonkamer']) > tonumber(13000) and otherdevices['Verlichting - Eettafel dimmer'] == 'On'  and otherdevices['Verlichting - TV'] == 'On' and otherdevices['Verlichting - Piano'] == 'On' and otherdevices['Verlichting - Bank'] == 'On' then
            commandArray['Verlichting - TV'] = 'Off'
            commandArray['Verlichting - Piano'] = 'Off'
            commandArray['Verlichting - Bank'] = 'Off' 
        print("Low light ended, turn off other lights") 
end
return commandArray
The log states:

Code: Select all

2023-01-06 17:10:00.666 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:11:00.352 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:12:00.392 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:13:00.373 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:14:00.384 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:15:00.402 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:16:00.409 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:17:00.427 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:18:00.459 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
2023-01-06 17:19:00.514 Error: EventSystem: in Verlichting - low light: [string "function timebetween(s,e) ..."]:16: field 'sec' is not an integer
What could be causing these problems? Has there been a lua change recently?

Re: Lua scripts suddenly not working anymore

Posted: Friday 06 January 2023 17:23
by willemd
I did not look at your script, but does it take into account a year change?

Re: Lua scripts suddenly not working anymore

Posted: Friday 06 January 2023 19:32
by S10NL
Found it!

The script refers to the variable [Srise] and [Sset] which contains astronomical sunset and sundown.
These variables werent retrieved correctly and thus the script failed on the parsing