set_function
Turn on or off DCC locomotive decoder functions F0-F28 by address and function number. Uses cached state to avoid redundant commands.
Instructions
Turn one of a locomotive's decoder functions (F0-F28) on or off.
Args: address: The locomotive's DCC address. Acquires the throttle automatically if this session doesn't already hold it. function: Function number, 0-28 inclusive (validated; anything outside that range returns an error rather than being sent to JMRI). What each number actually controls is decoder/ roster-specific — F0 is almost universally the headlight(s) (see lights_on/lights_off below for that common case), but F1-F28 vary loco to loco (bell, horn, sound effects, couplers, etc.). If a user names a function by effect ("turn on the bell", "rear lights") rather than a number, call get_locomotive_functions(name) FIRST to check for a user-set label before guessing or asking — only fall back to asking the user for the F-number if that loco has no label matching what they described. state: True to turn the function on, False to turn it off.
Safe to call repeatedly with the same state: like set_speed/ set_direction, JMRI silently no-ops a redundant "already in this state" request instead of replying, and this tool checks a local per-function cache — kept fresh by JMRI's own broadcasts from ANY client holding this address, not just this one — before deciding whether to send anything, so a repeat call (or a function last toggled by a JMRI panel/PanelPro) still reports the correct current state instead of hanging.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes | ||
| address | Yes | ||
| function | Yes |