Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
- @ script_time_heating.lua
- @ author : Siewert Lameijer
- @ since : 1-1-2015
- @ updated : 5-4-2017
- @ Script to switch ON/OFF heating when someone @ home or not
- -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
- --]]
- -- Someonehome Switch
- local someonehome = 'Iemand Thuis'
- local nobody_home = 'Niemand Thuis'
- -- Nest Various
- local nest_setpoint = 'Nest - Setpoint'
- local nest_room_temp = 'Nest - Temp + Hum'
- local nest_setpoint_idx = 77
- local setpoint_low = 17
- local setpoint_high = 21
- local max_trigger_temp_day = 20.5
- --
- -- **********************************************************
- -- Is weekend?
- -- **********************************************************
- -- weekday [0-6 = Sunday-Saturday]
- function IsWeekend()
- local dayNow = tonumber(os.date("%w"))
- local weekend
- if (dayNow == 0) or (dayNow == 5) or (dayNow == 6) then weekend = 1
- else weekend = 0
- end
- return weekend
- end
- --
- -- **********************************************************
- -- Time Between
- -- **********************************************************
- --
- function timebetween(s,e)
- timenow = os.date("*t")
- year = timenow.year
- month = timenow.month
- day = timenow.day
- s = s .. ":00"
- 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
- return isbetween
- end
- --
- -- **********************************************************
- --
- -- **********************************************************
- --
- presence = (otherdevices['Laptops'] == 'On' or otherdevices['Televisie'] == 'On' or otherdevices['Visite'] == 'On' or otherdevices['Telefoons'] == 'On')
- weekend = IsWeekend()
- setpoint_current_temp = tonumber(otherdevices_svalues[nest_setpoint])
- sNestTemp, sNestHumidity = otherdevices_svalues[nest_room_temp]:match("([^;]+);([^;]+)")
- sNestTemp = tonumber(sNestTemp)
- sNestHumidity = tonumber(sNestHumidity)
- commandArray = {}
- --
- -- **********************************************************
- -- Turn heating ON when SomeOneHome and is weekend @daytime
- -- **********************************************************
- --
- if presence
- and setpoint_current_temp == setpoint_low
- and sNestTemp <= max_trigger_temp_day
- and timebetween("07:30:00","18:00:00")
- and weekend == 1
- then
- commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command¶m=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
- end
- --
- -- **********************************************************
- -- Turn heating ON when SomeOneHome and IsNot weekend @daytime
- -- **********************************************************
- --
- if presence
- and setpoint_current_temp == setpoint_low
- and sNestTemp <= max_trigger_temp_day
- and timebetween("08:00:00","18:00:00")
- and weekend == 0
- then
- commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command¶m=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
- end
- --
- -- **********************************************************
- -- Turn heating ON when SomeOneHome @nightime
- -- **********************************************************
- --
- if presence
- and setpoint_current_temp == setpoint_low
- and sNestTemp <= setpoint_high
- and timebetween("18:00:01","22:30:00")
- then
- commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command¶m=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""
- end
- --
- -- **********************************************************
- -- Turn heating OFF when Nobody at home
- -- **********************************************************
- --
- if otherdevices[nobody_home] == 'On' and setpoint_current_temp ~= setpoint_low then
- commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command¶m=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_low..""
- end
- return commandArray
Advertisement
Add Comment
Please, Sign In to add comment