I made (partially found) a quick and dirty integration with met.no for a weather service a while back. Met.no is the same instance as YR.no.
Maybe someone can use (and improve, its messy) it. This version only collects the temperature and sends it to 1/1/0. Temperature is correct for the locations I have tried it. Loads of other information available in the output file. Also, you need to specify the correct longitude and latitude on the LM/SL for it to work.
Maybe someone can use (and improve, its messy) it. This version only collects the temperature and sends it to 1/1/0. Temperature is correct for the locations I have tried it. Loads of other information available in the output file. Also, you need to specify the correct longitude and latitude on the LM/SL for it to work.
Code:
require('uci')
forecast = {}
function parsetag(parser, tag, attributes)
if tag == 'time' then
table.insert(forecast, {})
elseif tag == 'precipitation' then
forecast[ #forecast ].precipitation = attributes.value
elseif tag == 'windSpeed' then
forecast[ #forecast ].wind_speed = attributes.mps
elseif tag == 'temperature' then
forecast[ #forecast ].temperature = attributes.value
end
end
latitude = uci.get('genohm-scada.core.latitude')
latitude = tonumber(latitude)
longitude = uci.get('genohm-scada.core.longitude')
longitude = tonumber(longitude)
url = 'https://api.met.no/weatherapi/locationforecast/1.9/?lat='..latitude..'&lon='..longitude..''
data, err = require('ssl.https').request(url)
if data then
require('lxp').new({
StartElement = parsetag
}):parse(data)
grp.write('1/1/0/', forecast[1].temperature)
else
log('Weather fetch failed: ' .. tostring(err))
end