The Limitation of Reactive Control
Most smart air purifier systems use threshold-based control: when indoor PM2.5 exceeds 25 μg/m³, the purifier switches on. But waiting for pollution to enter before filtering means residents still absorb the peak exposure. Predictive control activates the system before PM2.5 reaches hazardous levels, dramatically reducing exposure.
Input Data for LSTM AQI Forecasting
Historical AQI: hourly PM2.5 from IQAir API (nearest monitoring station) + Thailand Pollution Control Department (PCD) data — 2 years of history.
Meteorological data: wind speed and direction, temperature, relative humidity, atmospheric pressure from the Open-Meteo API (free).
Seasonal features: month, day of week, hour of day. Bangkok AQI follows a clear pattern: peaks at 07:00–09:00 and 17:00–20:00 during the haze season (November–February).
Lag features: PM2.5 readings 1, 2, 4, 6, 12, and 24 hours prior — the most important features.
LSTM Model Architecture
Sequence length: 24 timesteps (24 hours). Features: PM2.5, temperature, humidity, wind speed, wind direction (cos/sin), hour (sin/cos), month (sin/cos) = 9 features. Model: 2-layer LSTM (64 units / 32 units) + Dropout 0.2 + Dense output (forecasts for 1h, 2h, 3h, 4h ahead). Training split: 18 months training, 3 months validation, 3 months test. Performance: MAE ~8–15 μg/m³ for 1–2h forecasts; RMSE rises with longer horizons.
Deployment on Raspberry Pi 5
Train the model on a cloud instance or PC, then export as TensorFlow Lite (.tflite) or ONNX. Run inference on Pi 5 every 30 minutes, or triggered when AQI changes by >10 μg/m³. A Python script updates the Home Assistant sensor (sensor.aqi_forecast_1h) via REST API.
Predictive Automation Logic in Home Assistant
When sensor.aqi_forecast_1h > 50 (Moderate): turn all air purifiers to high speed, reduce ERV flow to minimum (less outdoor air import), close smart windows if fitted, send LINE alert notifying that high AQI is forecast in 1 hour and the system has been prepared.
When sensor.aqi_forecast_1h < 30 (Good): set air purifiers to auto/low mode, increase ERV flow to normal for maximum fresh air.
Bangkok AQI Seasonal Patterns
Fine dust season (November–March): PM2.5 AQI regularly exceeds 100 for multi-day stretches — the period when the LSTM needs the most data and has the most variability. Retrain the model annually with new data.
Monsoon season (May–October): rain washes out PM2.5 — AQI stays low, LSTM accuracy is higher, purifiers run less.
Predictive vs Reactive Control Results
Simulation using Bangkok dataset: reactive control (25 μg/m³ threshold) absorbs 100% of cumulative PM2.5 during AQI spikes. Predictive LSTM control (1h ahead) reduces cumulative PM2.5 exposure by 40–60% by activating the system 30–60 minutes before the spike.
