And I really have no idea where to go from here.2019-05-09 08:19:00.444 Error: EventSystem: in Weather: [string " local domo_ip = "192.168.178.5:8080..."]:30: attempt to index global 'time' (a nil value)
Any clue what is happening and why this error occurs?
Code: Select all
local domo_ip = "192.168.178.5:8080"
local weerstation = 31
local api_key = "myKey"
local debug = 1
local language = "nl"
local dev_DewPoint = "Dauwpunt"
local dev_CloudCover = "Bewolkingsgraad"
local dev_UV = "UV"
local dev_Ozone = "Ozon"
function UpdateDev(device,nvalue,svalues)
print("UpdateDev "..device..'/'..nvalue..'/'..svalues)
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[device]..'|'..tostring(nvalue)..'|'..tostring(svalues)}
end
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
end
if ((time.min+2)%5)==0 then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl "http://'..domo_ip..'/json.htm?type=settings"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
lat = jsonData.Location.Latitude
lon = jsonData.Location.Longitude
local coord = lat..","..lon
print("Darksky function coordinates"..coord)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl "https://api.darksky.net/forecast/'..api_key..'/'..coord..'?lang='..language..'&units=si&exclude=hourly,flags"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
if jsonData ~= nil then
val_UV = jsonData.currently.uvIndex
val_Ozone = jsonData.currently.ozone
val_DewPoint = round(jsonData.currently.dewPoint,1)
val_CloudCover = jsonData.currently.cloudCover*100
end
if debug==1 then
print("Bewolkingsgraad : "..val_CloudCover.. " %")
print("UV-kracht :"..val_UV)
print("Ozone : De ozone-waarde is "..val_Ozone)
print("Dauwpunt : "..val_DewPoint.. " °C")
end
UpdateDev(dev_CloudCover,0,val_CloudCover)
UpdateDev(dev_DewPoint,0,val_DewPoint)
UpdateDev(dev_UV,0,val_UV..";0")
UpdateDev(dev_Ozone,0,val_Ozone)
if debug==1 then
print ("Dauwpunt: "..val_DewPoint.." °C")
print ("Bewolkingsgraad: "..val_CloudCover.." %")
print ("UV-Index: "..val_UV)
print ("Ozone: "..val_Ozone)
end
end