Post

Logic Gates

Boolean logic operations (AND, OR, NOT, XOR, etc.) for conditional automation workflows.

Logic Gates

Logic Gates: Boolean Logic for Smart Automation

Logic Gates bring the power of boolean logic to your automation workflows, enabling conditional execution based on the states of data points and GPIO pins. With support for all standard logic operations, you can build sophisticated decision trees and state machines.

Info: This is an Executor node type that can be executed to perform work by the execution of a parent node. Logic Gates evaluate their inputs and produce a boolean result that can control downstream automation.

Info: This feature uses TargetingNodeMetaData, which means it can be configured to read from source nodes (Data Points or Pins) and write boolean results to target nodes. This enables complex logic chains across your automation system.

Overview

Logic Gates evaluate boolean inputs from GPIO pins or data points and produce a boolean output. The result can control other pins, update data points, or conditionally execute child workflows. This is essential for building intelligent automation that responds to multiple conditions.

Supported Logic Operations

Gate TypeInputsDescriptionOutput
AND2Both inputs must be trueTRUE if both inputs are TRUE
OR2Either input can be trueTRUE if any input is TRUE
NOT1Inverts the inputTRUE if input is FALSE
NAND2NOT AND (inverted AND)TRUE if any input is FALSE
NOR2NOT OR (inverted OR)TRUE if both inputs are FALSE
XOR2Exclusive ORTRUE if inputs are different
XNOR2Exclusive NOR (inverted XOR)TRUE if inputs are the same
BUFFER1Passes through unchangedTRUE if input is TRUE

Logic Gate Processing Flow

graph TD
    A[Parent Executes Logic Gate] --> B[Read Source 1 State]
    B --> C{Two Inputs<br/>Required?}
    C -->|Yes| D[Read Source 2 State]
    C -->|No| E[Apply Logic Operation]
    D --> E
    E --> F{Result = TRUE?}
    F -->|Yes| G[Execute Child Nodes]
    F -->|No| H[Skip Children]
    G --> I[Write to Target]
    H --> I
    I --> J[Complete]

How It Works

When a logic gate executes:

  1. Read Input 1: Fetches boolean state from first source (Pin or DataPoint)
  2. Read Input 2 (if needed): Fetches state from second source for 2-input gates
  3. Validation: Ensures required inputs are configured
  4. Logic Evaluation: Applies the selected gate operation to the inputs
  5. Target Update: Writes the boolean result to target Pin or DataPoint
  6. Conditional Execution: If result is TRUE, executes all child nodes

Input Source Types

Logic Gates can read from:

  • GPIO Pins (KrillApp.Server.Pin): Reads digital state (ON/OFF)
  • Data Points (KrillApp.DataPoint): Interprets value as boolean (1.0 = TRUE, 0.0 = FALSE)

Output Target Types

Logic Gates can write to:

  • GPIO Pins: Sets pin state to ON (TRUE) or OFF (FALSE)
  • Data Points: Creates snapshot with 1.0 (TRUE) or 0.0 (FALSE)

Configuration

FieldDescriptionRequired
gateTypeType of logic gate (AND, OR, NOT, etc.)Yes
sourcesList of source node IDs (1 or 2 depending on gate)Yes
targetsList of target node IDs (typically one)Yes

Use Cases

  • Safety Interlocks: Use AND gates to require multiple conditions before enabling equipment
  • Redundancy: Use OR gates for backup sensor redundancy
  • Alarm Conditions: Combine multiple sensor states to trigger alerts
  • State Machines: Build complex state logic with multiple gates
  • Conditional Routing: Direct data flow based on multiple conditions
  • Emergency Stops: NOT gate for stop button logic
  • Change Detection: XOR gate to detect state changes

Example Workflows

Safety Interlock (AND Gate):

  1. Input 1: Temperature Below Threshold (DataPoint)
  2. Input 2: Safety Switch Closed (Pin)
  3. Logic Gate: AND
  4. Output: Enable Heater (Pin)
  5. Children: Only execute if both conditions are met

Multi-Sensor Alarm (OR Gate):

  1. Input 1: Motion Sensor 1 (Pin)
  2. Input 2: Motion Sensor 2 (Pin)
  3. Logic Gate: OR
  4. Output: Alarm State (DataPoint)
  5. Children: Send notification if either sensor triggered

Inversion Control (NOT Gate):

  1. Input: Emergency Stop Button (Pin)
  2. Logic Gate: NOT
  3. Output: System Enable (DataPoint)
  4. Children: Normal operation when stop is NOT pressed

State Change Detection (XOR Gate):

  1. Input 1: Previous State (DataPoint)
  2. Input 2: Current State (DataPoint)
  3. Logic Gate: XOR
  4. Output: State Changed Flag (DataPoint)
  5. Children: Log change event

Cascading Logic Gates

Logic Gates can be chained together to create complex boolean expressions:

1
2
3
4
5
6
7
Sensor1 ─┐
         ├─ AND ─┐
Sensor2 ─┘       │
                 ├─ OR ── Enable
Sensor3 ─┐       │
         ├─ AND ─┘
Sensor4 ─┘

This creates: (Sensor1 AND Sensor2) OR (Sensor3 AND Sensor4)

Integration Points

  • Pins: Direct hardware control for physical systems
  • Data Points: Store and log decision results
  • Triggers: Use thresholds and timers as inputs
  • Executors: Control downstream automation execution

Logic Gates are essential for building intelligent, condition-based automation systems with complex decision logic.

This post is licensed under CC BY 4.0 by the author.