# Hysteresis

Process

A threshold switch with hysteresis that analyzes an analog input value and switches a digital output accordingly. The hysteresis prevents frequent toggling when the value fluctuates around the threshold.

Hysteresis
V
O

# Inputs

IDAbbrevNameTypeDefaultDescription
valueVValueNUMBER0A numeric input that provides the measured or calculated value to be compared against the configured thresholds.

# Outputs

IDAbbrevNameTypeDefaultDescription
outputOOutputBOOLEANfalseA boolean output that switches based on the input value and configured thresholds with hysteresis.

# Configuration

IDNameTypeDefaultUnitDescription
modeHysteresis modeENUM0Defines how the hysteresis is configured: either using a midpoint with hysteresis range, or explicit on/off thresholds.

Details:

Values: Midpoint + Hysteresis, Threshold (On/Off)
midpointMidpoint valueNUMBER50.0The center point of the hysteresis range. Output turns on when value exceeds midpoint + hysteresis, and turns off when value falls below midpoint - hysteresis.

Details:

Visible whenmode = Midpoint + Hysteresis
hysteresisHysteresis rangeNUMBER5.0The range around the midpoint that creates the hysteresis effect. Must be greater than 0. Output switches at midpoint ± hysteresis.

Details:

Visible whenmode = Midpoint + Hysteresis
> 0
value_onValue output turns onNUMBER55.0The threshold value at which the output turns on. If value_on > value_off, output activates when value rises above this threshold. If value_on < value_off, output activates when value falls below this threshold.

Details:

Visible whenmode = Threshold (On/Off)
neq value_off
value_offValue output turns offNUMBER45.0The threshold value at which the output turns off. If value_on > value_off, output deactivates when value falls below this threshold. If value_on < value_off, output deactivates when value rises above this threshold.

Details:

Visible whenmode = Threshold (On/Off)
neq value_on

# Source Code

View Volang source
value = input::get("value")
output = output::get("output")
mode = config::get("mode") // 0=midpoint+hysteresis, 1=threshold

new_output = false

if (mode == 0) { // Midpoint + Hysteresis
    midpoint = config::get("midpoint")
    hysteresis = config::get("hysteresis")
    
    threshold_on = midpoint + hysteresis
    threshold_off = midpoint - hysteresis
    
    if (value >= threshold_on) {
        new_output = true
    } else if (value <= threshold_off) {
        new_output = false
    } else {
        // In hysteresis range, maintain current state
        new_output = output
    }
} else if (mode == 1) { // Threshold (On/Off)
    value_on = config::get("value_on")
    value_off = config::get("value_off")
    
    if (value_on > value_off) {
        // Standard hysteresis: on when high, off when low
        if (value >= value_on) {
            new_output = true
        } else if (value <= value_off) {
            new_output = false
        } else {
            // In hysteresis range, maintain current state
            new_output = output
        }
    } else {
        // Inverted hysteresis: on when low, off when high (value_off > value_on)
        if (value <= value_on) {
            new_output = true
        } else if (value >= value_off) {
            new_output = false
        } else {
            // In hysteresis range, maintain current state
            new_output = output
        }
    }
}

output::set("output", new_output)

A threshold switch with hysteresis that analyzes an analog input value and switches a digital output accordingly. The hysteresis prevents frequent toggling when the value fluctuates around the threshold.