Implementing Irrigation System Control via Mobile Applications
Field irrigation controllers — devices with relays that open and close electromagnetic solenoid valves on zones. Rain Bird, Hunter, Orbit — the most known names. Most communicate with "smart" hubs via proprietary protocols. For custom integration into mobile applications, use either manufacturer APIs (if available), replace the controller with IoT-compatible hardware (ESP32 with MQTT, Raspberry Pi with GPIO), or an intermediate gateway.
Rachio API: Cloud Integration
Rachio is one of the few manufacturers with public REST API. OAuth 2.0 authentication, full_control scope:
// iOS, async/await
class RachioClient {
let baseURL = "https://api.rach.io/1/public"
var accessToken: String
func getPersonInfo() async throws -> PersonInfo {
return try await get("/person/info")
}
func startZone(zoneId: String, duration: Int) async throws {
// duration in seconds
try await put("/zone/start", body: [
"id": zoneId,
"duration": duration
])
}
func stopDevice(deviceId: String) async throws {
try await put("/device/stop_water", body: ["id": deviceId])
}
func createScheduleRule(deviceId: String, zones: [ZoneSchedule]) async throws -> ScheduleRule {
return try await post("/schedulerule", body: [
"device": ["id": deviceId],
"name": zones.first?.name ?? "Schedule",
"zones": zones.map { ["id": $0.id, "duration": $0.durationSeconds] },
"startTime": 21600, // seconds from midnight = 6:00
"type": "FIXED_SCHEDULE"
])
}
}
Rachio Webhook allows receiving real-time events: watering start/stop, valve errors, rain detection. Register webhook via API; events arrive as POST requests to developer server, which forwards them to mobile app via WebSocket or FCM.
MQTT Controller: Custom Hardware
For custom installations — ESP32 controller with MQTT. Topics:
irrigation/zone/1/command → {"action": "open", "duration": 300}
irrigation/zone/1/state → {"isOpen": true, "openedAt": "2024-07-15T06:00:00Z"}
irrigation/system/status → {"activeZones": [1,3], "waterFlow": 12.5, "pressure": 2.8}
Mobile app subscribes to irrigation/+/state and irrigation/system/status. Control — publish to irrigation/zone/+/command.
For Flutter:
class IrrigationRepository {
late MqttServerClient _client;
final StreamController<ZoneState> _zoneStateController = StreamController.broadcast();
Stream<ZoneState> get zoneStates => _zoneStateController.stream;
Future<void> connect(MqttConfig config) async {
_client = MqttServerClient(config.host, config.clientId)
..port = config.port
..secure = true
..securityContext = config.sslContext
..keepAlivePeriod = 30
..onDisconnected = _onDisconnected;
await _client.connect(config.username, config.password);
_client.subscribe('irrigation/+/state', MqttQos.atLeastOnce);
_client.updates!.listen((messages) {
for (final message in messages) {
final payload = MqttPublishPayload.bytesToStringAsString(
(message.payload as MqttPublishMessage).payload.message,
);
final zoneId = _extractZoneId(message.topic);
_zoneStateController.add(ZoneState.fromJson(zoneId, jsonDecode(payload)));
}
});
}
Future<void> startZone(int zoneId, Duration duration) async {
final builder = MqttClientPayloadBuilder();
builder.addString(jsonEncode({
'action': 'open',
'duration': duration.inSeconds,
}));
_client.publishMessage(
'irrigation/zone/$zoneId/command',
MqttQos.atLeastOnce,
builder.payload!,
);
}
}
Schedule and Automation
Irrigation schedule is a separate screen where you set zones, duration, and repetition. Complexity: schedule must account for weather forecast (skip watering if rain expected) and soil sensor data.
Integrate with weather forecast via Open-Meteo API (free, no key):
Future<bool> shouldSkipIrrigation(double lat, double lon) async {
final url = Uri.parse(
'https://api.open-meteo.com/v1/forecast'
'?latitude=$lat&longitude=$lon'
'&daily=precipitation_sum'
'&forecast_days=2'
'&timezone=auto'
);
final response = await http.get(url);
final data = jsonDecode(response.body);
final todayRain = data['daily']['precipitation_sum'][0] as double;
final tomorrowRain = data['daily']['precipitation_sum'][1] as double;
// Skip if today or tomorrow has >5mm rain
return todayRain > 5.0 || tomorrowRain > 5.0;
}
Zone Management UX
Zone management screen — map or schematic plan with color indicators: green — active zone, gray — inactive, red — valve error. Long tap on zone — start manual watering with time selection (slider 1-60 minutes).
"Stop all" button must always be accessible in one action — don't hide in menu.
Developing irrigation control application with Rachio API or custom MQTT controller, schedule and weather integration: 3-5 weeks. Cost calculated after clarifying equipment and zone count.







