Local/offline/self-hosted weather forecast?

Temperature less than 4.1 and snow height is less than 100ft, sleet is possible.
Temperature less than 2.1 and snow height is 0ft, snow is possible.

Dew point is 1C or below, snow is possible.
Wet bulb is below 2.1, snow is possible.

You need to combine all the conditions together with the snow height to have a roughly useful true or false result.

Had a quick play, bear in mind Jinja doesn’t have good loop control - hopefully someone can come along and make this more efficient - but:

{% set inp = namespace([]) %}
{% set inp.temp = 8.8|float %} << set your temperature source eg states('sensor.outside_temperature')|float 
{% set inp.dew = 7.4|float %} << set your dew point source eg states('sensor.dewpoint')|float
{% set inp.alt = 0|int %}
{% set DALR = (0.3 / 4) %}
{% set SALR = (0.15 / 4) %}
{%- for _ in range(1,1000) -%}
  {%- if inp.temp > inp.dew and inp.temp > -0.0 -%}
    {%- set inp.temp = (inp.temp - DALR)|round(5,0) -%}
    {%- set inp.alt = inp.alt + 25 -%}
  {% endif %}
{%- endfor -%}
{%- for _ in range(1,1000) -%}
  {%- if inp.temp > -0.0 -%}
    {%- set inp.temp = (inp.temp - SALR)|round(5,0) -%}
    {%- set inp.alt = inp.alt + 25 -%}
  {%- endif -%}
{%- endfor -%}
{{ inp.alt, inp.temp }}

Produces: (5400, -0.0125) which is correct 5400ft up is the freezing line for this temperature and dewpoint input.

Just to save you some problems in the future, I would go ahead and change all the floats to “float (default = 0)” since the next HA update (i.e. tomorrow) this will fail to function due to requirement changes. You can set the default to any value but it will require a default to be set with the Dec release.

1 Like

Yeah, I didn’t do for the floats, because I knew they were being fed with valid values. But you will notice that I did give the round filter a default value of 0. (Or I assumed I had, but looking at the documentation, it doesn’t look like you can give the round filter a default value)

Just in case you wondered how reliable the formulas are:

2 Likes

I will be incorporating this for my Tempest probably over the Christmas break.
I like the snow line and cloud level; you did 99% of the work for what I need so that makes it even better.

1 Like

Please do let me know how you get on, I like to know that I have helped someone.

For the Scotish Borders Weather site, I’m a bit confused. The link on the page for MWF links to a page on how to clean laminated flooring, I was hoping for the three different snow methods explained on the previous page.

From your experience is the aviation method the most accurate? As I currently look at the site, Avation and Weather Display says no snow; but BettleJuice says maybe.

You stated sleet possible if snow height is <100ft but on the site it currently says sleet possible and snow line is 99m (BJ formula).

Are the formulas linked on the page that I’m missing? I’m just trying to get all the info that I can on predicting and would like to see the differences.

Edit
Also, do you have formula that is used for the absolute humidity. I would like to compare that to what I’m using:

    def absolute_humidity(self, temp, humidity):
        """Return Absolute Humidity.
        Grams of water per cubic meter of air (g/m^3)
        Input:
            Temperature in Celcius
            Relative Humidity in percent
        AH = (1320.65/TK)*RH*(10**((7.4475*(TK-273.14))/(TK-39.44))
            where:
              AH is Absolute Humidity g/m^3
              RH is Relative Humidity in range of 0.0 - 1.0.  i.e. 25% RH is 0.25
              TK is Temperature in Kelvin
        """
        if temp is None or humidity is None:
            return None

        # Convert Celcius to Kelvin for temperature
        TK = temp + 273.16
        # Format Relative Humidity
        RH = humidity / 100
        # Absolute Humidity Estimation is fairly acurate between (5C - 20C) (41F - 122F)
        AH = (1320.65 / TK) * RH * (10 ** ((7.4475 * (TK - 273.14)) / (TK - 39.44)))

        """
        # lf/ft^3 is too small a value for that unit, will pass metric units
        # just like Solar Radiation
        # Leaving conversion here for future reference
        if self._unit_system == UNITS_IMPERIAL:
            # (g/m^3 * 0.000062) converts to lb/ft^3
            return round(AH * 0.000062, 6)
        """
        return round(AH, 2)

The Midlands Weather Forum is unfortunately no longer with us, these formulas were devised back in 2006/7.

The Weather Display formula comes directly from Weather Display, the software that I connect my weather station to. I have no idea how the internals of it work.

The BeetleJuice formula as far as I remember, does additional calculations involving height above sea level and wetbulb temperature too.

The aviation formula only requires knowledge of the surface air temperature and the dewpoint.

I cannot provide any insight in to how Absolute Humidity is calculated, because that again is provided directly from Weather Display.

All I can say is that I have been running the site (BordersWeather) since 2006, and in my opinion the Aviation Formula is the one that I trust the most. (I’m pretty sure the Weather Display formula also uses height above sea level in it’s calculations too). Cloud Base - as you might have guessed by now, is also provided by Weather Display directly, I do not have a formula to calculate it - though since every weather station software on the planet seems to provide this value, there must be a fairly standard formula kicking around somewhere to calculate it.

You might like to know, that the original aviation formula as far as I remember is actually for Fahrenheit, and had to be converted to make it work for celcius. Here is a forum post discussing methods:

I am going down a rabbit hole within a rabbit hole now.
From my research DALR is relatively standard and most have similar temperature rates ranging (usually) from 1.8 to 2.1 C/1000ft.

but for SALR that is more dynamic.
It varies for latitude and varies for time of year. A fair approximation can be SALR (in C/km) = 6.26 - 2.5 sin(latitude) for Winter/Spring. Probably not worth calculating for the Summer.

https://link.springer.com/article/10.1007/BF02247093

You have given me a great starting point.
I’m trying to estimate for any possibility not just where I live.
I will say that this seems a little easier to do snow line then UV levels which vary in time of year, time of day (all angle of the sun); I was/am attempting to estimate UV levels to help determine cloud cover based on comparison of estimated UV to UV readings on my weather station.

It doesn’t need to be that exact though, because even if the snow line is at ground line, it doesn’t mean a lot unless there is also going to be precipitation too, and depending of where that moisture comes from it may or may not fall as snow. Once the snow line is down to an adequate height where you could get snow, the wetbulb temperature then comes in to play, for example (from my observations) with a wetbulb between 0C and 1C you are more likely to get fluffy large flakes, but when the wetbulb goes below 0C you are more likely to get the fine powdery snow. As that wetbulb climbs above 1C snow becomes more sleety until it is just rain.

But again none of that matters unless all the conditions are right, the snow line has been at the level that snow would have been possible today had we had precipitation, but because the precipitation is coming from the west, it is bringing warm air with it, thus the snow line has now increased in height again. All that you can ever hope to achieve with completely offline data, is an estimate or indication, but nothing absolute.

EDIT to add:
I do eventually plan to find out how to parse Grib3 files with PHP though, so that I can generate my own local forecast, but of course that still relies on getting the Grib files via the internet in the first place.

Or when I eventually get around to learning Python…

(Also apologies for the rabbit holes that I KNOW that those links will send you down… )

I have considered downloading weather satellite photos directly from the GEOS satellites. I have a HAM (amateur radio) license which started me on the satellite communication path. You don’t need a license to receive the information (download).

https://jeremyclark.ca/wp/telecom/rtl-sdr-for-satellite-weather-on-goes16-planning/

There are many, many, many more sites out there with satellite info.

I know it is not GRIB but you could run machine learning to look at sat photos to render predictions especially when paired with your local data.

For a turnkey way to grab those satellite images: GitHub - jekhokie/raspberry-noaa-v2: V2 of the fantastic Raspberry Pi NOAA setup

And once you have those images, you can use some more elaborate image-based ML forecasting models:

And just for kicks, another ML-based model that requires a large amount of data to seed (but not images): Using Machine Learning to Predict the Weather: Part 1.

And let’s not forget, that for hyperlocal 12-36hr forecasting, the Zambretti Forecast is not to be overlooked. I also work on the basis, that if the air pressure falls by more than 12mb in 24 hours, then string winds / heavy rain can be expected. Most self contained cheap electronic weather stations, use the Zambretti method to give the forecast, and how much the air pressure across 3 or 6 hours has dropped for the storm alarm.

FYI Beteljuice still has a webpage, I found it when I was checking how to spell Zambretti ( Beteljuices Zambretti Algorithm based Forecaster ) so you may be able to contact him and ask him about his snow forecast formula.

The component I’m working on is going to first do Zambretti, after which I’ll add more of the things you’ve brought up in this thread :slight_smile: .

1 Like

Excellent, I will be one of the first to volunteer to test that for you!! I’m also a programmer, and data nerd (partially fuelled by Aspergers). So this excites me greatly!
Andy

Why not instead of the loop do:
SnowLine = (192 * AirTemp) + StationHeight (all in C or meters)
The 192 being 1C drop per 192 meter rise (you can use your own lapse rate, I was looking for a good average). Conversions to feet and F are easy with other calculations which you can just add in to formula. The integration I am using defaults in metric and will convert the final values to imperial if that is was the user desires (which I do) but I write my contributions all in metric to make it easier for everyone.

It was written in PHP, and the loop at the time was to ensure that we had got the calculations correct. I just left it like that, because maths is not my strong point. The bugging of the script is a long page, that is explaining what is happening at every step, and what the values for all the variables are for each step.

This thread is getting more and more interesting.
I have simplified Andrew’s loop while keeping the same approach.
Everything is based in meters and Celsius: assuming that DALR is almost 1° C every 100 meteres, and SALR 0.5° C every 100 meters, we can simplify as follows:

dalr= 100 * (temperature - dew_point)
salr = 200 * dew_point
snow_line = (salr + dalr + elevation) - 150

where temperature is current temperature, dew_point is current dew point, and elevation the station altitude. Then I subtract 150 meters to get the snow line.

The result is very close to Andrew’s one, of course there is some difference due to the imperial/metric conversion.

I have not dropped the ball completely on this.
https://community.weatherflow.com/t/current-conditions/13953/29
Tomorrow is supposed to be a full day without clouds in months, so maybe I can eventually test my equations fully. I have six different formulas I am testing right now that I am doing in Node-Red then sending back to HA.

@mobile.andrew.jones Does the aviation snow line seem to work the best for you? From the Borderland website you referenced the range of estimated snow lines is more than 2000ft with the Beetlejuice estimate being the lowest and aviation being the highest.

I also have the Zambretti algorithm in Node-Red but I still need to work on the inputs; mainly the hour prior pressure, prior two hour pressure, and the prior three hour pressure. I think I have everything else in there from @briis WeatherFlow2MQTT container (I pulled LAT & LONG from HA, and GMT/UTC). Everything is in Java Script (Node-Red) just since it is very easy to modify for testing. I have every function separated out into it’s own block for easy debugging for now; so it is a confusing mess for anyone else to look at but makes perfect sense to me. As soon as I can verify my functions, I will simplify and put a PR in for WF2MQTT for current conditions and then the Zambretti. I am also utilizing the discussion above about Snow for current conditions.

I would not mind others looking at what I posted in the link above in the WeatherFlow forums to see if it makes sense and I’m not missing something. I know that Snow, Snow-Rain, Fog, and Partly Cloudy are currently missing but I’m working on them. I am open to other ideas on Partly Cloudy, I was considering changes from cloudy to sunny a few times in an hour and call it Partly Cloudy for up to an hour after the last change and then set condition to either Cloudy or Sunny whichever it is (if not any other at that time).

2 Likes