Implementing AI Climate Control with Habit Learning in a Smart Home Mobile App
Nest thermostat changed user expectations: a climate system should learn habits and adjust itself. A regular smart thermostat with a fixed schedule requires manual setup and doesn't adapt. A learning system observes user behavior for weeks and builds a predictive model: when the person wakes, when they come home, when they sleep, what temperature they prefer morning vs evening.
Collecting Contextual Data
Habit learning requires multiple input streams:
Presence in home. Wi-Fi presence detection — analyzing active MAC addresses on network (router ARP table via SSH or SNMP) without GPS. More reliable than geofencing with poor GPS in apartment. Passive Bluetooth scanning on mobile as backup signal.
Manual adjustments. Each time user manually changes temperature in app — that's a training signal. "Friday 22:30 user lowered temperature from 22°C to 20°C" — significant pattern.
External conditions. Outdoor temperature (OpenWeatherMap or façade sensor), cloud cover, wind — affect home heat loss and preferred interior temperature.
@Entity(tableName = "climate_events")
data class ClimateEvent(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val timestamp: Long,
val eventType: EventType, // MANUAL_ADJUST, AUTO_SETPOINT, PRESENCE_DETECTED, PRESENCE_GONE
val roomId: String,
val setTemperature: Float?,
val actualTemperature: Float,
val outdoorTemperature: Float,
val hour: Int, // 0-23
val dayOfWeek: Int, // 1=Mon
val isWeekend: Boolean,
val presenceCount: Int, // devices on network
)
Comfortable Temperature Prediction Model
After 2–3 weeks of data accumulation, train a model. For this task, simple models work well, not complex neural networks: Gradient Boosting (LightGBM) or Random Forest on features {hour, dayOfWeek, isWeekend, outdoorTemp, presenceCount}.
# Server: train personal comfort temperature model
import lightgbm as lgb
from sklearn.model_selection import TimeSeriesSplit
def train_comfort_model(user_id: str) -> lgb.Booster:
events = load_manual_adjustments(user_id, days=30)
features = pd.DataFrame({
'hour_sin': np.sin(2 * np.pi * events.hour / 24),
'hour_cos': np.cos(2 * np.pi * events.hour / 24),
'dow': events.day_of_week,
'is_weekend': events.is_weekend.astype(int),
'outdoor_temp': events.outdoor_temperature,
'presence': events.presence_count,
})
target = events.set_temperature
model = lgb.LGBMRegressor(n_estimators=100, learning_rate=0.05, max_depth=4)
tscv = TimeSeriesSplit(n_splits=5)
# cross-val for quality assessment...
model.fit(features, target)
return model
Model exports to ONNX or TFLite, loads into mobile app. Forecast for next 24 hours — array of temperature setpoints by hour. Applied automatically or requires user confirmation (configurable).
Managing Climate Equipment
Mobile app controls equipment through multiple levels:
Local thermostats with API. Nest Thermostat — Google Smart Device Management API. Ecobee — ecobee3 API. Heatmiser — Modbus TCP or hub. Tado — REST API. Each has its own authorization (OAuth2 or API key) and request limits.
MQTT controllers. Thermostat on ESP32 with ESPHome firmware: controlled via MQTT home/thermostat/setpoint. Mobile app writes directly or through Home Assistant REST API.
// iOS: sending thermostat setpoint via Home Assistant
class ClimateController {
private let haBaseURL: String
private let bearerToken: String
func setTemperature(entityId: String, temperature: Double) async throws {
let url = URL(string: "\(haBaseURL)/api/services/climate/set_temperature")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(bearerToken)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONEncoder().encode([
"entity_id": entityId,
"temperature": temperature
])
let (_, response) = try await URLSession.shared.data(for: request)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
throw ClimateError.setpointFailed
}
}
}
Model Adaptation and Automation Management
Model retrains annually with fresh data and decay of old data (seasonal drift: summer and winter preferences differ). If user corrects automatic setpoint several times — app suggests immediate retraining.
Trust zones: user can allow automatic setpoints only within acceptable range — e.g., "automatically, but not below 18°C and not above 24°C." Going outside — request confirmation via notification.
Multi-room climate: separate model per room, different patterns (bedroom vs living room vs nursery). Model synchronization on server; mobile app gets single forecast set via REST.
Developing AI climate habit learning module for smart home mobile app: 8–12 weeks. With multi-zone support and integration of multiple thermostat brands: 4–5 months. Pricing is calculated individually.







