For such think I like use 1 minute interval but if you want better reaction you can set less time like 30 or 15s oryou can adjust further this script e.g. you can choose Resident 0s and create auto adjusting the time for next calculation like below:
You can also disable this script if heating controller is off.
Code:
valveStatesTag = 'circulation_pump'
pumpGA = '1/1/10'
opened, first_timestamp = false, 0
valveStates = grp.tag(valveStatesTag)
for v = 1, #valveStates, 1 do
valveState = valveStates[v]
if valveState.value then
opened = true
if first_timestamp > 0 then
if first_timestamp > valveState.updatetime then first_timestamp = valveState.updatetime end
else
first_timestamp = valveState.updatetime
end
end
end
if opened then
opened_5_minutes = (os.microtime() - first_timestamp) >= 300
if opened_5_minutes then
grp.checkwrite(pumpGA, true)
nextCalculationAfter = 30
else
grp.checkwrite(pumpGA, false)
nextCalculationAfter = 301 - (os.microtime() - first_timestamp) -- run a little after possible change
end
else
grp.checkwrite(pumpGA, false)
nextCalculationAfter = 301
end
log('Next calculation after: ' .. nextCalculationAfter .. 's.')
os.sleep(nextCalculationAfter)
You can also disable this script if heating controller is off.
Done is better than perfect