# Hysteresis
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
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
value | V | Value | NUMBER | 0 | A numeric input that provides the measured or calculated value to be compared against the configured thresholds. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | A boolean output that switches based on the input value and configured thresholds with hysteresis. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
mode | Hysteresis mode | ENUM | 0 | Defines how the hysteresis is configured: either using a midpoint with hysteresis range, or explicit on/off thresholds. Details: Values: Midpoint + Hysteresis, Threshold (On/Off) | |
midpoint | Midpoint value | NUMBER | 50.0 | The 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 when mode = Midpoint + Hysteresis | |
hysteresis | Hysteresis range | NUMBER | 5.0 | The range around the midpoint that creates the hysteresis effect. Must be greater than 0. Output switches at midpoint ± hysteresis. Details: Visible when mode = Midpoint + Hysteresis> 0 | |
value_on | Value output turns on | NUMBER | 55.0 | The 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 when mode = Threshold (On/Off)neq value_off | |
value_off | Value output turns off | NUMBER | 45.0 | The 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 when mode = 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)
