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
Trying to modify a thermostat script
Moderator: leecollings
- blackdog65
- Posts: 311
- Joined: Tuesday 17 June 2014 18:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Norfolk, UK
- Contact:
Re: Trying to modify a thermostat script
I created an additional dummy switch (in my case a multi-position for hot water too) and added it in as an another "if" condition then the dummy switch is controlled by timers.
Good luck
Sean
Good luck
Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
Re: Trying to modify a thermostat script
Thanks for the reply. Will try that, but I really would like to learn more about Lua and understand what is wrong with the time code
- havnegata
- Posts: 114
- Joined: Wednesday 10 September 2014 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10162
- Location: Norway
- Contact:
Re: Trying to modify a thermostat script
Thanks for the reply. Will try that, but I really would like to learn more about Lua and understand what is wrong with the time code
- blackdog65
- Posts: 311
- Joined: Tuesday 17 June 2014 18:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Norfolk, UK
- Contact:
Re: Trying to modify a thermostat script
I can't help there as I'm a complete Lua NOOB 

CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
- havnegata
- Posts: 114
- Joined: Wednesday 10 September 2014 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10162
- Location: Norway
- Contact:
Re: Trying to modify a thermostat script
It's working now. I was using too many paranthesis.
It was:
elseif (temperature > (setpoint + hysteresis)) or ((time.hour > 16)) then
It should be:
elseif (temperature > (setpoint + hysteresis)) or (time.hour > 16) then
It was:
elseif (temperature > (setpoint + hysteresis)) or ((time.hour > 16)) then
It should be:
elseif (temperature > (setpoint + hysteresis)) or (time.hour > 16) then
- havnegata
- Posts: 114
- Joined: Wednesday 10 September 2014 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10162
- Location: Norway
- Contact:
Re: Trying to modify a thermostat script
Seems I was a little quick on cheering... Suddenly the heater turned on again, which it was not supposed to do..
Oh well, back to searching the forum, and hopefully some of you can pinpoint my fault
Oh well, back to searching the forum, and hopefully some of you can pinpoint my fault

- havnegata
- Posts: 114
- Joined: Wednesday 10 September 2014 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10162
- Location: Norway
- Contact:
Re: Trying to modify a thermostat script
With the help of jvdz and his example of a time function I managed to achieve my goal. This is a wonderful forum!
function timebetween(s,e)
timenow = os.date("*t")
year = timenow.year
month = timenow.month
day = timenow.day
s = s .. ":00" -- add seconds in case only hh:mm is supplied
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
--~ print(" s:" .. s .. " e:" .. e .. " sdifference:" .. sdifference.. " edifference:" .. edifference)
return isbetween
end
commandArray = {}
if timebetween("09:15:00","09:44:00") then
--- perform action
end
return commandArray
function timebetween(s,e)
timenow = os.date("*t")
year = timenow.year
month = timenow.month
day = timenow.day
s = s .. ":00" -- add seconds in case only hh:mm is supplied
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
--~ print(" s:" .. s .. " e:" .. e .. " sdifference:" .. sdifference.. " edifference:" .. edifference)
return isbetween
end
commandArray = {}
if timebetween("09:15:00","09:44:00") then
--- perform action
end
return commandArray
Who is online
Users browsing this forum: No registered users and 1 guest