OpenSprinkler/OpenSprinkler-Weather

Issue using local weather server: yesterday weather not used as watering data

FranzStein opened this issue · 0 comments

The result of the local.ts function getLocalWateringData does not contain yesterday's weather data if running it after midnight. I'm not sure what is intented here? I assume yesterday's data shall be used after startup. In this case the script line "...yesterday as WateringData," has to be executed after "...today,". Please change the corresponding function accordingly:


export const getLocalWateringData = function(): WateringData {
    const result: WateringData = {
            // Use today's weather, if we dont have information for yesterday yet (i.e. on startup)
            ...today,
            // Use yesterday's weather updated every midnight, if available after startup
            ...yesterday as WateringData,
            // PWS report "buckets" so consider it still raining if last bucket was less than an hour ago
            raining: last_bucket !== undefined ? ( ( Date.now() - +last_bucket ) / 1000 / 60 / 60 < 1 ) : undefined,
            weatherProvider: "local"
    };

    if ( "precip" in yesterday && "precip" in today ) {
            result.precip = yesterday.precip + today.precip;
    }

    return result;
};

The changed function works fine for me on Raspberry PI 3 Model B+. If not raining, it results in a single watering percentage number per day!