Skip to content

Add more Parallax controls and wait for command results - #235

Closed
tn9design wants to merge 9 commits into
bretterer:mainfrom
tn9design:feature/r2-parallax-controls
Closed

tn9design wants to merge 9 commits into
bretterer:mainfrom
tn9design:feature/r2-parallax-controls

Conversation

@tn9design

@tn9design tn9design commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

This builds on @ibain's signed lock/unlock work in #229. It adds the payloads needed for frunk, rear liftgate, windows, climate, seat conditioning and charging, plus a helper that waits for the vehicle to report the result.

Why

Getting the command accepted by the cloud doesn't always tell us what happened at the vehicle. During R2 testing, some charging commands took effect even though the result came back with operation error 3. Retrying those automatically could send the same command twice.

What

  • Add closure, climate and charging payload encoders using the existing VehicleCommand parameters and temperature/charge-limit bounds.
  • Subscribe to command results before sending, then wait for a matching command ID and RVM with a successful completion status. Clean up interrupted subscription setup so timeouts and cancellations do not leave stale registrations.
  • Send each command once. If the result is missing or ambiguous, report that the command may have taken effect and ask the caller to check the vehicle before retrying. Raw server messages and credentials stay out of these errors.

Testing

Vehicle tests used the earlier local build; the subsequent subscription-cleanup and input-validation refinements were verified offline.

The existing HA wake button was tested successfully. Earlier attempts took a few minutes; the latest user-operated test woke the R2 quickly, with HA reporting ready. The wake command remains on its existing path; this is not a new Parallax wake implementation. Rear-liftgate open and close were also confirmed by the owner and HA state history.

  • 384 tests pass on Python 3.12. Network access was restricted to localhost for the mock servers.
  • Ruff and mypy pass. Regenerating the protobuf modules produces no changes.
  • Added tests for payload bytes, parameter validation, matching results, timeouts, cancellation and subscription cleanup.
  • Tested on one R2: locks, frunk opening, rear-liftgate opening/closing, climate and temperature, driver-seat heat/ventilation, steering-wheel heat, defrost, Gear Guard and charging controls. Charging worked in these tests; some acknowledgements were inconsistent as described above. We haven't seen evidence of a major charging-control problem, but the cause of those responses is still uncertain.

Windows didn't move during testing, and iOS Shortcuts reported window venting unavailable for this R2. The R2 frunk closes manually, so powered frunk closing does not apply to this vehicle. Panic hasn't been physically tested. There are more details in docs/parallax-commands.md.

Related work / merge order

This branch includes @ibain's commits from #229 with their attribution intact. Happy to rebase this onto main after #229 merges, or keep the combined branch if you'd prefer to review and merge it together. That choice is up to the maintainers and #229's author.

The companion HA integration change can be reviewed alongside this. It needs a published client version containing both sets of changes before it can use them through its normal dependency pin.

Testing was done with the R2 parked at home and connected to Wi-Fi. Commands used Rivian's cloud API. We expect the same behavior when the vehicle is connected over cellular, but haven't verified that separately.

ibain and others added 9 commits October 20, 2026 09:40
command.proto describes the envelope, operation and state messages of a
signed remote command, and body.proto the lock and unlock payloads. The
modules are regenerated with the protoc hook.
encode_command signs an operation the way the Android app does,
decode_command_state_message reads the vehicleCommandStatePx messages,
and encode_lock and encode_unlock build the lock and unlock payloads.
_debug_message is taken out of core.py so the new decoder logs unknown
fields like the others.
send_parallax_command posts a signed command, and
subscribe_for_parallax_command_state follows it. The keys are
keyword-only, and a command id that is not a UUID is refused before
anything is sent.
@natekspencer

Copy link
Copy Markdown
Collaborator

Thanks for this. #229 is now merged (squashed), and #232 removed the THIRD_ROW_* seat heat commands, so this needs a rebase and a few changes:

  1. Rebase onto main without Add signed Parallax lock/unlock commands #229's original commits: git rebase --onto origin/main a3710b6. Your five commits then apply with no conflicts.
  2. Rename in controls.py's _SURFACES: use CABIN_HVAC_3RD_ROW_REAR_LEFT/RIGHT_SEAT_HEAT. The old names no longer exist, so the module fails to import. With that change all tests pass.
  3. Keep auth and rate-limit errors. execute_command catches every Exception and re-raises it as ParallaxExecutionError ... from None. That swallows RivianUnauthenticated and RivianApiRateLimitError, so Home Assistant never starts reauth, and the original cause is lost. Let RivianApiException subclasses through, or at least keep from err.
  4. Match on the command ID only in on_state. The first waking_up messages can arrive with an empty rvm, as found while testing Add signed Parallax lock/unlock commands #229.
  5. Missing parameters (e.g. params["level"]) raise KeyError. Raise RivianBadRequestError, as _validate_vehicle_command does.
  6. Move ParallaxExecutionError into exceptions.py as a subclass of RivianApiException.
  7. Split out the cancellation-cleanup changes in ws_monitor.py and rivian.py. They're a general fix and would be easier to review as their own PR.

Also, @walthowd mentioned on #229 that they have Parallax versions of the vehicle commands in their fork. It's worth comparing notes so you don't duplicate work.

@natekspencer natekspencer added the enhancement New feature or request label Nov 11, 2026
@walthowd

Copy link
Copy Markdown
Contributor

Hey @tn9design, I've been hacking on the same thing in my fork (walthowd#2), so comparing notes like Nate suggested.

Good news: your payloads and mine match byte for byte, all but one. I fired your exact bytes at my 2026 R1S (Gen 2, 2026.36.01) and everything worked: locks, windows, frunk, liftgate, seat heat/vent, steering wheel heat, preconditioning, temp including HI and LO, defrost, charge limit, start/stop charging. The liftgate working on a Gen 2 R1S should cover the ask in bretterer/home-assistant-rivian#338.

A few notes from the truck:

  • The one difference is LO. Your temperature_celsius isn't optional, so temp 0 goes out as an empty payload; mine sends an explicit 0. The truck sets LO either way, but I'd mark it optional so the 0 actually goes over the wire.
  • Setting the temp with preconditioning off gets no result and changes nothing. Turn it on first.
  • I got operation error 3 (nats: timeout) twice while the truck was dozing off. One of those commands went through and one didn't, so your "may have taken effect, check before retrying" handling is exactly right.
  • Stop charging drops it right back to the charging schedule, so a test start/stop doesn't mess up the overnight charge.

Mine also has charge port door, panic, and Gear Guard video on/off if you want to fold those in. No sense having two of these, so I'm happy to drop my PR and build on #235.

@natekspencer

Copy link
Copy Markdown
Collaborator

Thanks for all the work on this, and for testing on an R2. Since this was opened, the rest of it has landed in other PRs, so I'm closing it:

Your R2 results are worth keeping here: liftgate open and close worked; the windows didn't move (and iOS Shortcuts showed window venting unavailable); the frunk closes by hand; and some charging commands took effect even though the result came back as operation error 3.

natekspencer added a commit that referenced this pull request Nov 16, 2026
* Remove a subscription that's interrupted while starting

start_subscription registers a subscription before sending the
subscribe request. If the send fails or is cancelled, the caller never
gets an unsubscribe handle, but the registration stays: every reconnect
resubscribes it, its callback keeps getting messages, and the web
socket never closes because it always has a subscription.

Remove the registration when the send is interrupted, and close the
connection if nothing else is on it. A subscribe cancelled while
connecting or waiting for the ack also closes an otherwise unused
connection. Cleanup is bounded to 5 seconds and keeps the original
error.

From #235.

Co-authored-by: tn9design <52539250+tn9design@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the connection for subscribes still starting

The cancel cleanup closed the web socket whenever it had no
subscriptions, which includes while another subscribe is still waiting
for the ack on the same connection, so that one failed too.

The client now counts the subscriptions it's still starting and closes
the connection only when nothing is subscribed or starting on it. The
monitor no longer closes it when a subscribe send is interrupted: it
removes its own registration and leaves the closing to the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Tidy the interrupted subscription cleanup and its tests

Check the web socket before the guarded send, so an assertion can't be
logged as a failed send, and shorten _close_unused_ws's docstring.

The two-waiter test now waits for both subscribes to be starting rather
than sleeping, and the interrupted-send test checks the server is told
the subscription is complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: tn9design <52539250+tn9design@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants