This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Wind speed close shutter
#1
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:


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
Reply
#2
Try using hourly forecast xml: https://www.yr.no/place/Lithuania/Klaipe...y_hour.xml
Wind speed is specified in miles per hour for some reason so a bit of extra conversion is required.
Reply
#3
There are better api's available using JSON. But first of all i would like to say that for this purpose it's better to meassure at the side where your shutter is installed. Specially if you use it for a professional installation side. Some weather API's can be found here. https://superdevresources.com/weather-fo...ping-apps/
Below an example we use with a Dutch weather API in JSON.

require('ssl.https')
require('json')

city = 'Amsterdam'

data = ssl.https.request('http://weerlive.nl/api/json-10min.php?locatie=' ..city)
datatable = json.pdecode(data)
datatable = datatable['liveweer'][1]
--log(datatable)

temp = datatable.temp --actuele temperatuur
--log('Actuele temperatuur: ' ..temp.. '°C')

windms = datatable.windms --windsnelheid in meter per seconde
--log('Windsnelheid: ' ..windms.. ' m/s')
Reply
#4
Hi,

I would add a check to be sure that the values from the online service are received as expected, we do the same with a signal from a local weather station (alive signal).

Make a resident / scheduled script at like this:
Code:
lastupdate = grp.find('1/1/1').updatetime
difference = os.time() - lastupdate
if difference > then 3600 then -- 1 hour not changed
   alert('No new value received from online weather service')
   -- or mail / push / sms etcetera
end
BR,

Erwin
Reply


Forum Jump: