Time based Lua script

cjnicholl
Posts: 75
Joined: Thursday 06 November 2014 16:59
Target OS: Linux
Domoticz version: 2564
Contact:

Re: Time based Lua script

Post by cjnicholl » Friday 30 January 2015 18:29

I'm guessing it's machine based but how many scripts is it possible to have running at any one time?

User avatar
stef62376
Posts: 31
Joined: Friday 12 December 2014 23:51
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: Time based Lua script

Post by stef62376 » Friday 20 February 2015 9:28

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

D'rMorris
Posts: 301
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Time based Lua script

Post by D'rMorris » Friday 20 February 2015 12:00

Absolutely true, my bad :).

Danny94
Posts: 12
Joined: Monday 18 January 2016 19:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Time based Lua script

Post by Danny94 » Thursday 11 February 2016 0:25

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
3x Hue Lux, 1x Hue Ambiance, 1x Hue rgbwstrip, 1x Hue Iris, 4x KiKa, KiKa doorbell
Raspberry Pi 3, RFXtrx433 USB

lukbe
Posts: 18
Joined: Saturday 06 May 2017 22:46
Target OS: Raspberry Pi
Domoticz version: 3.8153
Contact:

Re: Time based Lua script

Post by lukbe » Monday 08 May 2017 19:36

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests