Hello,
I have a script for my floor heating pump. But the 'nalooptijd' of 10 min. are not in.
Can someone fix this? I have no experience with lua
script:
logging = true
function log (level, message)
file = io.open("/ram/domoticz.log", "a")
file:write(string.format("%s %-5s: LUA : %s\n", os.date("%m/%d/%Y %I:%M:%S %p"),level, message))
io.close(file)
end
AfterOff = 900
Vloer_Retour = 'Vloer_Retour'
Vloer_Aanvoer = 'Vloer_Aanvoer'
Pomp = 'Pomp'
commandArray = {}
PumpOn = tonumber(uservariables['PumpOn'])
-- if one of the sensor temps changed, do our thing
if ( devicechanged[Vloer_Retour] or devicechanged[Vloer_Aanvoer] ) then
time = os.time() -- Current time (integer sec)
dt_in = otherdevices[Vloer_Aanvoer] -- Get in temp
dt_out = otherdevices[Vloer_Retour] -- Get out temp
dt = dt_in - dt_out -- calculate diff
if (logging) then print("INFO",string.format("t_out %.2f t_in %.2f dt %.2f Pomp: %s OnTime: %d", dt_out, dt_in, dt, otherdevices[Pomp], time - PumpOn)) end
-- if temp difference > 1 degree celcius, immediatly tunr on Pump
if (dt > 1) then
-- update time we last turned "On" the pump
PumpOn = os.time()
if (otherdevices[Pomp] == "Off") then
commandArray[Pomp] = "On"
end
else
-- must me lower/equal 1 degree, see if minimum pump "On" time exeeded
if ( (os.time() - PumpOn) >= AfterOff ) then
if (otherdevices[Pomp] == "On") then
commandArray[Pomp] = "Off"
end
end
end
end
commandArray['Variable:PumpOn'] = tostring(PumpOn)
return commandArray
Add "nalooptijd" in a lua script
Moderator: leecollings
-
- Posts: 8
- Joined: Wednesday 13 April 2016 10:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
-
- Posts: 673
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: Add "nalooptijd" in a lua script
Why not use something like Off AFTER?
Verstuurd vanaf mijn SM-G930F met Tapatalk
Verstuurd vanaf mijn SM-G930F met Tapatalk
-
- Posts: 8
- Joined: Wednesday 13 April 2016 10:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Add "nalooptijd" in a lua script
Sorry, I mean, if the pump is switched off for >24 hours, then the pump switch on 10 min.
- jvdz
- Posts: 2332
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Add "nalooptijd" in a lua script
Something like this should work assuming some device will trigger it. I've also moved the updating of the variable inside the if or else it will update each time the script is ran.
Jos
Code: Select all
commandArray = {}
logging = true
function log(level, message)
file = io.open("/ram/domoticz.log", "a")
file:write(string.format("%s %-5s: LUA : %s\n", os.date("%m/%d/%Y %I:%M:%S %p"), level, message))
io.close(file)
end
-- Function to return the number of seconds the device was last changed
function datetimedifferencenow(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year = year, month = month, day = day, hour = hour, min = minutes, sec = seconds}
difference = os.difftime(t1, t2)
return difference
end
AfterOff = 900
Vloer_Retour = 'Vloer_Retour'
Vloer_Aanvoer = 'Vloer_Aanvoer'
Pomp = 'Pomp'
commandArray = {}
-- if pomp didn't change in the last 24 hours then activate for 10 minutes
if (datetimedifferencenow(Pomp) > 60*60*24) then
commandArray[Pomp] = "On for 10"
end
if (devicechanged[Vloer_Retour] or devicechanged[Vloer_Aanvoer]) then
PumpOn = tonumber(uservariables['PumpOn'])
-- if one of the sensor temps changed, do our thing
time = os.time() -- Current time (integer sec)
dt_in = otherdevices[Vloer_Aanvoer] -- Get in temp
dt_out = otherdevices[Vloer_Retour] -- Get out temp
dt = dt_in - dt_out -- calculate diff
if (logging) then print("INFO", string.format("t_out %.2f t_in %.2f dt %.2f Pomp: %s OnTime: %d", dt_out, dt_in, dt, otherdevices[Pomp], time - PumpOn)) end
-- if temp difference > 1 degree celcius, immediatly tunr on Pump
if (dt > 1) then
-- update time we last turned "On" the pump
PumpOn = os.time()
if (otherdevices[Pomp] == "Off") then
commandArray[Pomp] = "On"
end
else
-- must me lower/equal 1 degree, see if minimum pump "On" time exeeded
if ((os.time() - PumpOn) >= AfterOff) then
if (otherdevices[Pomp] == "On") then
commandArray[Pomp] = "Off"
end
end
end
commandArray['Variable:PumpOn'] = tostring(PumpOn)
end
return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 8
- Joined: Wednesday 13 April 2016 10:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Add "nalooptijd" in a lua script
Thanks!!, But now getting a error:
string "commandArray = {} ..."]:20: field 'day' missing in date table
Frank
string "commandArray = {} ..."]:20: field 'day' missing in date table
Frank
- jvdz
- Posts: 2332
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Add "nalooptijd" in a lua script
Ah, I see indeed I made a mistake. It didn't retrieve the lastchanged date/time information for pomp.
I can't test the script myself
... so here is an update for you to test:
Jos
I can't test the script myself

Code: Select all
logging = true
function log(level, message)
file = io.open("/ram/domoticz.log", "a")
file:write(string.format("%s %-5s: LUA : %s\n", os.date("%m/%d/%Y %I:%M:%S %p"), level, message))
io.close(file)
end
-- Function to return the number of seconds the device was last changed
function datetimedifferencenow(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year = year, month = month, day = day, hour = hour, min = minutes, sec = seconds}
difference = os.difftime(t1, t2)
return difference
end
AfterOff = 900
Vloer_Retour = 'Vloer_Retour'
Vloer_Aanvoer = 'Vloer_Aanvoer'
Pomp = 'Pomp'
commandArray = {}
-- if pomp didn't change in the last 24 hours then activate for 10 minutes
if (datetimedifferencenow(otherdevices_lastupdate[Pomp]) > 60*60*24) then
commandArray[Pomp] = "On for 10"
end
if (devicechanged[Vloer_Retour] or devicechanged[Vloer_Aanvoer]) then
PumpOn = tonumber(uservariables['PumpOn'])
-- if one of the sensor temps changed, do our thing
time = os.time() -- Current time (integer sec)
dt_in = otherdevices[Vloer_Aanvoer] -- Get in temp
dt_out = otherdevices[Vloer_Retour] -- Get out temp
dt = dt_in - dt_out -- calculate diff
if (logging) then print("INFO", string.format("t_out %.2f t_in %.2f dt %.2f Pomp: %s OnTime: %d", dt_out, dt_in, dt, otherdevices[Pomp], time - PumpOn)) end
-- if temp difference > 1 degree celcius, immediatly tunr on Pump
if (dt > 1) then
-- update time we last turned "On" the pump
PumpOn = os.time()
if (otherdevices[Pomp] == "Off") then
commandArray[Pomp] = "On"
end
else
-- must me lower/equal 1 degree, see if minimum pump "On" time exeeded
if ((os.time() - PumpOn) >= AfterOff) then
if (otherdevices[Pomp] == "On") then
commandArray[Pomp] = "Off"
end
end
end
commandArray['Variable:PumpOn'] = tostring(PumpOn)
end
return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 8
- Joined: Wednesday 13 April 2016 10:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Add "nalooptijd" in a lua script
Works fine!! Thanks! 
Frank

Frank
-
- Posts: 53
- Joined: Wednesday 22 March 2017 9:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Contact:
Re: Add "nalooptijd" in a lua script
What do you use to read the temperatures? I currently check my Nest to see if the heating is on, but I have to guess the extra time the pump needs to run.
Who is online
Users browsing this forum: No registered users and 1 guest