set_function
Turn a DCC locomotive's decoder functions (F0–F28) on or off by address and function number, with local validation and safe repeat calls. Ideal for controlling headlights, horn, bell, or custom sounds.
Instructions
Turn one of a locomotive's decoder functions (F0-F28) on or off.
Args: address: DCC address. Auto-acquires the throttle if needed. function: 0-28 inclusive (validated locally; out-of-range returns an error without contacting JMRI). What each number controls is decoder/roster-specific — F0 is almost always headlight(s) (see lights_on/lights_off), F1-F28 vary loco to loco (bell, horn, sounds, couplers...). If the 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 ask for the F-number if no label matches. state: True to turn the function on, False to turn it off.
Safe to call repeatedly with the same state: JMRI silently no-ops a redundant request, and a local per-function cache (kept fresh by JMRI's own broadcasts from ANY client holding this address) avoids hanging on a repeat or externally-toggled function.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes | ||
| address | Yes | ||
| function | Yes |