A have a bathscale that's working 4 sometime. All readings are send to domoticz 4 each person. But sudenly a get a error in my log.
[string "commandArray = {}..."]:43: bad argument #1 to 'sub' (string expected, got nil)
A have searching for it , but don't find anything. Line 43 is year = string.sub(s, 1, 4)
Is there someone to have a look for what is wrong ? Thanks
Code: Select all
commandArray = {}
if (devicechanged['Weegschaal']) then
print('scale data received')
data = otherdevices_svalues['Weegschaal']
weightMiddle=75
if tonumber(data) == 0 then
print('Gewicht gelijk aan 0')
else
if (tonumber(data) <= weightMiddle and tonumber(data) > 60 ) then
print('Dit is Sabine')
strDeviceNumber="120"
strDeviceName="Gewicht Sabine"
else
if tonumber(data) >= weightMiddle then
print('Dit is Kris')
strDeviceNumber="119"
strDeviceName="Gewicht Kris"
else
if (tonumber(data) >= 55 and tonumber(data) <= 60 ) then
print('Dit is Robin')
strDeviceNumber="122"
strDeviceName="Gewicht Robin"
else
print('Dit is Milan')
strDeviceNumber="121"
strDeviceName="Gewicht Milan"
end
end
end
end
t1 = os.time()
s = otherdevices_lastupdate[strDeviceName]
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)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
--only update database if 30 seconds has passed since last entry (my oregon gr101 device sends 11 requests over about 10 seconds)
if difference > 30 then
strData = tostring(data) ..'"'
strProgram= 'curl -s -i -H -f --max-time 2 --connect-timeout 2 -0 "Accept: application/json" "http://xxx.xxx.xxx.xxx:xxxx/json.htm?type=command¶m=udevice&hid=2&idx='
strProgram2 ='&dunit=4&dtype=93&dsubtype=1&nvalue=0&svalue='
strCmd = strProgram .. strDeviceNumber .. strProgram2 .. strData
commandArray['SendNotification']= strData
os.execute(strCmd)
end
end
return commandArray