Skip to content

LocalWeatherProvider throws "insufficient data" error when solarRadiation is null (Zimmerman algorithm) #175

@smeisens

Description

@smeisens

Description

The LocalWeatherProvider in tag pr-170 throws "insufficient data" error when using Zimmerman watering algorithm with a PWS that does not provide solarRadiation data.

Environment

  • Docker image: ghcr.io/opensprinkler/weather-server:pr-170
  • Weather provider: local (PWS via WeeWX)
  • Watering algorithm: Zimmerman (selected in OpenSprinkler device)
  • PWS: Weather station without solar radiation sensor

Problem

All observations in observations.json have "solarRadiation":null because the PWS doesn't have a solar sensor. This causes the weather server to continuously throw:

There is insufficient data to support watering calculation from local PWS.

Root Cause

In /weather/dist/index.cjs line ~XX (LocalWeatherProvider):

const avgSolar = dayObs.reduce((sum, obs) => 
  !isNaN(obs.solarRadiation) && ++cSolar2 ? sum + obs.solarRadiation : sum, 
0) / cSolar2;

if (!(cTemp2 && cHumidity2 && cPrecip2) || 
    [minTemp, minHum, -maxTemp, -maxHum].includes(Infinity) || 
    !(cSolar2 && cWind2 && cPrecip2)) {  // <- THIS FAILS
  throw new CodedError(10);
}

When solarRadiation is null:

  • isNaN(null) returns false
  • cSolar stays 0
  • Condition !(cSolar2 && ...) is true → Error thrown

Expected Behavior

Zimmerman algorithm does NOT require solarRadiation - it only uses temperature, humidity, and rain. The check should allow cSolar == 0 when using Zimmerman.

Suggested Fix

Differentiate between ETo (which requires solarRadiation) and Zimmerman (which doesn't):

// Only require solar/wind for ETo calculations
if (!(cTemp2 && cHumidity2 && cPrecip2) || 
    [minTemp, minHum, -maxTemp, -maxHum].includes(Infinity)) {
  throw new CodedError(10);
}

// For ETo: additionally require solar and wind
if (isEToCalculation && !(cSolar2 && cWind2)) {
  throw new CodedError(10);
}

Workaround

Switch to :release tag (but loses 7-day historical data feature from pr-170)

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions