[EXAMPLE] Irrigation zone control

Discussion in 'C-Bus Automation Controllers' started by Daggo, Feb 26, 2018.

  1. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    Just a simple manual zone control i have setup, might help others. I have another one for auto running through all stations if anyone needs too.

    Need to set zone2time levels in the object page (1 Minute) to level 1 and so on. Then in visualization set object vis parameter to display tags.

    Code:
      -- Checks if button was turned on or off
    value = event.getvalue()
    -- Gets user selected zone running time from on screen time per zone
    zone2time = GetUserParam('Local', 'zone2time')
    zoneoncheck = GetUserParam('Local', 'zoneon')
    
    if (value == 255) then
      -- Set value of user parameter 'zoneon' on local network to 2 this changes on screen display too ZONE 2 running
        SetUserParam('Local', 'zoneon', 2)   
      -- Set value of other zones to 0.
        SetCBusLevel(0, 113, 7, 0, 0)
        SetCBusLevel(0, 113, 6, 0, 0)
        SetCBusLevel(0, 113, 5, 0, 0)
        SetCBusLevel(0, 113, 4, 0, 0)
        SetCBusLevel(0, 113, 1, 0, 0)
      -- Set group 'Group 3' on application 'Irrigation' in network 'Local' to 255 over 0 seconds and after time reset to 0.
      PulseCBusLevel('Local', 'Irrigation', 'Group 3', 255, 0, zone2time * 60, 0)
      -- wait for zone2time to finish in seconds
      os.sleep(zone2time * 60)
      -- need to set this cbus level otherwise irrigation button stays on even tho its off with the pulsecbuslevel.
      SetCBusLevel(0, 113, 3, 0, 0)
      -- check to see if any other station are running if yes do nothing.
      value2 = GetUserParam('Local', 'zoneon')   
    if ( value2 == 2) then
      SetUserParam('Local', 'zoneon', 0)     
     end
      -- check to see if station 2 is running if yes then change stations status to off.
    elseif  (zoneoncheck == 2) then
      SetUserParam('Local', 'zoneon', 0)
    end
     
    Daggo, Feb 26, 2018
    #1
  2. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    Pressing button Turns on the zone you want plus turns off any other that might be on.
    Pressing button again or turning on another station will turn off the zone.
     
    Daggo, Feb 26, 2018
    #2
  3. Daggo

    Jake N

    Joined:
    Oct 9, 2018
    Messages:
    4
    Likes Received:
    0
    Hi Daggo

    Thanks for sharing your code, ive been having a hard time getting the 'basics' to work on the 5500SHAC. I will try your code out next its exactly what ive been trying to do... Could you also post the auto running version?

    Many thanks
     
    Jake N, Feb 17, 2019
    #3
  4. Daggo

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hi,

    Yes, interested in the auto irrigation logic. I'm already missing my CTC.

    Cheers,
    Paul
     
    pspeirs, Apr 17, 2019
    #4
  5. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    No worries will see if i can find where i saved it.
     
    Daggo, Apr 17, 2019
    #5
  6. Daggo

    CrazyDave

    Joined:
    Apr 24, 2019
    Messages:
    3
    Likes Received:
    0
    Location:
    Buseltion Western Australia
    any chance i would be able to get a copy aswell please.
     
    CrazyDave, May 1, 2019
    #6
  7. Daggo

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    I did something a little different.

    Set up the groups
    upload_2019-5-14_14-3-33.png


    Set up the page with sprinklers, etc
    upload_2019-5-14_14-4-45.png

    The main script runs the solenoids

    Code:
    -- object mapped to this event must have its data type set
    value = event.getvalue()
    
    num_sprinklers = 8
    
    -- If we have issues an OFF command, turn ALL valves OFF and reset timers
    if (value == 0) then
    
        -- Manually Stop Irrigation if it is running
        local irrigation_clock = 0
          SetUserParam('Local Network', 'Irrigation_Clock', 0)
          SetUserParam('Local Network', 'Irrigation_Clock_String', SecondsToClock(irrigation_clock))
    
        for idx = 1, num_sprinklers, 1
            do
            local sprinkler = string.format('sprinkler_%u', idx)
            SetCBusByKW({sprinkler}, 'or', {target = 0, ramprate = 0})
            --msg = string.format('Setting Sprinkler %u to OFF', idx)
            --log(msg)
        end
        
      
    else
        -- We have an ON command, so start the sprinkler sequence
        -- Check if the enable control group is enabled
        if (GetEnableState('Master Enable - Irrigation') == true) then
    
            -- For each sprinkler up to num_sprinklers
            for idx = 1, num_sprinklers, 1
                do
                
                if (GetCBusState('Local Network', 'Irrigation', 'Irrigation - Start') == true) then
    
                    local sprinkler = string.format('sprinkler_%u', idx)
                    local timer_label = string.format('sprinkler_%u_runtime', idx)
    
                    obj = GetCBusByKW(timer_label, 'or')[1]
    
                    if not obj.value then
                        msg = string.format('Check Sprinkler Runtime Group %u is configured correctly', idx)
                        log(msg)
                    else
                        -- Get the number of minutes to run this sprinkler
                        timer_on_value = (obj.value) * 60
                        if (timer_on_value > 0) then
                            -- Value of zero means sprinkler is not enabled
    
                               log(string.format('Setting Sprinkler %u ON for %u minutes', idx, timer_on_value))
                               SetUserParam('Local Network', 'Irrigation_Clock', timer_on_value)
        
                            SetCBusByKW({sprinkler}, 'or', {target = 255, ramprate = 0})
                        
                            while (GetUserParam('Local Network', 'Irrigation_Clock') > 0) do
                                os.sleep(1)
                            end
    
                            os.sleep(2)
    
                            SetCBusByKW({sprinkler}, 'or', {target = 0, ramprate = 0})
                            log(string.format('Setting Sprinkler %u OFF', idx))
    
                            os.sleep(2)
    
                        
                        else
                            log(string.format('Sprinkler %u currently disabled', idx))
                    
                        end
                    end
                end
            end
        end
        
        SetCBusState('Local Network', 'Irrigation', 'Irrigation - Start', false)
    
    end
    

    Using this to format a clock string

    Code:
    -- convert seconds to clock
    function SecondsToClock(seconds)
      local seconds = tonumber(seconds)
    
      if seconds <= 0 then
        return "00:00:00";
      else
        hours = string.format("%02.f", math.floor(seconds/3600));
        mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
        secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
        return hours..":"..mins..":"..secs
      end
    end

    The following is part of a 1 second timer script

    Code:
    -- ************ Irrigation Timer ************ 
     
      irrigation_clock = GetUserParam('Local Network', 'Irrigation_Clock')
    
    if (irrigation_clock > 0) then
        SetUserParam('Local Network', 'Irrigation_Clock', irrigation_clock - 1)
        SetUserParam('Local Network', 'Irrigation_Clock_String', SecondsToClock(irrigation_clock))
        --SetUserParam('Local Network', 'Irrigation_Clock', irrigation_clock - 1)
    else
        SetUserParam('Local Network', 'Irrigation_Clock_String', SecondsToClock(0))
    end
    
    The Scheduler is set up for different times depending on the season.
    upload_2019-5-14_14-12-9.png



    There are probably a few other bits and pieces holding it together but that should be the most of it.
     
    pspeirs, May 14, 2019
    #7
    MarkB likes this.
  8. Daggo

    GlenF

    Joined:
    Jan 22, 2006
    Messages:
    130
    Likes Received:
    0
    Hi pspeirs,

    Was going to have a go at implementing this so was hoping you might be able to help a little.

    When you say a few other bits and pieces holding this together, is there anything specific you can think of?

    Is the list at the top the only objects you needed to define?

    I can probably guess and embarrass myself, however, can you please tell me where each of these three areas of code are run from / triggered ie I am guessing main script is inside the schedules but where are the clock and 1 sec timer?

    Thanks in advance. As you might have worked out, not great at this but keen to learn and have a go.

    Glen
     
    GlenF, Aug 2, 2021
    #8
  9. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    value = event.getvalue()
    zone1time = GetCBusLevel('Local', 'Irrigation', 'zone1time')
    zoneoncheck = GetUserParam('Local', 'zoneon')

    if (value == 255) then
    -- Set value of user parameter 'now_temp' on local network to 12.1
    SetUserParam('Local', 'zoneon', 1)
    SetCBusLevel(0, 113, 7, 0, 0)
    SetCBusLevel(0, 113, 6, 0, 0)
    SetCBusLevel(0, 113, 5, 0, 0)
    SetCBusLevel(0, 113, 4, 0, 0)
    SetCBusLevel(0, 113, 3, 0, 0)
    -- Set group 'Group 1' on application 'Irrigation' in network 'Local' to 255 over 0 seconds and after time reset to current level.
    PulseCBusLevel('Local', 'Irrigation', 'Group 1', 255, 0, zone1time * 60, 0)
    -- wait for 1.5 seconds
    os.sleep(zone1time * 60)
    SetCBusLevel(0, 113, 1, 0, 0)
    value2 = GetUserParam('Local', 'zoneon')

    if ( value2 == 1) then
    SetUserParam('Local', 'zoneon', 0)
    end

    elseif (zoneoncheck == 1) then
    SetUserParam('Local', 'zoneon', 0)
    end
     
    Daggo, Sep 15, 2021
    #9
  10. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    thats a script for zone 1
    each zone has its own script
     
    Daggo, Sep 15, 2021
    #10
  11. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    I did this quite some time tho. Zone 2 below

    value = event.getvalue()
    zone2time = GetCBusLevel('Local', 'Irrigation', 'zone2time')
    zoneoncheck = GetUserParam('Local', 'zoneon')

    if (value == 255) then
    -- Set value of user parameter 'zoneon' on local network to 2 this changes on screen display to ZONE 2 running
    SetUserParam('Local', 'zoneon', 2)
    -- Set value of other zones to 0.
    SetCBusLevel(0, 113, 7, 0, 0)
    SetCBusLevel(0, 113, 6, 0, 0)
    SetCBusLevel(0, 113, 5, 0, 0)
    SetCBusLevel(0, 113, 4, 0, 0)
    SetCBusLevel(0, 113, 1, 0, 0)
    -- Set group 'Group 3' on application 'Irrigation' in network 'Local' to 255 over 0 seconds and after time reset to 0.
    PulseCBusLevel('Local', 'Irrigation', 'Group 3', 255, 0, zone2time * 60, 0)
    -- wait for zone2time to finish in seconds
    os.sleep(zone2time * 60)
    -- need to set this cbus level otherwise irrigation button stays on even tho its off with the pulsecbuslevel.
    SetCBusLevel(0, 113, 3, 0, 0)
    -- check to see if any other station are running if yes do nothing.
    value2 = GetUserParam('Local', 'zoneon')
    if ( value2 == 2) then
    SetUserParam('Local', 'zoneon', 0)
    end
    -- check to see if station 2 is running if yes then change stations status to off.
    elseif (zoneoncheck == 2) then
    SetUserParam('Local', 'zoneon', 0)
    end
     
    Daggo, Sep 15, 2021
    #11
  12. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    13
    Likes Received:
    0
    I think from memory i used the scheduler to start the script this manual run script will cycle through all stations if they are on i added a button to the screen so the user can manually start the script whenever they want too, which will run through every station if they are on.
    manualstart.PNG screen.PNG
     
    Daggo, Sep 15, 2021
    #12
  13. Daggo

    Ron Arends

    Joined:
    Apr 4, 2018
    Messages:
    6
    Likes Received:
    0
    Hi, sorry to bother you, I have irrigation running via schedule and turn on/off via its page. I was curious how I could create a disable button like yours. This way, when it's raining the sprinklers will not come on. Thanks Ron
     
    Ron Arends, Dec 1, 2021
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.