Weather-conditioned irrigation with OpenWeather and Node-RED
Two schedulers, one decision pipeline
Manual mode respects the human
Reasons, not just booleans
A snippet from the implementation
Straight from the example as deployed on the Raspberry Pi (Docker) — copy it freely:
const LAT = 41.6000; // latitude of the farm (placeholder)
const LON = 1.8000; // longitude of the farm (placeholder)
const API_KEY = env.get("OPENWEATHER_API_KEY");
msg.mode = msg.mode || "auto"; // "auto" (scheduler) or "manual"
msg.url =
"https://api.openweathermap.org/data/2.5/forecast" +
`?lat=${LAT}&lon=${LON}&appid=${API_KEY}&units=metric&cnt=8`;
// cnt=8 -> next 24 h in 3-hour blocks
return msg;
// ===========================================================================
// FUNCTION 2 — "Decide irrigation"
// Analyzes the OpenWeather response: cancels if rain is forecast or there
// is frost risk. Manual mode ignores the rain (the farmer's decision).
// ===========================================================================
/*
const RAIN_THRESHOLD_MM = 2.0; // mm accumulated in 24 h that cancel the cycle
const FROST_THRESHOLD_C = 1.0; // forecast minimum in ºC that cancels the cycle
const blocks = msg.payload.list || [];
let totalRain = 0;
let minTemp = 99;
for (const b of blocks) {
totalRain += (b.rain && b.rain["3h"]) ? b.rain["3h"] : 0;
minTemp = Math.min(minTemp, b.main.temp_min);
}The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Which OpenWeather endpoint does the flow use?
The 5-day/3-hour forecast endpoint with cnt=8, which covers the next 24 hours and is available on the free tier. The API key is read from the OPENWEATHER_API_KEY environment variable of the Node-RED container, never stored in the flow.
What happens if the OpenWeather API is unreachable?
The http request node returns an error and the decision function never sets msg.regar, so the safe default is to skip the automatic cycle and notify by Telegram. The farmer can always force a manual cycle.
Can I change the thresholds without editing the flow?
In the example they are constants at the top of the function node for clarity. In production we move them to flow context or environment variables so the rain and frost thresholds are editable from the dashboard.