OpenSprinkler Integration with SHAC

Discussion in 'C-Bus Automation Controllers' started by jasonson, Oct 13, 2018.

  1. jasonson

    jasonson

    Joined:
    Feb 17, 2014
    Messages:
    34
    Likes Received:
    6
    Location:
    Brisbane
    I am playing with a Pi-Zero running OsPi (Open Sprinkler) as test for a cheap irrigation controller that has a decent integration with Weather Underground and automatic rain delays, technical operating based on climatic conditions etc..

    You can set the zones in OS to send an HTTP command. So I wrote a very basic (no real error handling) server that runs on the SHAC to accept commands from the OS and operate the Group Address associated with my irrigation zones.

    It may not be something I would do professionally, I am just playing around home while its raining outside but it may be of use to someone else.

    Example zone setup in OpenSprinkler
    [​IMG]

    example code in the SHAC as a resident script with 0 sec interval:
    Code:
    local socket = require("socket")
    -- create a TCP socket and bind it to the local host, at port 9001
    local server = assert(socket.bind("*", 9001))
    -- loop forever waiting for clients
    while 1 do
      -- wait for a connection from any client
      local client = server:accept()
      -- make sure we don't block waiting for this client's line
      client:settimeout(3)
      -- receive the line
      local line, err = client:receive()
      -- if there was no error, and it received something decode it and act on it.
      if not err and line ~="" then
        --Get zone number from command
        local ZoneNum = tonumber(line:sub(6,7))
        --Get zone state from command
        local ZoneState = toboolean(tonumber(line:sub(8,8)))
        --In application 113, set ZoneNum to ZoneState
          SetCBusState(0, 113, ZoneNum, ZoneState)
        --log instruction for debugging.
        log("Zone: ".. ZoneNum.. " was set to ".. tostring(ZoneState))
      end
      --Sleep
      socket.sleep(1)
    end
    
     

    Attached Files:

    jasonson, Oct 13, 2018
    #1
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.