Trying to modify a thermostat script
Posted: Wednesday 10 February 2016 17:03
Hi there!
I've been trying to modify this thermostatscript made by Alexandre DUBOIS to include time. As my skills are low, I'm without success so far. The script starts at anytime and doesn't end when I want it to. Any ideas?
-- Alexandre DUBOIS - 2014
-- This script keeps the room temperature between 19 °C and 21 °C when the virtual switch 'Lounge Thermostat' is on
--------------------------------
------ Variables to edit ------
--------------------------------
local setpoint = 20 --Setpoint temperature
local hysteresis = 0.5 --Threshold to prevent the relay keeps switching in 2 directions
local sensor = 'Soverom' --Name of the temperature sensor
local thermostat = 'DUMMY Soverom' --Name of the virtual switch of the thermostat
local heater = 'Varmeovn soverom' --Name heater to turn on/off
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
--The sensor emits every 40 seconds. This will be approximately the frequency of execution of the script.
if (devicechanged[sensor]) then
print('Device changed')
temperature = tonumber(devicechanged[sensor..'_Temperature']) --Temperature is raised in the lounge only if the "Thermostat" is on
time = os.date("*t")
if (otherdevices[thermostat]=='On') then
print('--- Termostat styrer oppvarming av soverom ---')
if (temperature < (setpoint - hysteresis)) and ((time.hour >= 15) and (time.hour <= 16)) then
print('Oppvarming av soverom')
commandArray[heater]='On'
elseif (temperature > (setpoint + hysteresis)) or ((time.hour > 16)) then
print('Stopper oppvarming av soverom')
commandArray[heater]='Off'
end
end
end
return commandArray
I've been trying to modify this thermostatscript made by Alexandre DUBOIS to include time. As my skills are low, I'm without success so far. The script starts at anytime and doesn't end when I want it to. Any ideas?
-- Alexandre DUBOIS - 2014
-- This script keeps the room temperature between 19 °C and 21 °C when the virtual switch 'Lounge Thermostat' is on
--------------------------------
------ Variables to edit ------
--------------------------------
local setpoint = 20 --Setpoint temperature
local hysteresis = 0.5 --Threshold to prevent the relay keeps switching in 2 directions
local sensor = 'Soverom' --Name of the temperature sensor
local thermostat = 'DUMMY Soverom' --Name of the virtual switch of the thermostat
local heater = 'Varmeovn soverom' --Name heater to turn on/off
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
--The sensor emits every 40 seconds. This will be approximately the frequency of execution of the script.
if (devicechanged[sensor]) then
print('Device changed')
temperature = tonumber(devicechanged[sensor..'_Temperature']) --Temperature is raised in the lounge only if the "Thermostat" is on
time = os.date("*t")
if (otherdevices[thermostat]=='On') then
print('--- Termostat styrer oppvarming av soverom ---')
if (temperature < (setpoint - hysteresis)) and ((time.hour >= 15) and (time.hour <= 16)) then
print('Oppvarming av soverom')
commandArray[heater]='On'
elseif (temperature > (setpoint + hysteresis)) or ((time.hour > 16)) then
print('Stopper oppvarming av soverom')
commandArray[heater]='Off'
end
end
end
return commandArray