DEV Community

Natalia Ruiz
Natalia Ruiz

Posted on

How to Control a Robot Vacuum Cleaner from Your Python App

Controlling a robot vacuum cleaner from your own app is not just an exciting tech project—it’s a practical way to automate cleanliness and integrate smart-home routines into your everyday life. Python makes it simple to create automations, interact with APIs, and even build full dashboards that keep your home spotless.

Whether you're building a cleaning schedule or reacting to real-time changes in your environment, a robot vacuum connected to your Python code can transform how you think about home hygiene.

🤖 Understanding Robot Vacuum APIs

Most robot vacuums today offer connectivity through Wi-Fi, and many use open or semi-documented APIs. Some work with MQTT, while others communicate using HTTP requests. Before you code, you need to identify how your device communicates.

Here's a simplified version of a robot vacuum that exposes these basic API endpoints:

  • POST /start - Begin cleaning
  • POST /stop - Stop cleaning
  • POST /dock - Return to charging station

Let’s use Python to communicate with this API.

🐍 Python Controller Code

You can use the requests library to control your robot vacuum.

import requests

ROBOT_IP = "192.168.1.150"  # Replace with your robot's IP

def send_command(command):
    url = f"http://{ROBOT_IP}/{command}"
    try:
        r = requests.post(url)
        print(f"{command.capitalize()} command sent. Status:", r.status_code)
    except Exception as e:
        print("Error sending command:", e)

# Examples
send_command("start")
send_command("stop")
send_command("dock")
Enter fullscreen mode Exit fullscreen mode

This modular approach makes your code cleaner and easier to expand.

🖥️ Build a Web Dashboard with Flask

You can build a web app to control your vacuum from your phone or desktop.

Install Flask

pip install flask
Enter fullscreen mode Exit fullscreen mode

app.py

from flask import Flask, render_template
import requests

app = Flask(__name__)
ROBOT_IP = "192.168.1.150"

def send_command(cmd):
    try:
        r = requests.post(f"http://{ROBOT_IP}/{cmd}")
        return r.status_code
    except:
        return 500

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/<cmd>")
def control(cmd):
    if cmd in ["start", "stop", "dock"]:
        send_command(cmd)
        return f"{cmd.capitalize()} command sent."
    return "Invalid command."

if __name__ == "__main__":
    app.run(debug=True)
Enter fullscreen mode Exit fullscreen mode

templates/index.html

<!DOCTYPE html>
<html>
<head>
  <title>Robot Vacuum Controller</title>
</head>
<body>
  <h2>Control Your Robot Vacuum</h2>
  <button onclick="send('start')">Start</button>
  <button onclick="send('stop')">Stop</button>
  <button onclick="send('dock')">Dock</button>

  <script>
    function send(cmd) {
      fetch('/' + cmd)
        .then(res => res.text())
        .then(msg => alert(msg));
    }
  </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

📦 Add Scheduling with Python

Want your robot to clean every morning at 8 AM? Use the schedule library.

pip install schedule
Enter fullscreen mode Exit fullscreen mode
import schedule
import time

def start_cleaning():
    send_command("start")

schedule.every().day.at("08:00").do(start_cleaning)

while True:
    schedule.run_pending()
    time.sleep(1)
Enter fullscreen mode Exit fullscreen mode

Automating daily routines like this helps maintain consistent South Loop Deep Cleaning service without requiring manual intervention.

🧹 Enhance with Motion Sensors

Use a motion sensor to trigger cleaning only when the room is empty. Here’s a simulation:

import random

def room_is_empty():
    return random.choice([True, False])

if room_is_empty():
    send_command("start")
else:
    print("Room is occupied, skipping clean cycle.")
Enter fullscreen mode Exit fullscreen mode

This method works well in shared spaces or offices, especially for targeted Carpet Cleaning service in South Loop where timing matters.

🏠 Real-world Residential Use

In apartment setups or condos, especially in high-traffic areas like South Loop, we’ve seen homeowners use automation to manage Residential Cleaning service South Loop il more efficiently. With Python, you can tie everything together—from schedules to smart triggers—ensuring cleaning only happens when it's needed.

🧠 Final Thoughts

Python makes it easy to build a robot vacuum controller that is smart, extensible, and fun. Whether you’re scheduling regular cleans or reacting to real-time events, your code can clean smarter—not harder.

This project bridges the gap between simple cleaning and smart automation. If you’ve been looking for a hands-on way to explore IoT, this is a great place to start.

Stay tuned for more integrations like voice control, sensor data, and AI-powered mapping.

Happy coding, and cleaner living!

Top comments (0)