Time based Lua script

Moderator: leecollings

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

Re: Time based Lua script

Post by cjnicholl »

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: 11
Joined: Friday 12 December 2014 22:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Time based Lua script

Post 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
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Time based Lua script

Post by D'rMorris »

Absolutely true, my bad :).
Danny94
Posts: 7
Joined: Monday 18 January 2016 18:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time based Lua script

Post 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
3x Hue Lux, 1x Hue Ambiance, 1x Hue rgbwstrip, 1x Hue Iris, 4x KiKa, KiKa doorbell
Raspberry Pi 3, RFXtrx433 USB
lukbe
Posts: 16
Joined: Saturday 06 May 2017 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Time based Lua script

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

Who is online

Users browsing this forum: No registered users and 1 guest