set_direction
Set a locomotive's direction (forward/reverse) using its DCC address. Automatically acquires throttle and safely handles repeated or external direction changes.
Instructions
Set a locomotive's direction of travel: "forward" or "reverse".
Args: address: DCC address. Auto-acquires the throttle if needed. direction: Exactly "forward" or "reverse" (case-insensitive) — the decoder's own front/back, not compass direction. For "turn it around"/"go the other way", flip the current reported direction rather than guessing.
Best practice: stop a moving loco first — a direction change at speed can jolt or be ignored depending on the decoder; this tool doesn't enforce that, just forwards the request.
Returns direction as "forward"/"reverse" (translated from JMRI's true/false) — independent of speed, never changed here.
Safe to call repeatedly with the same direction: JMRI silently no-ops a redundant request, and a local cache (kept fresh by JMRI's own broadcasts from ANY client) avoids hanging on a repeat or externally-set direction.
In exhibition mode, "reverse" is REFUSED outright (returns an error, does not silently force forward — there's no speed change here to narrate as "moving anyway") — "forward" still works normally. See enter_exhibition_mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| direction | Yes |