TL;DR (one-liner)
- Attach a Raspberry Pi camera + Pi controller, integrate with Roborock local control (python-miio or Valetudo), set patrol routines, stream video, publish alerts via MQTT/Telegram.
Safety & legal note
- Respect privacy — inform housemates/guests.
- Don’t use for spying on others or unlawful surveillance.
- Warranty risk: flashing firmware (Valetudo) may void warranty. Proceed only if comfortable.
What you’ll need (parts)
- Roborock S8 (base).
- Raspberry Pi 4 (2GB+) or Pi Zero 2 W (for light use).
- Pi Camera Module (or USB webcam).
- USB power bank (5V 2–3A) or 5V supply near dock.
- MicroSD card (16GB+) for Pi OS.
- Optional: USB microphone / speaker for voice alerts.
- Optional: PIR sensor or ultrasonic sensor (for local motion triggers).
- Ethernet cable or reliable Wi-Fi.
- Small velcro/3M mounting strips and a lightweight bracket to attach Pi to robot or base.
- Laptop for setup.
- (Advanced) TTL serial adapter, screwdriver kit — only if flashing Valetudo.
Two approaches — pick one
- Non-invasive (recommended): Keep Roborock firmware intact. Use local LAN control (python-miio) or cloud control to send start/stop/go_to commands; Pi handles camera, streaming, motion detect, alerts. Lower risk.
- Full local control (advanced): Install Valetudo or other local firmware for direct map+goto control and MQTT integration. More powerful but riskier (voids warranty; requires serial access).
Prep — common setup steps
- Flash Raspberry Pi OS to SD:
Raspberry Pi Imager→ Raspberry Pi OS Lite. - Boot Pi, enable SSH, connect Wi-Fi.
- Update:
sudo apt update && sudo apt upgrade -y
- Install basics:
sudo apt install python3-pip git curl -y
Step A — Non-invasive setup (full guide)
A1 — Get Roborock token (LAN control)
- Install Mi Home (Xiaomi) / Roborock app, add device.
- Export device token/credentials (tools:
python-miiotoken extraction via backup or usemiioinstructions). - NOTE: token extraction methods vary; follow community guide specific to your app/OS.
A2 — Install python-miio on Pi
pip3 install python-miio- Quick test (replace TOKEN & IP):
pip3 install miio
mirobo --ip 192.168.1.55 --token YOUR_TOKEN raw_command get_status
- If success → Pi can start/stop/vacuum/go_to.
A3 — Pi camera streaming
- Enable camera:
sudo raspi-config→ Interfaces → Camera → Enable. - Install
motionorffmpegstreamer. Example usingffmpeg+ simple HTTP stream:
# install
sudo apt install ffmpeg -y
# start simple stream (adjust device)
ffmpeg -f v4l2 -framerate 15 -video_size 640x480 -i /dev/video0 \
-f mpeg1video -b 800k http://0.0.0.0:8081/feed1.ffm
- Or use
mjpg-streamerfor MJPEG:sudo apt install mjpg-streamer(or build).
A4 — Motion detection + alerts
- Install
motion(motion detection daemon) or write Python usingopencv:pip3 install opencv-python numpy paho-mqtt python-telegram-bot
- Minimal motion script (pseudo):
# detect_motion.py (sketch)
import cv2, time, paho.mqtt.client as mqtt
cam = cv2.VideoCapture(0)
mqttc = mqtt.Client(); mqttc.connect("mqtt-broker.ip",1883,60)
ret, frame1 = cam.read(); ret, frame2 = cam.read()
while True:
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
_, thresh = cv2.threshold(blur,20,255,cv2.THRESH_BINARY)
if cv2.countNonZero(thresh) > 3000:
mqttc.publish("home/robot/patrol/motion","1")
frame1 = frame2
ret, frame2 = cam.read()
time.sleep(0.2)
- Hook MQTT → Telegram or push notifications.
A5 — Patrol logic (Python controller)
- Logic: scheduled runs + on-demand + motion-triggered investigate.
- Example flow:
- Schedule at night:
cron→ runpatrol.py. patrol.pysendsmiiocommands:start_clean,go_toknown coordinates, orspot_clean.- While moving, Pi streams camera; motion triggers higher-res capture and notification.
- Schedule at night:
- Example
patrol.pyskeleton:
from miio import Vacuum
v = Vacuum("192.168.1.55", token="YOURTOKEN")
# start
v.start()
# wait, then spot or go_to if supported
# v.goto(x,y) # requires advanced firmwares / Valetudo
# stop & return
v.home()
A6 — Map + checkpoints
- Without Valetudo, exact
go_tomay be limited. Use timed segments:- Start vacuum → let run X seconds → pause → rotate camera capture → resume.
- With Valetudo (advanced) you can
go_tocoordinates precisely.
A7 — Notifications & remote view
- MQTT topics:
home/robot/patrol/statushome/robot/patrol/motion
- Hook to Telegram bot:
- Create bot, get token, send images on motion event (via
python-telegram-bot).
- Create bot, get token, send images on motion event (via
Step B — Advanced: full local control with Valetudo (power user)
Only if comfortable opening vacuum and using TTL serial. Warranty risk.
- Open robot — find serial header on mainboard.
- Connect TTL adapter (3.3V) to board.
- Back up original firmware.
- Flash
custombootloader + installValetudo(or other local firmware). - Configure Valetudo → exposes REST API + MQTT + map/goto commands.
- Use Pi to send REST/MQTT commands: precise
goto,resume,pause. - Use mapping to create checkpoints and run patrol route reliably.
Example: simple end-to-end patrol script (non-invasive)
- Precondition: python-miio control works; Pi camera streaming online; MQTT broker reachable.
cronnightly:*/30 22-06 * * * /usr/bin/python3 /home/pi/patrol.pypatrol.pydoes:v.start()- wait 90s
v.pause()- capture 10s of camera frames → analyze for motion
- If motion → publish MQTT alert + send Telegram image +
v.home()and stop - else resume and continue next segment
- Results: periodic checks, live stream, alerts on movement.
Example code snippets (copy-paste ready)
- Install libs:
pip3 install python-miio paho-mqtt python-telegram-bot opencv-python - Minimal motion + notify (combine from earlier snippets). (User can request full scripts and I’ll paste entire files.)
Mounting & power tips
- Mount Pi near docking station rather than on robot to avoid weight/obstruction.
- If mounting on robot: use lightweight Pi Zero + small camera; secure with velcro.
- Power: use small powerbank with pass-through so robot can still charge; or run Pi off wall supply at docking station.
Practical patrol ideas / behaviors
- Nightly perimeter sweep (quiet) → send snapshots on motion.
- Doorway-focused checks: aim camera near main door while robot is near dock.
- Passive monitor: robot stays docked; Pi camera + PIR does the detecting. Robot dispatched only on alert.
- Map-based patrol (Valetudo): create loop of waypoints →
gotoeach → capture → move on.
Troubleshooting
python-miiotoken errors → re-extract token; ensure LAN mode enabled.- Camera lag → reduce resolution/framerate.
- Robot stuck during manual move → monitor and abort via
v.stop().
Extensions (nice extras)
- Integrate with Home Assistant: expose entities, automation, UI.
- Add two-way audio: microphone + speaker for warnings.
- Add thermal sensor camera (FLIR) for night detection (advanced, expensive).
- Create web dashboard with map, live feed, last alerts.
Quick maintenance checklist
- Test dry runs in daytime.
- Lower camera resolution for reliability.
- Log events with timestamps.
- Keep emergency stop accessible.