blackscreener

Domoticz - xiaomi purifier 2s

May 7th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.33 KB | None | 0 0
  1. --
  2. -- Domoticz passes information to scripts through a number of global tables
  3. --
  4. -- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
  5. --   otherdevices['yourotherdevicename'] = "On"
  6. --   otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
  7. --   otherdevices_svalues['yourotherthermometer'] = string of svalues
  8. --
  9. -- uservariables and uservariables_lastupdate are arrays for all user variables:
  10. --   uservariables['yourvariablename'] = 'Test Value'
  11. --   uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
  12. --
  13. -- other useful details are contained in the timeofday table
  14. --   timeofday['Nighttime'] = true or false
  15. --   timeofday['SunriseInMinutes'] = number
  16. --   timeofday['Daytime'] = true or false
  17. --   timeofday['SunsetInMinutes'] = number
  18. --   globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
  19. --
  20. -- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
  21. -- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
  22. --
  23. -- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
  24. --
  25.  
  26.  
  27. print ("Time based event fired");
  28. -- loop through all the devices
  29. for deviceName,deviceValue in pairs(otherdevices) do
  30. --    if (deviceName=='myDevice') then
  31. --        if deviceValue == "On" then
  32. --            print("Device is On")
  33. --        elseif deviceValue == "Off" then
  34. --            commandArray['a device name'] = "On"
  35. --            commandArray['Scene:MyScene'] = "Off"
  36. --        end
  37. --    end
  38. end
  39.  
  40. -- loop through all the variables
  41. for variableName,variableValue in pairs(uservariables) do
  42. --    if (variableName=='myVariable') then
  43. --        if variableValue == 1 then
  44. --            commandArray['a device name'] = "On"
  45. --            commandArray['Group:My Group'] = "Off AFTER 30"
  46. --        end
  47. --    end
  48. end
  49.  
  50. function timebetween(s,e)
  51.     timenow = os.date("*t")
  52.     year = timenow.year
  53.     month = timenow.month
  54.     day = timenow.day
  55.     s = s .. ":00"  -- add seconds in case only hh:mm is supplied
  56.     e = e .. ":00"
  57.     shour = string.sub(s, 1, 2)
  58.     sminutes = string.sub(s, 4, 5)
  59.     sseconds = string.sub(s, 7, 8)
  60.     ehour = string.sub(e, 1, 2)
  61.     eminutes = string.sub(e, 4, 5)
  62.     eseconds = string.sub(e, 7, 8)
  63.     t1 = os.time()
  64.     t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
  65.     t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds}
  66.     sdifference = os.difftime (t1, t2)
  67.     edifference = os.difftime (t1, t3)
  68.     isbetween = false
  69.     if sdifference >= 0 and edifference <= 0 then
  70.         isbetween = true
  71.     end
  72.     print(" s:" .. s  .. "  e:" .. e .. "  sdifference:" .. sdifference.. "  edifference:" .. edifference)
  73.     return isbetween
  74. end
  75.  
  76.  
  77. commandArray = {}
  78.  
  79. -- w nocy tryb nocny, w dzień tryb auto
  80. if (uservariables["airpower"] == 1 and uservariables["silent"] == 0 and uservariables["airauto"] == 1 and  timebetween("00:00:00","05:59:00")) then
  81.     commandArray['Oczyszczacz - Source']='Set Level: 10' --Silent (Tryb nocny)
  82.     commandArray['Variable:noc']='1'
  83.     commandArray['Variable:ON_25.75']='0'
  84.     commandArray['Variable:ON_10.25']='0'
  85.     print ("Oczyszczacz - tryb nocny")
  86. 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
  87.     commandArray['Oczyszczacz - Source']='Set Level: 30' --Idle (Tryb automatyczny)
  88.     commandArray['Variable:noc']='0'
  89.     print ("Oczyszczacz - tryb auto")
  90. elseif (uservariables["airpower"] == 1 and uservariables["silent"] == 0 and uservariables["airauto"] == 1 and timebetween("22:01:00","23:59:00")) then
  91.     commandArray['Oczyszczacz - Source']='Set Level: 10' --Silent (Tryb nocny)
  92.     commandArray['Variable:noc']='1'
  93.     commandArray['Variable:ON_25.75']='0'
  94.     commandArray['Variable:ON_10.25']='0'
  95.     print ("Oczyszczacz - tryb nocny")
  96. end
  97.  
  98. --wyłączenie i włączenie oczyczacza w zależności od stanu powietrza
  99. if (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["dobrepowietrze"] == 1)  then
  100.     commandArray['Oczyszczacz - Power']='Off'
  101.     print ("Dobre powietrze - oczyszczacz wyłączony")
  102.     commandArray['Variable:silent']='0'
  103.     commandArray['Variable:idle']='0'
  104.     commandArray['Variable:favorite']='0'
  105. elseif (uservariables["airauto"] == 1 and uservariables["dobrepowietrze"] == 0 and uservariables["airpower"] == 0)  then
  106.     commandArray['Oczyszczacz - Power']='On'
  107.     print ("Słabe powietrze - oczyszczacz włączony")
  108. end
  109.  
  110. --od 25 do 75 pm 2.5 tryb favorite 2 (poza tym zakresem tryb auto)
  111. 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
  112.     commandArray['Oczyszczacz - Source']='Set Level: 20' --Favorite (Tryb ulubiony)
  113.     commandArray['Oczyszczacz - Fan Favorite level']='Set Level 14' --Wybór favorite 2
  114.     commandArray['Variable:ON_25.75']='1'
  115.     print ("Oczyszczacz - tryb favorite 2 włączony (pm 2.5 od 25 do 75)")
  116. elseif (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["25.75"] == 0) then
  117.     commandArray['Variable:ON_25.75']='0'
  118.     print ("Oczyszczacz - tryb favorite 2 wyłączony (pm 2.5 różne od 25 do 75)")
  119. end
  120.  
  121. --od 10 do 25 pm 2.5 tryb favorite 1 (poza tym zakresem tryb auto)
  122. 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
  123.     commandArray['Oczyszczacz - Source']='Set Level: 20' --Favorite (Tryb ulubiony)
  124.     commandArray['Oczyszczacz - Fan Favorite level']='Set Level 7' --Wybór favorite 1
  125.     commandArray['Variable:ON_10.25']='1'
  126.     print ("Oczyszczacz - tryb favorite 1 włączony (pm 2.5 od 10 do 25)")
  127. elseif (uservariables["airpower"] == 1 and uservariables["airauto"] == 1 and uservariables["noc"] == 0 and uservariables["10.25"] == 0) then
  128.     commandArray['Variable:ON_10.25']='0'
  129.     print ("Oczyszczacz - tryb favorite 1 wyłączony (pm 2.5 różne od 10 do 25)")
  130. end
  131.  
  132. return commandArray
Advertisement
Add Comment
Please, Sign In to add comment