diff --git a/dashboard/plugins/stations/sensors.py b/dashboard/plugins/stations/sensors.py index 59aaa89..f912d02 100644 --- a/dashboard/plugins/stations/sensors.py +++ b/dashboard/plugins/stations/sensors.py @@ -22,6 +22,22 @@ from . import sources SAVE_EVERY_N_POLLS = 10 # ~5 min at 30 s polls HISTORY_MAX_AGE_S = 24 * 3600 # discard older points on load +TEMP_OK = (-50.0, 70.0) # °C a room or the outdoors can be; outside = a failed read + + +def plausible(t, h): + """A failed sensor read (22 Oct 2026: "Shelf" sent 21948 °C / 0 % for 20 min) → no reading at all: + an impossible temperature drops the humidity of that read too; humidity outside 0–100 % alone.""" + try: + t = None if t is None else float(t) + h = None if h is None else float(h) + except (TypeError, ValueError): + return None, None + if t is not None and not TEMP_OK[0] <= t <= TEMP_OK[1]: + return None, None + return t, (h if h is None or 0 <= h <= 100 else None) + + wake = threading.Event() # Settings ▸ Sensors saved: poll now source_status = {} # source id → "ok · 14:05" / what went wrong @@ -68,7 +84,8 @@ def sensors_worker(store): if r is None: s.update(None, None, None, None) # offline else: - s.update(getattr(s, "fixed_name", "") or r["name"], r["t"], r["h"], r["age"]) + t, h = plausible(r["t"], r["h"]) + s.update(getattr(s, "fixed_name", "") or r["name"], t, h, r["age"]) bad = [v for v in status.values() if not v.startswith("ok")] store.sensors_status = ("ok · " + datetime.now().strftime("%H:%M")) if not bad else \ (bad[0] if len(status) == 1 else f"{len(status) - len(bad)} of {len(status)} sources ok — {bad[0]}") diff --git a/dashboard/plugins/stations/views.py b/dashboard/plugins/stations/views.py index b10d974..3b9b24d 100644 --- a/dashboard/plugins/stations/views.py +++ b/dashboard/plugins/stations/views.py @@ -117,7 +117,8 @@ def chart(points, rng, span, step, now, units): parts.append(f"{p[4]:.0f}%") strips.append({"x": x(p[0]), "w": round(w, 1), "tip": " · ".join(parts)}) import math - gap = next(g for g in (1, 2, 5, 10, 20) if (hi - lo) / g <= 5) # round steps, at most 5 lines + gap = next((g for g in (1, 2, 5, 10, 20) if (hi - lo) / g <= 5), # round steps, at most 5 lines + 10 ** math.ceil(math.log10((hi - lo) / 5))) # (a range no sensor makes: never a crash) yt = [v * gap for v in range(math.ceil(lo / gap), math.floor(hi / gap) + 1)] return {"w": CHART_W, "h": CHART_H, "temp": temp_paths, "hum": hum_paths, "band": bands, "strips": strips, "yticks": [{"y": y(v), "v": f"{v:.0f}{u}"} for v in yt],