# Toggle

Verarbeitung
Toggle
TG
ON
OFF
O
ON
OFF

# Eingänge

IDKürzelNameTypStandardBeschreibung
inputTGinputBOOLEANfalse
onONonBOOLEANfalse
offOFFoffBOOLEANfalse

# Ausgänge

IDKürzelNameTypStandardBeschreibung
outputOoutputBOOLEANfalse
onONonBOOLEANfalse
offOFFoffBOOLEANfalse

# Zustand

IDNameTypStandardEinheitBeschreibung
last_input_statelast_input_stateBOOLEANfalse
last_on_statelast_on_stateBOOLEANfalse
last_off_statelast_off_stateBOOLEANfalse

# Quellcode

Volang-Quellcode anzeigen
pulse_ms = 100
channel = input::channel()
value = input::value()

// Single callback handler - resets both pulse outputs
// Only one callback can be active at a time per block
extern fn onCallback(unused) {
    output::set("on", false)
    output::set("off", false)
}

// Handle "off" input first (dominant input)
if (channel == "off") {
    last_off_state = state::get("last_off_state")

    if (value and !last_off_state) {
        // Rising edge on off input - turn off output
        prev = output::get("output")
        if (prev) {
            output::set("output", false)
            callback::clear()
            output::set("on", false)
            output::set("off", true)
            callback::set(pulse_ms, "onCallback", 0)
        }
    }

    state::set("last_off_state", value)
    return
}

// If off input is held high, block is locked - ignore other inputs
// Still track input states to avoid false edges after unlock
if (state::get("last_off_state")) {
    if (channel == "input") {
        state::set("last_input_state", value)
    } else if (channel == "on") {
        state::set("last_on_state", value)
    }
    return
}

// Handle "on" input
if (channel == "on") {
    last_on_state = state::get("last_on_state")

    if (value and !last_on_state) {
        // Rising edge on "on" input - turn on output
        prev = output::get("output")
        if (!prev) {
            output::set("output", true)
            callback::clear()
            output::set("off", false)
            output::set("on", true)
            callback::set(pulse_ms, "onCallback", 0)
        }
    }

    state::set("last_on_state", value)
    return
}

// Handle toggle input
if (channel == "input") {
    last_input_state = state::get("last_input_state")

    // Only react to rising edge (false -> true)
    if (value and !last_input_state) {
        prev = output::get("output")
        output::toggle("output")
        callback::clear()
        output::set("on", false)
        output::set("off", false)
        if (prev) {
            // Was on, now off - emit off pulse
            output::set("off", true)
        } else {
            // Was off, now on - emit on pulse
            output::set("on", true)
        }
        callback::set(pulse_ms, "onCallback", 0)
    }

    state::set("last_input_state", value)
}
Erfahren Sie, wie der Logikbaustein Toggle funktioniert, wann Sie ihn einsetzen und wie Sie ihn in Ihrer Voldeno Smart-Home-Automatisierung konfigurieren.