User Tools

Site Tools


get_weather_conditions_and_forecast

This is an old revision of the document!


Weather and resource monitoring

GetCurrentWeather()

The GetCurrentWeather function returns the current weather conditions at the WebHMI installation location. The data is being updated approximately every two hours. The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400.

If for some reason the data has not been received, the value nil will be returned.

The function returns a table with the following fields:

time The time for which the weather data was received
text A short textual description of the current weather
temperature Air temperature in degrees Celsius
pressure Atmospheric pressure in hPa
humidity Relative air humidity in %
windDirection The direction of the wind origin, metrological degrees (north— 0 degrees)
windSpeed Wind speed in m/s
cloudness Covering the sky with clouds as a percentage
rain Precipitation (rain), in mm
snow Precipitation (snow), in mm

GetForecastWeather(interval)

The GetForecastWeather function returns the weather forecast at the WebHMI installation location to the specified interval. The data is updated approximately every two hours. The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400.

If for some reason the data has not been received, the value nil will be returned.

The interval is a three-hour time interval in the future. From zero to 6. Total six intervals. Zero interval is the forecast in about 3 hours. The first interval is the forecast in six hours. Etc. The format of the returned data is identical to the function GetCurrentWeather.

An example of a simple program that turns on and off the warm floor before entering the store, depending on the weather conditions.

function main (userId)
    local current = GetCurrentWeather();
    local nextForecast = GetForecastWeather(0);
 
    if (nextForecast.temperature > 6 and current.temperature > 6) then -- positive temperature
        WriteReg(91, 0); -- turn anti-ice off 
    end
 
    if (current.snow < 1 and nextForecast.snow < 1) then -- not snowing 
        WriteReg(91, 0); -- turn anti-ice off
    end
 
    if (current.cloudness < 20 and nextForecast.cloudness < 20) then -- clear
        WriteReg(91, 0); -- turn anti-ice
    end
 
    if (current.snow > 2 or nextForecast.snow > 2) then -- it's snowing
        WriteReg(91, 1); -- turn anti-ice on
    end
end

GetSunriseTime(interval)

The function GetSunriseTime returns the time in the format Unixtime of the sunrise in the current day. The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400. If for some reason the data has not been received, the value nil will be returned.

GetSunsetTime(interval)

The function GetSunsetTime returns the time in Unixtime format of sunset in the current day. The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400. If for some reason the data has not been received, the value nil will be returned.

get_weather_conditions_and_forecast.1547030505.txt.gz · Last modified: 2019/01/09 10:41 by akuzmuk

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki