▲ 3 r/litterrobot
LR3 automation since sensors failed
Hey! I figured I would share a little project I worked on to make life with my old LR3 easier, I have replaced sensors to keep the machine working however the box would never cycle from the cats using it, so I had claude make a script for a background service to cycle the litter box every 2 hours. sensors for cat safety are still functional!
The Whisker app only lets you start a cycle by hand. Here's how I made my Litter-Robot 3 Connect run a clean cycle on a schedule, with no hardware changes. It uses the same Whisker login you use in the app and an always-on computer (I use a Raspberry Pi; any Linux box, Mac, or Windows PC that stays on works).
**How it works:**
the unofficial [pylitterbot](https://github.com/natekspencer/pylitterbot) library (the one Home Assistant's Litter-Robot integration uses) logs into the Whisker cloud and sends the "start clean cycle" command. A scheduler runs a tiny script every couple of hours.
**What you need**
- Python 3.11 or newer (`python3 --version`)
- Your Whisker account email and password
- A machine that's on whenever a cycle should fire
---
## Linux / Raspberry Pi setup (copy and paste)
On Debian/Raspberry Pi OS you may need the venv package first: `sudo apt install python3-venv`
**1. Create a folder and a private Python environment**
```bash
mkdir -p ~/litter && cd ~/litter
python3 -m venv venv
./venv/bin/pip install pylitterbot
```
**2. Save the script as `~/litter/litter_cycle.py`**
```python
"""Trigger a clean cycle on every Litter-Robot on the Whisker account.
Credentials come from the WHISKER_USER / WHISKER_PASS environment variables.
Each run is appended to litter_cycle.log next to this script.
"""
import asyncio
import logging
import os
from pathlib import Path
from pylitterbot import Account
LOG = Path(__file__).with_name("litter_cycle.log")
logging.basicConfig(
filename=LOG,
level=logging.INFO,
format="%(asctime)s %(levelname)s %(message)s",
)
async def main() -> None:
account = Account()
try:
await account.connect(
username=os.environ["WHISKER_USER"],
password=os.environ["WHISKER_PASS"],
load_robots=True,
)
if not account.robots:
logging.error("Logged in but no robots found on the account")
return
for robot in account.robots:
await robot.start_cleaning()
logging.info("Started clean cycle on %s (status: %s)", robot.name, robot.status)
except Exception:
logging.exception("Cycle failed")
raise
finally:
await account.disconnect()
if __name__ == "__main__":
asyncio.run(main())
```
**3. Store your login in a private file (so it's not in the script or the cron line)**
```bash
cd ~/litter
read -rp "Whisker email: " WUSER
read -rsp "Whisker password: " WPASS; echo
umask 077
printf 'WHISKER_USER=%q\nWHISKER_PASS=%q\n' "$WUSER" "$WPASS" > .env
unset WUSER WPASS
chmod 600 .env
```
This writes `~/litter/.env`, readable only by your user. Never commit or share it.
**4. Create the wrapper `~/litter/run.sh`**
```bash
cat > ~/litter/run.sh <<'EOF'
#!/usr/bin/env bash
cd "$(dirname "$0")"
set -a; . ./.env; set +a
PYTHONUTF8=1 exec ./venv/bin/python litter_cycle.py
EOF
chmod 700 ~/litter/run.sh
```
**5. Test it.**
This really starts a clean cycle, so make sure the cat isn't in the globe:
```bash
~/litter/run.sh
tail -n 5 ~/litter/litter_cycle.log
```
You should hear the globe rotate, and the log should say `Started clean cycle on <your robot's name> (status: ...)`. If it says "Cycle failed", the traceback underneath will tell you why (wrong password is the usual cause).
**6. Schedule it with cron**
```bash
( crontab -l 2>/dev/null; echo "31 */2 * * * $HOME/litter/run.sh" ) | crontab -
crontab -l
```
That runs a cycle every 2 hours at :31. Change the schedule to taste: `31 * * * *` is hourly, `0 8,20 * * *` is 8am and 8pm, and [crontab.guru](https://crontab.guru) helps with the syntax.
**7. Confirm the first scheduled run fired**
(wait for the next :31):
```bash
tail -n 5 ~/litter/litter_cycle.log
```
To undo everything: `crontab -e` and delete the line, then `rm -rf ~/litter`.
---
## Windows setup (PowerShell)
1. Install Python 3.11+ from python.org.
2. Create the folder and environment:
```powershell
mkdir $HOME\litter; cd $HOME\litter
py -m venv venv
.\venv\Scripts\pip install pylitterbot
```
3. Save the same `litter_cycle.py` from above into `%USERPROFILE%\litter`.
4. Save your login as user environment variables (these are stored for your account only; new processes pick them up):
```powershell
[Environment]::SetEnvironmentVariable("WHISKER_USER", "you@example.com", "User")
[Environment]::SetEnvironmentVariable("WHISKER_PASS", "your-password", "User")
```
5. Test: `.\venv\Scripts\python.exe litter_cycle.py`, then `type litter_cycle.log`.
6. Schedule it every 2 hours at :31 (PowerShell, use `pythonw.exe` so no console window flashes):
```powershell
$py = "$HOME\litter\venv\Scripts\pythonw.exe"
$action = New-ScheduledTaskAction -Execute $py -Argument "$HOME\litter\litter_cycle.py" -WorkingDirectory "$HOME\litter"
$trigger = New-ScheduledTaskTrigger -Once -At "00:31" -RepetitionInterval (New-TimeSpan -Hours 2)
Register-ScheduledTask -TaskName "LitterRobot Cycle" -Action $action -Trigger $trigger
```
The PC must be on (or awake) for cycles to fire, which is why I moved mine to a Pi.
---
## Notes and gotchas
-
**It's an unofficial API.**
Whisker can change it without notice and break this. If it stops working, run `./venv/bin/pip install --upgrade pylitterbot` first.
-
**Run it from one place only.**
If two machines (or a PC task plus a Pi cron) both run it, the robot gets two cycle commands each interval.
-
**It cycles every robot on the account.**
If you have more than one, filter on `robot.name` inside the loop.
-
**I haven't tested what happens if the cat is in the globe when the command fires,**
so pick times that suit your cat. The script just sends the command.
-
**Home Assistant users**
may be able to do this with the Litter-Robot integration and a time-based automation instead of a script. I haven't tried that.
- The robot's built-in cycle delay setting (3, 7 or 15 minutes after the cat leaves) is separate and still works as normal.
u/Fnawesome27 — 4 days ago