Since winter is coming and I now have door sensors installed and my heating runing through domoticz I started a script today to monitor doors and windows to stop my heating when the door is left open (later option would also be to send a notification)
The script is now setup for 8 doors and windows (just an easy number) and when one or more are open for more than 5 minutes the heater control setpoint is changed, the old value stored in a variable and when all doors and windows are closed again the old setpoint is put back in place.
When the setpoint is changed by this script, I also toggle a virtual switch, which i use to grey out the button to increase the temperature setpoint on my frontpage when the switch is active... and show a little door open icon
Code: Select all
commandArray = {}
-- Purpose of this script is to power down the heating when doors or windows are open for over a number of minutes to safe energy by not heating up the entire globe.
-- The script is now set up for max 8 doors and 8 windows but could be extended to include items like a fire place or air conditioning units.
-- variable to be made is an integer "TempStorage" for temporarely storing the old temperature setpoint when powering down the heating
-- variable to be made is an integer "DoorCounter" to track the time a door is open
-- define the number of doors and windows to be monitored
Door_Count = 2 -- exact number of doors to be monitored (max 8 in current script)
Window_Count = 2 -- exact number of windows to be monitored (max 8 in current script)
Time_Out = 5 -- time in minutes for doors to be open before heating is powered off
Low_Temp = 5 -- setpoint to be used when powering off the heating
THERMOSTAT_NAME = 'WoonkamerSetpoint' -- exact name of thermostat to be changed
TEMP_IDX = 102 -- idx of thermostat to be changed
TEMPDOWN_NAME = 'AutoTempDown' --exact name of virual switch to temp down
TEMPDOWN_IDX = 229 --idx of temp down switch
DOOR_NAME1 = 'VoorDeurSensor' -- exact name of the door to be monitored
DOOR_NAME2 = 'SchuurDeur' -- exact name of the door to be monitored
DOOR_NAME3 = 'AchterDeurSensor' -- exact name of the door to be monitored
DOOR_NAME4 = 'NA' -- exact name of the door to be monitored
DOOR_NAME5 = 'NA' -- exact name of the door to be monitored
DOOR_NAME6 = 'NA' -- exact name of the door to be monitored
DOOR_NAME7 = 'NA' -- exact name of the door to be monitored
DOOR_NAME8 = 'NA' -- exact name of the door to be monitored
WINDOW_NAME1 = 'RaamBenedenVoorLinks' -- exact name of the window to be monitored
WINDOW_NAME2 = 'RaamBenedenVoorRechts' -- exact name of the window to be monitored
WINDOW_NAME3 = 'NA' -- exact name of the window to be monitored
WINDOW_NAME4 = 'NA' -- exact name of the window to be monitored
WINDOW_NAME5 = 'NA' -- exact name of the window to be monitored
WINDOW_NAME6 = 'NA' -- exact name of the window to be monitored
WINDOW_NAME7 = 'NA' -- exact name of the window to be monitored
WINDOW_NAME8 = 'NA' -- exact name of the window to be monitored
PRINT_MODE = true -- when true wil print output notifications to the log
PRINT_MODE_ALL = false -- when true wil print output all data to the log
TEST_MODE = false
-- get the global variables:
Counter = tonumber(uservariables['DoorCounter'])
Temp_Storage = tonumber(uservariables['TempStorage'])
-- Retrieve values from devices
Dev_TempSetpoint = otherdevices_svalues[THERMOSTAT_NAME]
-- create local arrey's to store names and binary values
local DOOR_BIN = {1,1,1,1,1,1,1,1}
local DOOR_NAME = {DOOR_NAME1,DOOR_NAME2,DOOR_NAME3,DOOR_NAME4,DOOR_NAME5,DOOR_NAME6,DOOR_NAME7,DOOR_NAME8}
local WINDOW_BIN = {1,1,1,1,1,1,1,1}
local WINDOW_NAME = {WINDOW_NAME1,WINDOW_NAME2,WINDOW_NAME3,WINDOW_NAME4,WINDOW_NAME5,WINDOW_NAME6,WINDOW_NAME7,WINDOW_NAME8}
-- check if the counter is active and increment if so
if (Counter > 0) then
Counter = Counter+1
if PRINT_MODE == true then
print('Incrementing door counter to ' .. Counter)
end
end
-- check the status of all doors
for i=1, Door_Count, 1 do
if (otherdevices[DOOR_NAME[i]]=='Open') then
DOOR_BIN[i]=0
if PRINT_MODE == true then
print('Door '.. DOOR_NAME[i] ..' is Open')
end
elseif (otherdevices[DOOR_NAME[i]]=='Closed') then
DOOR_BIN[i]=1
if PRINT_MODE == true then
print('Door '.. DOOR_NAME[i] ..' is Closed')
end
else
DOOR_BIN[i]=1
if PRINT_MODE == true then
print('Door '.. DOOR_NAME[i] ..' has an incorrect status')
end
end
end
DOOR_SUM=0
for i=1, 8, 1 do
Current=tonumber(DOOR_BIN[i])
DOOR_SUM=DOOR_SUM+Current
if PRINT_MODE_ALL == true then
print('Door ' .. i .. ' bindary is ' .. DOOR_BIN[i])
print('Doorsum is ' .. DOOR_SUM)
end
end
-- check the status of all windows
for i=1, Window_Count, 1 do
if (otherdevices[WINDOW_NAME[i]]=='Open') then
WINDOW_BIN[i]=0
if PRINT_MODE == true then
print('Window '.. WINDOW_NAME[i] ..' is Open')
end
elseif (otherdevices[WINDOW_NAME[i]]=='Closed') then
WINDOW_BIN[i]=1
if PRINT_MODE == true then
print('Window '.. WINDOW_NAME[i] ..' is Closed')
end
else
WINDOW_BIN[i]=1
if PRINT_MODE == true then
print('Window '.. WINDOW_NAME[i] ..' has an incorrect status')
end
end
end
WINDOW_SUM=0
for i=1, 8, 1 do
Current=tonumber(WINDOW_BIN[i])
WINDOW_SUM=WINDOW_SUM+Current
if PRINT_MODE_ALL == true then
print('Window ' .. i .. ' bindary is ' .. WINDOW_BIN[i])
print('Windowsum is ' .. WINDOW_SUM)
end
end
-- See if the counter has to be started
if (DOOR_SUM + WINDOW_SUM < 16) and (Counter == 0) then
Counter = 1
if PRINT_MODE == true then
if (DOOR_SUM < 8) then
print('DoorSum is ' .. DOOR_SUM)
print('A door has been openend starting counter')
end
if (WINDOW_SUM < 8) then
print('WindowSum is ' .. WINDOW_SUM)
print('A window has been openend starting counter')
end
end
end
-- check if when the counter is running, the doors are open for more than the set limit and the heater has to be powered down
if (Counter == Time_Out) then
if PRINT_MODE == true then
print('A door or window is open for more than the preset time of ' .. Time_Out .. 'Minutes')
end
commandArray[TEMPDOWN_NAME]='On'
-- convert temperature livingroom into numbers
Wu_TempSetpoint = tonumber(Dev_TempSetpoint)
commandArray['Variable:TempStorage'] = tostring(Wu_TempSetpoint)
if PRINT_MODE == true then
print('Storing current heater setpiont of ' .. Wu_TempSetpoint .. 'C')
print('Lowering the heating temperature to ' .. Low_Temp .. 'C')
end
commandArray['UpdateDevice'] = TEMP_IDX .. '|0|' .. Low_Temp
end
-- when the counter is active, check if it has to be set back to 0 because all doors and windows are closed again
if (DOOR_SUM + WINDOW_SUM == 16) then
if PRINT_MODE == true then
print('All doors and windows are closed, check if the counter is runing and need to be stopped')
end
if (otherdevices[TEMPDOWN_NAME] == 'On') then
commandArray[TEMPDOWN_NAME]='Off'
if PRINT_MODE == true then
print('Timer was active for : ' .. Counter .. ' Minutes')
print('Restoring temperature setpoint to: ' .. Temp_Storage .. ' C')
end
commandArray['UpdateDevice'] = TEMP_IDX .. '|0|' .. Temp_Storage
Counter = 0
else
if PRINT_MODE == true then
print('Timer is not active no action needed')
end
end
end
-- save the globals
commandArray['Variable:DoorCounter'] = tostring(Counter)
return commandArray