[EXAMPLE] Irrigation zone control

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

  1. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    9
    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
    1. Advertisements

  2. Daggo

    Daggo

    Joined:
    Feb 21, 2018
    Messages:
    9
    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
    1. Advertisements

  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:
    129
    Likes Received:
    4
    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:
    9
    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
    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:
    129
    Likes Received:
    4
    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
    1. Advertisements

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.