24.04.2018, 15:30
Code:
valveStatesTagEstate = 'pompa_circolazione_giorno_estate'
valveStatesTagInverno = 'pompa_circolazione_giorno_inverno'
pumpGA = '2/0/1'
openingValveTime = 60 -- time for fully open the valve (maximum time for next calculation)
minInterval = 30 -- minimum offset for next calculation
opened, firstTimestamp = false, 0
if stagione == false then
valveStatesEstate = grp.tag(valveStatesTagEstate)
for v = 1, #valveStatesEstate, 1 do
valveStateEstate = valveStatesEstate[v]
if valveStateEstate.value then
opened = true
if firstTimestamp > 0 then
if firstTimestamp > valveStateEstate.updatetime then firstTimestamp = valveStateEstate.updatetime end
else
firstTimestamp = valveStateEstate.updatetime
end
end
end
else
valveStatesInverno = grp.tag(valveStatesTagInverno)
for v = 1, #valveStatesInverno, 1 do
valveStateInverno = valveStatesInverno[v]
if valveStateInverno.value then
opened = true
if firstTimestamp > 0 then
if firstTimestamp > valveStateInverno.updatetime then firstTimestamp = valveStateInverno.updatetime end
else
firstTimestamp = valveStateInverno.updatetime
end
end
end
end
if opened then
fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime
if fullyOpened then
grp.checkwrite(pumpGA, true)
nextCalculationAfter = minInterval
else
grp.checkwrite(pumpGA, false)
nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change
end
else
grp.checkwrite(pumpGA, false)
nextCalculationAfter = openingValveTime + 1
end
-- log('Next calculation after: ' .. nextCalculationAfter .. 's.')
log(valveStatesEstate)
os.sleep(nextCalculationAfter)
In your opinion what is wrong in this script above. I add a condition to separate winter condition from summer condition.
I log variable log(valveStatesEstate) but the result is nil. Objects tags are correct and in other 2 scripts (the same) everything works fine.
I cannot understand the reason why it does not working. I expect to read TRUE in log (valveStateEstate).
Thank you for your help.