Nodes/NH-Nodes/Logic Gate (NH)
ComfyUI Node

Logic Gate (NH)

The boolean brain your workflow keeps not having

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Logic Gate (NH)
    • result
    afalse
    op
    bfalse

    Once your workflow grows a second boolean, you're going to want to combine them. Logic Gate (NH) (class NH_LogicGate) is the pack's AND/OR/NOT/XOR/NAND/NOR node - the small brain that turns two true/false inputs into one result. It's dead simple, which is the point. Every switch-heavy graph eventually needs "run this branch only if A is on AND B isn't," and this is the node that says it in one socket instead of a tangle.

    How it works

    Two boolean inputs, a (required) and b (optional), plus an op dropdown with the six standard gates. It computes the result and outputs a single BOOLEAN. Nothing fancy under the hood - it's literally the truth tables - but the details matter:

    • AND / OR / XOR / NAND / NOR - two-input gates; b does the work.
    • NOT - unary. It inverts a and ignores b entirely. Unwired b defaults to false, so NOT with an unwired b gives you not a, which is what you want.

    Output result is a proper BOOLEAN, so it wires straight into any NH switch, gate, or If/Else-style node that takes a boolean condition.

    Where you'd actually use it

    Anywhere you have two conditions that should both gate something. Classic example: "process this image only when the batch has content AND a certain mode is enabled." Chain two logic gates and you get "A OR (B AND C)" without a custom script node. It pairs naturally with the rest of the NH logic layer - List Index (NH)'s is_first/is_last flags, Load images matching's found output, or any Compare (NH) result. The plumbing-doc framing applies here: ComfyUI is a program with no keyboard, and the gate is how you write an if without typing one.

    Installing

    ComfyUI Manager → search NH-Nodes → install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jetthuangai/NH-Nodes.git
    cd NH-Nodes
    pip install -r requirements.txt
    

    Restart and refresh the browser page. Zero dependencies beyond the standard library.

    Gotchas

    The one real trap is NOT with b connected - the node ignores b, and people occasionally expect a NOT b to be a thing. It isn't; if you want "a and not b," chain NOT then AND. Also worth saying: this works on booleans only, not on "truthy" values - a string or a number won't coerce, so feed it real BOOLEAN outputs. And one from experience: gate nodes are easy to lose in a big graph, so label them (or use the pack's Boolean Switch values upstream) or you'll be hunting for which gate decided what.

    CategoryNH-Nodes/Logic

    Inputs (3)

    NameTypeDefaultDescription
    aBOOLEANfalse
    opCOMBO6 options: AND, OR, NOT, XOR, NAND, NOR
    boptBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    resultBOOLEAN