08.02.2020, 06:56
Hello,
I have a task where I need to get current wind speed and if it is above certain number (in this case 12 meters/second), the shutter in outside would close. I wanted to do this from KNX weather station, but it seems it doesn't provide actual wind speed accurately, so my guess is I should propably use some API service.
I have tried this script:
But it returns some odd numbers which doesn't really match the forecast from elsewhere, but then I thought maybe I just don't understand what it returns. So how data is returned? The table has 36 entries and I though maybe it is 35 from days starting from first entry (today) forecast, or no? Maybe it is some king of interval based?
Thank You
I have a task where I need to get current wind speed and if it is above certain number (in this case 12 meters/second), the shutter in outside would close. I wanted to do this from KNX weather station, but it seems it doesn't provide actual wind speed accurately, so my guess is I should propably use some API service.
I have tried this script:
Quote:require('socket.http')
forecast = {}
function parsetag(parser, tag, attributes)
if tag == 'time' then
table.insert(forecast, {})
elseif tag == 'symbol' then
forecast[ #forecast ].symbol = attributes.name
elseif tag == 'precipitation' then
forecast[ #forecast ].precipitation = attributes.value
elseif tag == 'windDirection' then
forecast[ #forecast ].wind_direction = attributes.code
elseif tag == 'windSpeed' then
forecast[ #forecast ].wind_speed = attributes.mps
elseif tag == 'temperature' then
forecast[ #forecast ].temperature = attributes.value
elseif tag == 'pressure' then
forecast[ #forecast ].pressure = attributes.value
end
end
url = 'http://www.yr.no/place/Lithuania/Klaipeda/Klaipėda/varsel.xml'
data, err = socket.http.request(url)
if data then
require('lxp').new({
StartElement = parsetag
}):parse(data)
log(forecast)
else
alert('Fetch failed: ' .. tostring(err))
end
But it returns some odd numbers which doesn't really match the forecast from elsewhere, but then I thought maybe I just don't understand what it returns. So how data is returned? The table has 36 entries and I though maybe it is 35 from days starting from first entry (today) forecast, or no? Maybe it is some king of interval based?
Thank You