Problem Lua script for import separate winddata from Buienradar

Moderator: leecollings

Post Reply
BBI_home
Posts: 25
Joined: Monday 08 December 2014 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem Lua script for import separate winddata from Buienradar

Post by BBI_home »

Hi,

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.
.
Schermafbeelding 2019-01-18 om 16.56.18.png
Schermafbeelding 2019-01-18 om 16.56.18.png (87.59 KiB) Viewed 688 times
.
So all the requested information is available in a virtual device.
.
Schermafbeelding 2019-01-18 om 17.53.43.png
Schermafbeelding 2019-01-18 om 17.53.43.png (29.99 KiB) Viewed 688 times
.
Schermafbeelding 2019-01-18 om 17.27.16.png
Schermafbeelding 2019-01-18 om 17.27.16.png (60.33 KiB) Viewed 688 times
.
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
This results in an error:

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"
}
I hope somebody is able to help me to take the next step.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Problem Lua script for import separate winddata from Buienradar

Post by jvdz »

The issue is you are trying to convert a text field "SSW"to a number:

Code: Select all

sDirectionStr = tonumber(sDirectionStr)
Should be:

Code: Select all

sDirectionStr = sDirectionStr
Looks like there is also an issue that you will only update the domoticz devices when debug is true. ;)
So this should be close I guess:

Code: Select all

--Script To Parse Buienradar Multi-Value Sensor.
--NOT ready--
--18-01-2019--

commandArray = {}
debug = true

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)
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 .. " ");
end
-- update devices in Domoticz
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}

return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
BBI_home
Posts: 25
Joined: Monday 08 December 2014 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem Lua script for import separate winddata from Buienradar

Post by BBI_home »

Hi Jos,

thanks for your reply.

at the end I wasn't satisfied with the results and I found some new code, which I've extended to produce also windforce data in Beaufort format.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests