Code: Select all
commandArray = {}
-- IDX Waterflow
jIDX = 235
-- Begintijd in uservariables zetten
if (uservariables['begin'] == 0)
then
-- print ("begin instellen")
commandArray['Variable:begin'] = tostring(1)
commandArray['Variable:begintijd']= tostring(os.time())
end
-- Decimalen
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- timedifference
function timedifference(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
-- Script
if (devicechanged['GPIO Watermeter'] == 'Off')
then
-- print ("Watermeter gaat naar Off")
btijd = uservariables['begintijd']
duur = os.time() - btijd
lpm = 60 /duur
-- print (lpm)
lpm = round(lpm, 2)
-- print (btijd)
-- print (os.time() - btijd)
-- print (os.time())
-- print (duur)
-- print (lpm)
commandArray['Variable:begintijd']= tostring(os.time())
commandArray['UpdateDevice'] = ''..jIDX..'|0|'..lpm..''
else
-- Keep a live device and set flow to zero
if (timedifference(otherdevices_lastupdate["GPIO Watermeter"]) > 300)
then
-- print("tijd langer dan 300")
flow = 0
-- commandArray['Variable:begintijd']= tostring(os.time() - 300)
commandArray['UpdateDevice'] = ''..jIDX..'|0|'..flow..''
end
end
return commandArray
line 22= 'year = string.sub(s, 1, 4)'‘ Error: EventSystem: in Waterflow: [string “commandArray = {}…”]:22: bad argument #1 to ‘sub’ (string expected, got nil)’
I use domoticz V4.10007 on a raspberry pi 3.
I searched for a solutions but I'm stuck. What can I change in this code?