hass-weatherflow2mqtt icon indicating copy to clipboard operation
hass-weatherflow2mqtt copied to clipboard

Add Lightning Probability

Open GlennGoddard opened this issue 2 years ago • 4 comments

New Feature

This is an oversimplification given the data we have to work with but might be useful. This will return a percentage as written:

def calculate_lightning_risk(lightning_strike_distance, lightning_strike_energy, strikes_1hr, strikes_3hr, strikes_today):
    # Constants
    D = lightning_strike_distance # distance of lightning strikes
    E = lightning_strike_energy # energy of the lightning strike
    S1 = strikes_1hr # number of strikes in the last hour
    S3 = strikes_3hr # number of strikes in the last 3 hours
    S = strikes_today # total number of strikes today
    
    # Lightning risk calculation
    risk_factor = D*E + S1 + S3 + S
    lightning_risk = risk_factor/sum([D*E, S1, S3, S])
    return lightning_risk

Additional context

No response

GlennGoddard avatar Jan 11 '23 04:01 GlennGoddard

This is written to provide more weight to more recent strikes since the 1hr strikes are included in the 3 hour, and the 3 hour is included in the total for the day.

GlennGoddard avatar Jan 11 '23 05:01 GlennGoddard

ReDone in JavaScript for testing and provide % probability:

// Probability of Lightning
// for testing in Node-Red (Java-Script) all inputs are Imperial
// function in metric since WeatherFlow2MQTT is best done metric

temperature = (msg.temperature - 32) * (5/9)
relativeHumidity = msg.humidity
solarRadiation = msg.sr
windSpeed = msg.wind_speed * 0.44704
pressure = msg.sea_press * 33.863886666667
strikes_1m = msg.light_1m
strikes_1h = msg.light_1h
strikes_3h = msg.light_3h
strikes_day = msg.light_day
dew_point = (msg.dp - 32)*(5/9)
cloudy = flow.cloudy
partly_cloudy = flow.part_cloud

let prob = 0;

// temperature, dew point, and relative humidity check
if (temperature > 30) {
    if (relativeHumidity > 50 && dew_point > 15) {
        prob += 30;
    } else if (relativeHumidity > 30 && dew_point > 10) {
        prob += 20;
    }
}

// solar radiation check
if (solarRadiation > 600) {
    prob += 25
} else if (solarRadiation > 400) {
    prob += 10;
}

// wind speed check
if (windSpeed < 15) {
    prob += 15
}

// pressure check
if (pressure < 1000) {
    prob += 25
} else if (pressure < 1010) {
    prob += 10;
}

// lightning detector check
if (strikes_1m > 1 || strikes_1h > 20 || strikes_3h > 50 || strikes_day > 120) {
    prob += 25
} else if (strikes_1m > 0 || strikes_1h > 10 || strikes_3h > 20 || strikes_day > 50) {
    prob += 10;
}

// cloud coverage check
if (cloudy || partly_cloudy) {
    prob += 25;
}

msg.light = prob
return msg;

GlennGoddard avatar Jan 12 '23 04:01 GlennGoddard

I am looking up lightning data per latitude to maybe include

Most Likely conditions for Lightning: humidity range 50-70% temperature range 20-30C / 68-86F sea level pressure range 1010-1020hPa local time 2-3pm and 2-3am

Lightning has occurred at -85F / -65C; very rare however

GlennGoddard avatar Jan 12 '23 05:01 GlennGoddard

I am still experimenting, but everything I have tried so far is not consistent in prediction.

GlennGoddard avatar Jun 20 '23 16:06 GlennGoddard