I'm trying to create a Lua script to split data from a combined virtual sensor into several virtual sensors in order to display just the info to fit in a single frontpage.html cell.
. .
So all the requested information is available in a virtual device.
. . .
Therefore I like to create a Lua script but until now without success.
Version: V4.9700
Platform: Raspberry Pi 3 Model B+ /Stretch
Code: Select all
--Script To Parse Buienradar Multi-Value Sensor.
--NOT ready--
--18-01-2019--
commandArray = {}
debug = true
-- for debugging, use this file
if (debug) then
file = io.open("/home/pi/lua_test.log", "a")
end
idxc ='BU_Wind' -- name of combined sensor 412
idxb='427' -- idx of virtual Windbearing sensor
idxr='426' -- idx of virtual Winddirection sensor
idxs='425' -- idx of virtual Windspeed sensor
idxg='428' -- idx of virtual Gust sensor
idxt='429' -- idx of virtual Temperature sensor
idxw='430' -- idx of virtual Temperature Windchill sensor
--Collecting data from combined sensor:
sDirection, sDirectionStr, sSpeed, sGust, sTemp, sChill = otherdevices_svalues[idxc]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sDirection = tonumber(sDirection)
sDirectionStr = tonumber(sDirectionStr)
sSpeed = tonumber(sSpeed)
sGust = tonumber(sGust)
sTemp = tonumber(sTemp)
sChill = tonumber(sChill)
if (debug==true) then
print("Direction " .. idxc .. " is: " .. sDirection .. " ");
print("DirectionStr " .. idxc .. " is: " .. sDirectionStr .. " ");
print("Speed " .. idxc .. " is " .. sSpeed .. " ");
print("Gust " .. idxc .. " is: " .. sGust .. " ");
print("Temp " .. idxc .. " is: " .. sTemp .. " ");
print("Chill " .. idxc .. " is " .. sChill .. " ");
commandArray[1]={['UpdateDevice'] = idxb .. '|0|' .. sDirection}
commandArray[2]={['UpdateDevice'] = idxr .. '|0|' .. sDirectionStr}
commandArray[3]={['UpdateDevice'] = idxs .. '|0|' .. sSpeed}
commandArray[4]={['UpdateDevice'] = idxg .. '|0|' .. sGust}
commandArray[5]={['UpdateDevice'] = idxt .. '|0|' .. sTemp}
commandArray[6]={['UpdateDevice'] = idxw .. '|0|' .. sChill}
end
return commandArray
stack traceback:
domoticz/scripts/lua/scripts_weer_data_buienradar.lua:23: in main chunk
[C]: in ?
Which I unfortunately can't solve.
How the fix this, especially where all the input data is available:
http://192.168.2.12:8080/json.htm?type=devices&rid=412?
Code: Select all
{
"ActTime" : 1547828368,
"AstrTwilightEnd" : "18:57",
"AstrTwilightStart" : "06:32",
"CivTwilightEnd" : "17:33",
"CivTwilightStart" : "07:56",
"DayLength" : "08:19",
"NautTwilightEnd" : "18:16",
"NautTwilightStart" : "07:13",
"ServerTime" : "2019-01-18 17:19:28",
"SunAtSouth" : "12:05",
"Sunrise" : "08:35",
"Sunset" : "16:54",
"app_version" : "4.9700",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"Chill" : -2.2999999999999998,
"CustomImage" : 0,
"Data" : "212.0;SSW;30;41;1.0;-2.3",
"Description" : "",
"Direction" : 212.0,
"DirectionStr" : "SSW",
"Favorite" : 0,
"Gust" : "4.1",
"HardwareID" : 21,
"HardwareName" : "buienradar",
"HardwareType" : "Buienradar.nl (Weather lookup)",
"HardwareTypeVal" : 94,
"HaveTimeout" : false,
"ID" : "00150006",
"LastUpdate" : "2019-01-18 17:11:56",
"Name" : "BU_Wind",
"Notifications" : "false",
"PlanID" : "8",
"PlanIDs" : [ 8 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Speed" : "3.0",
"SubType" : "TFA",
"Temp" : 1.0,
"Timers" : "false",
"Type" : "Wind",
"TypeImg" : "wind",
"Unit" : 6,
"Used" : 1,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "412"
}
],
"status" : "OK",
"title" : "Devices"
}