Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Domoticz passes information to scripts through a number of global tables
- --
- -- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
- -- otherdevices['yourotherdevicename'] = "On"
- -- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
- -- otherdevices_svalues['yourotherthermometer'] = string of svalues
- --
- -- uservariables and uservariables_lastupdate are arrays for all user variables:
- -- uservariables['yourvariablename'] = 'Test Value'
- -- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
- --
- -- other useful details are contained in the timeofday table
- -- timeofday['Nighttime'] = true or false
- -- timeofday['SunriseInMinutes'] = number
- -- timeofday['Daytime'] = true or false
- -- timeofday['SunsetInMinutes'] = number
- -- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
- --
- -- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
- -- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
- --
- -- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
- --
- print ("Time based event fired");
- -- loop through all the devices
- for deviceName,deviceValue in pairs(otherdevices) do
- -- if (deviceName=='myDevice') then
- -- if deviceValue == "On" then
- -- print("Device is On")
- -- elseif deviceValue == "Off" then
- -- commandArray['a device name'] = "On"
- -- commandArray['Scene:MyScene'] = "Off"
- -- end
- -- end
- end
- -- loop through all the variables
- for variableName,variableValue in pairs(uservariables) do
- -- if (variableName=='myVariable') then
- -- if variableValue == 1 then
- -- commandArray['a device name'] = "On"
- -- commandArray['Group:My Group'] = "Off AFTER 30"
- -- end
- -- end
- end
- 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)
- 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 = {}
- -- w nocy tryb nocny, w dzień tryb auto
- if (uservariables["airpower"] == 1 and uservariables["silent"] == 0 and uservariables["airauto"] == 1 and timebetween("00:00:00","05:59:00")) then
- commandArray['Oczyszczacz - Source']='Set Level: 10' --Silent (Tryb nocny)
- commandArray['Variable:noc']='1'
- commandArray['Variable:ON_25.75']='0'
- commandArray['Variable:ON_10.25']='0'
- print ("Oczyszczacz - tryb nocny")
- elseif (uservariables["airpower"] == 1 and uservariables["idle"] == 0 and uservariables["airauto"] == 1 and uservariables["ON_25.75"] == 0 and uservariables["ON_10.25"] == 0 and timebetween("06:00:00","22:00:00")) then
- commandArray['Oczyszczacz - Source']='Set Level: 30' --Idle (Tryb automatyczny)
- commandArray['Variable:noc']='0'
- print ("Oczyszczacz - tryb auto")
- elseif (uservariables["airpower"] == 1 and uservariables["silent"] == 0 and uservariables["airauto"] == 1 and timebetween("22:01:00","23:59:00")) then
- commandArray['Oczyszczacz - Source']='Set Level: 10' --Silent (Tryb nocny)
- commandArray['Variable:noc']='1'
- commandArray['Variable:ON_25.75']='0'
- commandArray['Variable:ON_10.25']='0'
- print ("Oczyszczacz - tryb nocny")
- end
- --wyłączenie i włączenie oczyczacza w zależności od stanu powietrza
- if (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["dobrepowietrze"] == 1) then
- commandArray['Oczyszczacz - Power']='Off'
- print ("Dobre powietrze - oczyszczacz wyłączony")
- commandArray['Variable:silent']='0'
- commandArray['Variable:idle']='0'
- commandArray['Variable:favorite']='0'
- elseif (uservariables["airauto"] == 1 and uservariables["dobrepowietrze"] == 0 and uservariables["airpower"] == 0) then
- commandArray['Oczyszczacz - Power']='On'
- print ("Słabe powietrze - oczyszczacz włączony")
- end
- --od 25 do 75 pm 2.5 tryb favorite 2 (poza tym zakresem tryb auto)
- if (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["25.75"] == 1 and uservariables["ON_25.75"] == 0 and uservariables["10.25"] == 0) then
- commandArray['Oczyszczacz - Source']='Set Level: 20' --Favorite (Tryb ulubiony)
- commandArray['Oczyszczacz - Fan Favorite level']='Set Level 14' --Wybór favorite 2
- commandArray['Variable:ON_25.75']='1'
- print ("Oczyszczacz - tryb favorite 2 włączony (pm 2.5 od 25 do 75)")
- elseif (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["25.75"] == 0) then
- commandArray['Variable:ON_25.75']='0'
- print ("Oczyszczacz - tryb favorite 2 wyłączony (pm 2.5 różne od 25 do 75)")
- end
- --od 10 do 25 pm 2.5 tryb favorite 1 (poza tym zakresem tryb auto)
- if (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["10.25"] == 1 and uservariables["ON_10.25"] == 0 and uservariables["25.75"] == 0) then
- commandArray['Oczyszczacz - Source']='Set Level: 20' --Favorite (Tryb ulubiony)
- commandArray['Oczyszczacz - Fan Favorite level']='Set Level 7' --Wybór favorite 1
- commandArray['Variable:ON_10.25']='1'
- print ("Oczyszczacz - tryb favorite 1 włączony (pm 2.5 od 10 do 25)")
- elseif (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["10.25"] == 0) then
- commandArray['Variable:ON_10.25']='0'
- print ("Oczyszczacz - tryb favorite 1 wyłączony (pm 2.5 różne od 10 do 25)")
- end
- return commandArray
Advertisement
Add Comment
Please, Sign In to add comment