Domoticz METAR Script

Metar script
Lua time script

— METAR time script

local idx = 103
local station = “EHAM”

command = “curl http://tgftp.nws.noaa.gov/data/observations/metar/stations/” .. station .. “.TXT”
commandArray = {}

local m = os.date(‘%M’)
if (m % 30 == 5) then
— update at 5 and 35 minutes of every hour
local handle = io.popen(command)
local data = handle:read(“*a”)
handle:close()

if (data == ”) then
print(“Error metar data not fetched”)
return
end

data = string.gsub(data, “M”, “-“)
local pres = tonumber(string.match(data, ‘ Q([0-9]+)’))
local temp = tonumber(string.match(data, ‘ ([-0-9]+)/[-0-9]+ ‘))
local dew = tonumber(string.match(data, ‘ [-0-9]+/([-0-9]+) ‘))
local fore = 5

— very basic prediction
if (pres < 1000) then fore = 4 elseif (pres < 1020) then fore = 3 elseif (pres < 1030) then fore = 2 else fore = 1 end -- print (data, pres, temp) local hum = 100*(math.exp((17.625*dew)/(243.04+dew))/math.exp((17.625*temp)/(243.04+temp))) commandArray[1] = {['UpdateDevice'] = idx .. '|0|' .. temp .. ';' .. hum .. ';0;' .. pres .. ';' .. fore} end return commandArray