# Irrigation

Process

Irrigation system

Irrigation
T
R
P
S1
S2
S3
S4
S5
S6
S7
S8

# Inputs

IDAbbrevNameTypeDefaultDescription
triggerTTriggerBOOLEANfalse
resetRResetBOOLEANfalse

# Outputs

IDAbbrevNameTypeDefaultDescription
pumpPPumpBOOLEANfalseOutput for pump control
section_1S1Section #1BOOLEANfalseOutput for section #1 valve control
section_2S2Section #2BOOLEANfalseOutput for section #2 valve control
section_3S3Section #3BOOLEANfalseOutput for section #3 valve control
section_4S4Section #4BOOLEANfalseOutput for section #4 valve control
section_5S5Section #5BOOLEANfalseOutput for section #5 valve control
section_6S6Section #6BOOLEANfalseOutput for section #6 valve control
section_7S7Section #7BOOLEANfalseOutput for section #7 valve control
section_8S8Section #8BOOLEANfalseOutput for section #8 valve control

# Configuration

IDNameTypeDefaultUnitDescription
s1_enabledS1 enabledBOOLEANtrueControls if the section #1 is enabled
s1_durationS1 durationNUMBER600sTotal irrigation time in seconds for section #1

Details:

Visible whens1_enabled = true
≥ 0
s2_enabledS2 enabledBOOLEANfalseControls if the section #2 is enabled
s2_durationS2 durationNUMBER600sTotal irrigation time in seconds for section #2

Details:

Visible whens2_enabled = true
≥ 0
s3_enabledS3 enabledBOOLEANfalseControls if the section #3 is enabled
s3_durationS3 durationNUMBER600sTotal irrigation time in seconds for section #3

Details:

Visible whens3_enabled = true
≥ 0
s4_enabledS4 enabledBOOLEANfalseControls if the section #4 is enabled
s4_durationS4 durationNUMBER600sTotal irrigation time in seconds for section #4

Details:

Visible whens4_enabled = true
≥ 0
s5_enabledS5 enabledBOOLEANfalseControls if the section #5 is enabled
s5_durationS5 durationNUMBER600sTotal irrigation time in seconds for section #5

Details:

Visible whens5_enabled = true
≥ 0
s6_enabledS6 enabledBOOLEANfalseControls if the section #6 is enabled
s6_durationS6 durationNUMBER600sTotal irrigation time in seconds for section #6

Details:

Visible whens6_enabled = true
≥ 0
s7_enabledS7 enabledBOOLEANfalseControls if the section #7 is enabled
s7_durationS7 durationNUMBER600sTotal irrigation time in seconds for section #7

Details:

Visible whens7_enabled = true
≥ 0
s8_enabledS8 enabledBOOLEANfalseControls if the section #8 is enabled
s8_durationS8 durationNUMBER600sTotal irrigation time in seconds for section #8

Details:

Visible whens8_enabled = true
≥ 0

# State

IDNameTypeDefaultUnitDescription
activeactiveBOOLEANfalseIs irrigation currently active

# Source Code

View Volang source
channel = input::channel()

section_count = 8

fn disable_all(section_count) {
    section = 0
    while (section < section_count) {
        section += 1
        output::set(str::fmt("section_{}", section), false)
    }
}

extern fn onCallback(section_count, callback_id) {
    disable_all(section_count)

    current_section = 0
    if (callback_id == 0) {
        output::set("pump", true)
        callback::set(0, "onCallback", section_count, 1)
        return
    } else if (callback_id > 0 and callback_id < (section_count + 1)) {
        current_section = callback_id
    } else if (callback_id == (section_count + 1)) {
        output::set("pump", false)
        state::set("active", false)
        return
    }

    section_output = str::fmt("section_{}", current_section)
    section_enabled_cfg = str::fmt("s{}_enabled", current_section)
    section_duration_cfg = str::fmt("s{}_duration", current_section)

    section_enabled = config::get(section_enabled_cfg)
    section_duration = config::get(section_duration_cfg)

    if (!section_enabled) {
        callback::set(0, "onCallback", section_count, current_section + 1)
        return
    }

    output::set(section_output, true)
    callback::set(section_duration * 1000, "onCallback", section_count, current_section + 1)
}

input_value = input::value()

if (channel == "trigger" and input_value) {
    if (state::get("active")) {
        return
    }

    state::set("active", true)
    callback::set(0, "onCallback", section_count, 0)
    return
}

if (channel == "reset") {
    callback::clear()
    callback::set(0, "onCallback", section_count, section_count + 1)
    return
}
Irrigation system