Hi everybody,
I'm having problems reading the data from my weatherstation, I can see the device and with a json command from the browser it gives my all the data I need but getting it from lua is not working.
Can someone please help me?
Kind regards,
Patrick
The error I'm getting is: EventSystem: in Tuindata: [string "local Tuin_Temperatuur_idx = 251 ..."]:14: attempt to index a nil value (field 'Tuindata')
The device is: 236 RFXLink 2301 0 Tuindata Temp + Humidity WTGR800 10.3 C, 68 %
The json command is:
http://192.168.178.5:8080/json.htm?type=devices&rid=236
and returns:
- Spoiler: show
-
{
"ActTime" : 1585907850,
"AstrTwilightEnd" : "22:22",
"AstrTwilightStart" : "05:05",
"CivTwilightEnd" : "20:53",
"CivTwilightStart" : "06:33",
"DayLength" : "13:10",
"NautTwilightEnd" : "21:36",
"NautTwilightStart" : "05:51",
"ServerTime" : "2020-04-03 11:57:30",
"SunAtSouth" : "13:43",
"Sunrise" : "07:08",
"Sunset" : "20:18",
"app_version" : "2020.1 (build 11836)",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 100,
"CustomImage" : 0,
"Data" : "10.3 C, 69 %",
"Description" : "",
"DewPoint" : "4.86",
"Favorite" : 0,
"HardwareID" : 16,
"HardwareName" : "RFXLink",
"HardwareType" : "RFLink Gateway USB",
"HardwareTypeVal" : 46,
"HaveTimeout" : false,
"Humidity" : 69,
"HumidityStatus" : "Wet",
"ID" : "2301",
"LastUpdate" : "2020-04-03 11:57:22",
"Name" : "Tuindata",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" :
[
0
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "WTGR800",
"Temp" : 10.300000000000001,
"Timers" : "false",
"Type" : "Temp + Humidity",
"TypeImg" : "temperature",
"Unit" : 0,
"Used" : 0,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "236",
"trend" : 2
}
],
"status" : "OK",
"title" : "Devices"
}
This is the script:
- Spoiler: show
-
local Tuin_Temperatuur_idx = 251
local Tuin_Vochtigheid_idx = 252
commandArray = {}
time = os.date("*t")
if((time.min % 1)==0)then
function round(num, idp) -- Credits go to Martin Rourke, I used his function.
local mult = 10^(idp or 1)
return math.floor(num * mult + 0.5) / mult
end
-- Split data
sWeatherTemp, sWeatherHumidity = otherdevices_svalues['Tuindata']:match("([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp)
commandArray[1]={['UpdateDevice'] = Tuin_Temperatuur_idx .. '|0|' .. tostring(sWeatherTemp)}
sWeatherHumidity = tonumber(sWeatherHumidity)
commandArray[2]={['UpdateDevice'] = Tuin_Vochtigheid_idx .. '|' .. (sWeatherHumidity) .. '|0'}
end
return commandArray