Page 2 of 2

Re: Time based Lua script

Posted: Friday 30 January 2015 17:29
by cjnicholl
I'm guessing it's machine based but how many scripts is it possible to have running at any one time?

Re: Time based Lua script

Posted: Friday 20 February 2015 8:28
by stef62376
Actually you should add and (time.hour > 12) to the elseif statement for evening, otherwise it switches to evening again after midnight:

Code: Select all

time = os.date("*t")

commandArray = {}

if (timeofday['Daytime']) and (time.hour < 12) then

        commandArray['Variable:Time-Variable']='Morning'
        print("Time set to Morning")

elseif (timeofday['Daytime']) and (time.hour >= 12) then

        commandArray['Variable:Time-Variable']='Afternoon'
        print("Time set to Afternoon")

elseif (timeofday['Nighttime']) and (time.hour < 23) and (time.hour > 12) then

        commandArray['Variable:Time-Variable']='Evening'
        print("Time set to Evening")

elseif (timeofday['Nighttime']) then

        commandArray['Variable:Time-Variable']='Night'
        print("Time set to Night")
end

return commandArray

Re: Time based Lua script

Posted: Friday 20 February 2015 11:00
by D'rMorris
Absolutely true, my bad :).

Re: Time based Lua script

Posted: Wednesday 10 February 2016 23:25
by Danny94
When the variable is allready set to the current time of the day, it does not have to do it, and print a log again every minute.
Maybe add this to each IF?

Code: Select all

if (timeofday['Daytime']) and (time.hour < 12) then
to

Code: Select all

if (timeofday['Daytime']) and (time.hour < 12) and uservariables["Time-Variable"] ~= "Morning" then

Re: Time based Lua script

Posted: Monday 08 May 2017 19:36
by lukbe
Hello, is possible write in LUA script which will be executed for example every 30? I know that 1 minute is not problem, howewer i would like do script in lua which will be called every 30 or 20 seconds. Thank you