Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
30fa8a3
Let the routine runner start a job without a scene
virtitnerd Oct 12, 2026
487ccb1
Add a local executor for cloud-style schedules
virtitnerd Oct 12, 2026
aaca2f9
Run the schedule loop with the server and report nextFireTime
virtitnerd Oct 12, 2026
7b23655
Add a schedule store and evaluate crons in the robot's timezone
virtitnerd Oct 12, 2026
83f6dfe
Answer get/set/upd/del_timer from the schedule store
virtitnerd Oct 12, 2026
54002a2
Accept schedule create, update and delete over HTTP
virtitnerd Oct 12, 2026
4154b06
Run a schedule the way the cloud does: ask the robot to start its timer
virtitnerd Oct 18, 2026
1aaf386
Integrate schedule dispatch hardening and verified enablement
pponce Oct 26, 2026
0bbae6f
Keep a native schedule read that cannot reach the robot quiet
virtitnerd Nov 12, 2026
b437ef1
Accept the official app's set_timer layout and keep the robot's own t…
virtitnerd Nov 22, 2026
ad0da1b
Answer job writes with a plain string result
virtitnerd Nov 22, 2026
518e2df
Match native schedule timers on firmware that lists them as one string
virtitnerd Nov 22, 2026
05bd287
Stop opening a connection and reloading the inventory on every poll
virtitnerd Nov 22, 2026
58ab1f6
Accept day and month names in schedule crons
virtitnerd Nov 22, 2026
8f6e116
Document missed runs, write responses and the timer layouts in schedu…
virtitnerd Nov 22, 2026
b80e279
Assign an id when a created schedule's id is empty
virtitnerd Nov 22, 2026
4ec6465
Key the inventory cache on the file id as well
virtitnerd Nov 22, 2026
da01b1e
Accept wrapping weekday ranges and treat a leading * as unrestricted
virtitnerd Nov 22, 2026
15212dc
Answer get_timer from the store when the robot is silent, and keep ro…
virtitnerd Nov 22, 2026
e3ca337
Shorten long comments and merge the two missed-run sections
virtitnerd Nov 22, 2026
5d3bba8
Resolve the schedule time zone through our own helper
virtitnerd Nov 22, 2026
19555f2
Let server_timezone tolerate a context without timezone
virtitnerd Nov 22, 2026
cbb6673
Show the store's timers when the robot rejects get_timer
virtitnerd Nov 22, 2026
152a1ad
Drop a pending get_timer entry once the robot has answered
virtitnerd Nov 22, 2026
3a0a175
Forward set_timer for a timer the robot listed instead of storing a copy
virtitnerd Nov 22, 2026
6bb3020
Read the app's positional start_clean action in set_timer
virtitnerd Nov 22, 2026
89b7039
Parse SUN-SUN as Sunday only
virtitnerd Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/known_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ I have tried to copy over most functionality into this server, but some is not 1

- Vacuum camera live streaming — available; see the [model-specific results](camera.md#reported-camera-results). Bootstrap, activation and audio support vary by firmware, and some reports require custom builds.
- Firmware Updates
- Schedules (Routines/Scenes do work though)
- Schedules are experimental. A scheduled start has been reported on an S7; broader hardware compatibility, DST parity, and expired one-time jobs still need validation. See [schedule support](schedules.md). Routines/Scenes are separate.
- China-market devices have model/firmware-specific region and access-renewal restrictions. Unresolved a143/a146/a96 reports reject ordinary commands with `-10002 / rrcheck access denied` after local onboarding. See [known failures](tested_vacuums.md#known-failures). Factory-firmware a184 success was reported with custom interception and compromised-intermediate certificates; it does not establish support through the standard setup or resolve those other reports.
- Some users report success with the official cloud through a China-exit VPN; see [this comment](https://github.com/iobroker-community-adapters/ioBroker.mihome-vacuum/issues/842#issuecomment-1736230673). A China VPN did not resolve the G30 local-server report [#161](https://github.com/Python-roborock/local_roborock_server/issues/161), so it is not an established general workaround here.
175 changes: 175 additions & 0 deletions docs/schedules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Experimental schedule support

This implementation provides schedule storage, job APIs, time calculation, and dispatch. It does
not establish complete Roborock cloud compatibility on every model.

## Responsibilities and compatibility

Homebridge retains schedule switches, pause/delay decisions, original-time
restoration, daily reset, and recovery. The server provides the underlying APIs.

| Operation | Behavior in this branch |
| --- | --- |
| GET `/user/devices/{duid}/jobs` | Stored jobs with calculated UTC `nextFireTime` for enabled, valid jobs |
| POST to the collection | Persist a new job with a unique numeric ID; `result` is that ID as a string |
| PUT/PATCH `/user/devices/{duid}/jobs/{id}` | Verify native enablement when supplied, then save; preserve omitted fields and unknown model fields; `result` is `"done"` |
| DELETE an item | Remove the stored job and its occurrence record; `result` is `"done"` |
| `get/set/upd/del_server_timer` | Forward unchanged to the robot, which owns these timer entries |
| Legacy `get/set/upd/del_timer` | `set_timer` and the `upd_timer`/`del_timer` of a stored job are answered from the store. `get_timer` goes to the robot and the store's jobs are added to its reply (if the robot has not answered after 6 seconds, the store's jobs are sent alone; a robot error reply is passed through). Anything about a timer the store does not hold, and patrol timers, go to the robot |
| Native scheduled execution | Verify the robot timer is on, then send `server_scheduled_start` with the complete settings entry |

A job's numeric `id` is different from the robot timer's string ID in
`param.params[0].name`. Imported or previously unsynchronized jobs can disagree with the native timer.
The server now reconciles enablement and still checks both before execution.
Native jobs are not duplicated in the legacy `get_timer` view; clients must read the jobs API to list native-linked jobs.

The write calls (POST, PUT, DELETE) answer with a plain string in `result` because the
app's `IotApi` declares them as `ApiReturn<String>`; only GET returns the job list. The
exact strings the Roborock cloud sends are not captured here, so this shape is not
verified against the real service.

`set_timer` is accepted in the official app's layout, `[[id, [cron, ["start_clean", {...}]]]]`
with no status element (such a timer starts enabled), as well as the layouts that carry
`"on"`/`"off"`. A patrol timer (`app_start_patrol`) is forwarded to the robot, because the
server cannot start a patrol. If the store cannot save a `set_timer` or `upd_timer`, the
client gets an error and the request is not forwarded to the robot.

Robots do not all list their native timers the same way. Most answer `get_server_timer`
with `[name, "on"|"off", ...]`. An S6 MaxV (`roborock.vacuum.a10`, 02.62.46) answers
`["Y <name> 1 1 <cron> app_start", 0]` for an on timer and `["Y ...", "off", 0]` for an off
one, and its `upd_server_timer` needs that whole string, not the bare name. Both layouts are
read, and the whole string is sent back when the robot listed it that way.

Time updates accept the existing-job JSON PUT used by Homebridge, without
requiring `id` or `nextFireTime` in the body. If `param` is supplied, it replaces
the previous object exactly, so app removal of an optional field is preserved.
Settings such as `clean_order_mode`, `mop_template_id`, `map_index`, room-list
strings, and unknown future options survive storage and native dispatch.
Invalid cron/timezone/body values are rejected. A persistence failure does not
receive a successful write acknowledgement.

## Enablement synchronization across clients

Native schedule on/off changes are synchronized by the server, independent of
whether Homebridge, LocalRock, the OEM app, or the dashboard made the change.
A forwarded `upd/set/del_server_timer` request prompts a fresh native timer read.
The request and the robot's reply remain unchanged; sending a request or receiving
an `ok` is not used as proof of the final state. No client-specific HTTP write is
required after a native toggle.

A background read also runs at startup and approximately every 30 seconds to
recover missed traffic, reconnects, and changes made directly over the LAN. It reuses
one connection per robot and only reads robots that have a native-linked job. A robot
that cannot be read is tried again after 30 seconds, then 1, 2, 4 and up to 10 minutes;
a forwarded native write still triggers a read at once.
Successful reconciliation changes only `enabled` on existing, uniquely matched
jobs. It preserves IDs, cron/timezone, settings, unknown fields, and occurrence
claims. The dashboard's normal refresh shows the updated saved state. Other
clients see it on their next normal read; this is eventual synchronization,
not an unsolicited push into every app.

An HTTP job PUT/PATCH that supplies `enabled` verifies the matching native timer
before saving. A timer already in the requested state needs no extra write,
so the OEM app's native-update-then-PUT sequence remains compatible. A lost
acknowledgement is checked with one read-back, without repeating the write.
Time-only requests that omit `enabled` remain store-only edits.

Background reads and server edits share a per-vacuum lock. A native write that
overlaps a background read invalidates that read; edits/deletions during a read
are checked again before persistence. Missing, malformed, ambiguous or unreachable
timers leave the last saved state intact and never create replacement timers.
A normally polled, still-on timer does not re-enable a consumed one-time job.
An explicit native enable request can do so only after a fresh matching read;
that intent expires after two minutes. Unlinked server-only jobs retain their
existing behavior. Native timer time/settings edits are not imported into job
cron/settings by this enablement reconciliation.

## Execution and missed runs

The scheduler evaluates five-field cron expressions in each job's IANA timezone.
It checks approximately every 20 seconds and starts a job whose occurrence fell
inside the last tick, with up to 60 seconds of allowed lateness.

Before dispatch, the server saves an occurrence claim in the persistent inventory
under `schedule_occurrences`. A repeated tick, restart, or backward clock change
cannot dispatch the same claimed occurrence again. If that write fails, no start
is attempted. This is an at-most-once policy: a crash after claiming but before
sending can miss a clean. Run only one server process against an inventory; the
inventory lock does not coordinate multiple containers or external file editors.
Cloud re-import replaces schedule definitions, so back up local edits before
refreshing. Occurrence claims are retained across that refresh.

### Missed runs

There is no catch-up:

- The first tick after startup only sets a baseline. A job due while the server was stopped,
restarting, or suspended is lost, and so is one due during an event-loop stall longer than
60 seconds.
- An occurrence is consumed as soon as it is claimed, before anything is sent. If the robot
is offline or does not answer, if its linked native timer is off, missing or ambiguous, if
another routine or schedule is running on that robot, or if the 60 second dispatch window
has passed by the time the robot has answered, that occurrence is skipped and is not
retried later.
- A recurring job stays enabled and runs at its next occurrence. Day and month names
(`MON-FRI`, `JAN`) work in crons, and so do ranges that wrap past Sunday (`FRI-SUN`, `6-0`).
- A one-time job (`repeated` false) is disabled when its occurrence is claimed, whether or not
the clean then started. It does not run again, even after a failure.

### Native schedules

A fresh native timer read must find exactly one matching `on` entry. Off, missing,
ambiguous, malformed, or unreachable timer state prevents a start. After that
network wait, dispatch rechecks the stored job and its deadline, so a concurrent
time edit or deletion cancels stale work. The remaining read-to-start race is
resolved by the robot's native command; real firmware behavior needs testing.

A refused or timed-out native scheduled start is never retried as `app_start` or
`app_segment_clean`, and action-locked native starts are not automatically retried.
A robot refusal can mean a disabled/deleted timer; substituting an ordinary clean
could bypass that state. Legacy jobs retain upstream's separate cleaning-command
path; they do not establish native timer support on other firmware.

## Provisional behavior and remaining validation

- Native dispatch preserves the job's method and complete settings entry.
Validate room selection, map, cleaning order, mop mode and history on each model.
- DST policy currently skips nonexistent spring-forward times and runs only the
first occurrence of an ambiguous fall-back time. Automated tests cover this
policy; matching cloud behavior has not been established.
- One-time jobs are consumed when evaluated as due, including when dispatch
subsequently fails (see Missed runs). Expired imported one-time jobs and extended downtime need
further investigation: a five-field cron has no year and can match again in a
later year. Begin hardware testing with recurring jobs.
- Test create/edit/delete through the actual app, disabled/missing native timers,
robot reboot, server/container restart, offline/reconnect, and busy/DND refusal.
- B01 and other scheduling protocols require separate model validation.
Scene/routine scheduling is separate from these device job routes.
- A startup log saying a job task was accepted is not proof of a clean; check
subsequent timer-read/start replies, robot status, and cleaning history.

## First hardware test

Build the selected Git commit into a versioned Docker image. Run `uv sync --locked --extra dev`
and `uv run pytest -q` to execute the Python test suite before deployment.

1. Prepare the runtime configuration, DNS/certificate path, data backup, and
explicit cloud-to-local onboarding procedure. Start with one robot.
2. Import current jobs and verify every numeric job ID maps to the expected
native timer name. Confirm local jobs reads and robot timer reads separately.
3. Disable a recurring test schedule through Homebridge. Confirm the robot timer
reads off and the saved job becomes disabled without a separate HTTP update.
Re-enable it and confirm both states agree and a later occurrence runs once.
4. Test a room schedule and a whole-home schedule. Compare settings, rooms, map,
and history against the app. A refusal should stop dispatch, with no fallback
ordinary clean.
5. Exercise Homebridge delay and cancellation/restoration. Confirm only intended
times change, settings survive, and each resulting occurrence runs once.
6. Disconnect the robot across a due time and reconnect. Verify no replay, then
a future occurrence. Repeat with a server restart across the due time and
after a run. Test pending edits while a timer read is delayed.

Record image tag/commit, model and firmware, timezone, expected time, actual time,
timer state, settings, and relevant sanitized replies for each result. Returning
to the cloud requires the appropriate onboarding transition; stopping Docker is
not an automatic cloud/local switch.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nav:
- Reference:
- Log Retention: logging.md
- Known Limitations: known_limitations.md
- Schedule Support (Experimental): schedules.md
- Scene Validity Reports: scene_validity.md
- Tested Vacuums: tested_vacuums.md
- Compatibility Report Details: compatibility_reports.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@
from .routes.user.deviceshare import match_received_devices as _match_get_received_devices
from .routes.user.deviceshare import match_rooms as _match_get_shared_device_rooms
from .routes.user.devices.jobs import build as _build_get_schedules
from .routes.user.devices.jobs import build_create as _build_create_schedule
from .routes.user.devices.jobs import build_delete as _build_delete_schedule
from .routes.user.devices.jobs import build_update as _build_update_schedule
from .routes.user.devices.jobs import match as _match_get_schedules
from .routes.user.devices.jobs import match_create as _match_create_schedule
from .routes.user.devices.jobs import match_delete as _match_delete_schedule
from .routes.user.devices.jobs import match_update as _match_update_schedule
from .routes.user.devices.newadd import build as _build_add_device
from .routes.user.devices.newadd import match as _match_add_device
from .routes.user.homes.item import build as _build_get_home_data
Expand Down Expand Up @@ -609,6 +615,9 @@ def default_endpoint_rules() -> Sequence[EndpointRule]:
EndpointRule("get_device", _match_get_device, _build_get_device),
EndpointRule("get_device_extra", _match_get_device_extra, _build_get_device_extra),
EndpointRule("get_schedules", _match_get_schedules, _build_get_schedules),
EndpointRule("create_schedule", _match_create_schedule, _build_create_schedule),
EndpointRule("update_schedule", _match_update_schedule, _build_update_schedule),
EndpointRule("delete_schedule", _match_delete_schedule, _build_delete_schedule),
EndpointRule("post_app_info", _match_post_app_info, _build_post_app_info),
EndpointRule("get_inbox_latest", _match_get_inbox_latest, _build_get_inbox_latest),
EndpointRule("get_products_v4", _match_get_products_v4, _build_get_products_v4),
Expand Down
Loading