TS Smart Switch
A switch that doesn't blow up when a branch isn't wired
- input_1
- input_2
- output
Every workflow eventually needs the plumbing question answered: "use this input, or that one?" A plain boolean switch handles it - until one of the branches isn't connected, at which point most switches hand you a None, a blank, or a hard error. TS Smart Switch is the version with a safety net: it's a type-aware boolean switch for any data, and if the input it's told to select is missing, it auto-fails over to the other one. Optional branches become a one-node thing instead of a rewire.
How it works
Two inputs in, one out. switch is a boolean (labelled "Input 1" / "Input 2" in the UI) that picks the branch. The twist is data_type - a dropdown (images, video, audio, mask, string, int, float, …) that the node validates each input against. Connect a mismatched type into a slot and it's ignored rather than let through, so you can't silently route a string into an image socket and discover it three nodes later.
The auto-failover is the feature worth building around: switch on selects Input 1, off selects Input 2 - but if the selected input is empty, the other one passes through regardless. That's the whole "make one input optional with a sensible fallback" pattern from the README, and it's exactly how you build a branch that degrades gracefully: wire the primary source, leave the fallback optional, and the graph keeps running whether or not the primary is connected.
Both inputs are * (ANY type) and both are optional; the output mirrors whatever you fed in. Because the socket types are wildcards, the same node routes images, audio, masks, strings - anything the graph carries.
The setting that matters
data_type- set it once to the kind of data you're routing (e.g.imagesfor an image branch,audiofor an audio branch). It's what makes the mismatch-ignoring and the type safety work.switch- the boolean. Convert it to an input and drive it from a node (a seeded random, a frontend toggle) for dynamic routing.
Install
No dependencies - pure-Python utility inside comfyui-timesaver.
cd ComfyUI/custom_nodes
git clone https://github.com/AlexYez/comfyui-timesaver
cd comfyui-timesaver
python -m pip install -r requirements.txt
Restart and search "TS Smart Switch".
Common issues
- "It passed through the wrong input." Check
switch's position and whether the selected input was actually empty - if it was, failover did its job. - "My input got ignored."
data_typemismatch. The node validates against the declared type and drops mismatches on purpose; pick the right type and it'll connect. - "The sockets show as ANY and won't connect." ComfyUI highlights compatible sockets while dragging - the wildcard accepts whatever you bring. If a specific connection won't take, it's the
data_typevalidation doing its thing.
The honest scope: this is one of those nodes you forget exists until a graph keeps failing on an empty branch, and then it saves the afternoon. It won't do anything a careful hand-built switch can't - it just makes the "optional with fallback" case stop being fiddly.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| data_type | COMBO | Type of data being routed. Each input is validated against it; mismatched inputs are ignored. | |
| switch | BOOLEAN | true | On selects Input 1, off selects Input 2. If only one input is valid, it is passed through regardless (auto-failover). |
| input_1opt | * | First input branch. Evaluated only when it is the one selected (or when the other branch turns out to be missing), so an unused branch costs nothing. | |
| input_2opt | * | Second input branch. Evaluated only when it is the one selected (or when the other branch turns out to be missing). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | * | The selected input. |