24.04.2018, 21:50
(24.04.2018, 17:03)buuuudzik Wrote: You are trying to log value 'ValveStatesEstate' but you hasn't defined stagione so stagione equals nil so else condition is executed.
But generally when you extend this script maybe better would be create some function and do script more elastic also for the future
See below (but still you must define stagione!):
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 function getParamsFromValveStates(valvesTag) local valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do valveState = valveStates[v] if valveState.value then opened = true if firstTimestamp > 0 then if firstTimestamp > valveState.updatetime then firstTimestamp = valveState.updatetime end else firstTimestamp = valveState.updatetime end end end return opened, firstTimestamp end if not stagione then opened, firstTimestamp = getParamsFromValveStates(valveStatesTagEstate) else opened, firstTimestamp = getParamsFromValveStates(valveStatesTagInverno) 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.') os.sleep(nextCalculationAfter)
Thank you very much...stupid mistake!! I have to hire you