Guest User

Untitled

a guest
Apr 6th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. --[[
  2. -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  3.  
  4. @ script_time_heating.lua
  5. @ author : Siewert Lameijer
  6. @ since : 1-1-2015
  7. @ updated : 5-4-2017
  8. @ Script to switch ON/OFF heating when someone @ home or not
  9.  
  10. -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  11. --]]
  12.  
  13. -- Someonehome Switch
  14. local someonehome = 'Iemand Thuis'
  15. local nobody_home = 'Niemand Thuis'
  16.  
  17. -- Nest Various
  18. local nest_setpoint = 'Nest - Setpoint'
  19. local nest_room_temp = 'Nest - Temp + Hum'
  20. local nest_setpoint_idx = 77
  21. local setpoint_low = 17
  22. local setpoint_high = 21
  23. local max_trigger_temp_day = 20.5
  24.  
  25. --
  26. -- **********************************************************
  27. -- Is weekend?
  28. -- **********************************************************
  29. -- weekday [0-6 = Sunday-Saturday]
  30.  
  31. function IsWeekend()
  32. local dayNow = tonumber(os.date("%w"))
  33. local weekend
  34. if (dayNow == 0) or (dayNow == 5) or (dayNow == 6) then weekend = 1
  35. else weekend = 0
  36. end
  37. return weekend
  38. end
  39.  
  40. --
  41. -- **********************************************************
  42. -- Time Between
  43. -- **********************************************************
  44. --
  45.  
  46. function timebetween(s,e)
  47. timenow = os.date("*t")
  48. year = timenow.year
  49. month = timenow.month
  50. day = timenow.day
  51. s = s .. ":00"
  52. e = e .. ":00"
  53. shour = string.sub(s, 1, 2)
  54. sminutes = string.sub(s, 4, 5)
  55. sseconds = string.sub(s, 7, 8)
  56. ehour = string.sub(e, 1, 2)
  57. eminutes = string.sub(e, 4, 5)
  58. eseconds = string.sub(e, 7, 8)
  59. t1 = os.time()
  60. t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
  61. t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds}
  62. sdifference = os.difftime (t1, t2)
  63. edifference = os.difftime (t1, t3)
  64. isbetween = false
  65. if sdifference >= 0 and edifference <= 0 then
  66. isbetween = true
  67. end
  68. return isbetween
  69. end
  70.  
  71. --
  72. -- **********************************************************
  73. --
  74. -- **********************************************************
  75. --
  76.  
  77. presence = (otherdevices['Laptops'] == 'On' or otherdevices['Televisie'] == 'On' or otherdevices['Visite'] == 'On' or otherdevices['Telefoons'] == 'On')
  78. weekend = IsWeekend()
  79.  
  80. setpoint_current_temp = tonumber(otherdevices_svalues[nest_setpoint])
  81.  
  82. sNestTemp, sNestHumidity = otherdevices_svalues[nest_room_temp]:match("([^;]+);([^;]+)")
  83. sNestTemp = tonumber(sNestTemp)
  84. sNestHumidity = tonumber(sNestHumidity)
  85.  
  86. commandArray = {}
  87.  
  88. --
  89. -- **********************************************************
  90. -- Turn heating ON when SomeOneHome and is weekend @daytime
  91. -- **********************************************************
  92. --
  93.  
  94. if presence
  95. and setpoint_current_temp == setpoint_low
  96. and sNestTemp <= max_trigger_temp_day
  97. and timebetween("07:30:00","18:00:00")
  98. and weekend == 1
  99. then
  100. commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
  101. end
  102.  
  103. --
  104. -- **********************************************************
  105. -- Turn heating ON when SomeOneHome and IsNot weekend @daytime
  106. -- **********************************************************
  107. --
  108.  
  109. if presence
  110. and setpoint_current_temp == setpoint_low
  111. and sNestTemp <= max_trigger_temp_day
  112. and timebetween("08:00:00","18:00:00")
  113. and weekend == 0
  114. then
  115. commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
  116. end
  117.  
  118. --
  119. -- **********************************************************
  120. -- Turn heating ON when SomeOneHome @nightime
  121. -- **********************************************************
  122. --
  123.  
  124. if presence
  125. and setpoint_current_temp == setpoint_low
  126. and sNestTemp <= setpoint_high
  127. and timebetween("18:00:01","22:30:00")
  128. then
  129. commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
  130. end
  131.  
  132. --
  133. -- **********************************************************
  134. -- Turn heating OFF when Nobody at home
  135. -- **********************************************************
  136. --
  137.  
  138. if otherdevices[nobody_home] == 'On' and setpoint_current_temp ~= setpoint_low then
  139. commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_low..""
  140. end
  141.  
  142. return commandArray
Advertisement
Add Comment
Please, Sign In to add comment