nebhead / irrigator

Smart Sprinkler Controller for the Raspberry Pi
MIT License
27 stars 3 forks source link

Question: When using first relay as gate/control? Is it always powered when values are in use? #1

Closed Jibun-no-Kage closed 1 year ago

Jibun-no-Kage commented 1 year ago

Question: When using first relay as gate/control? Is it always powered when values are in use?

Just want to confirm I under the logic, so say relay 0 is your gate/control. And valve 1 uses relay 1, valve 2 uses relay 2, etc. Thus, to actually open valve 1, relay 0 must be closed, as well as relay 1 right?

Value 1, Relay 1 Closed, And Relay 0 Closed -> Flow Value 1, Relay 1 Open, And Relay 0 Closed -> No Flow Value 1, Relay 1 Closed, And Relay 0 Open -> No Flow Value 1, Relay 1 Open, And Relay 0 Open -> No Flow

I happen to be using a ESP8266 controlled relay board, and on power on, relays happen to be in a known state, so I don't technically need a gate/control. However, using a gate/control, does protect from a frozen relay fault. Since the relays are mechanical, is there not a chance that the relay can freeze in a closed state? By turning off the gate/control the given valve even if stuck, no water flow possible and vice-a-versa.

nebhead commented 1 year ago

The way I have wired this up (and with active low relays) the 'gate' relay is really only there to prevent errant valve activation during boot-up/resets. Honestly, it was more of an after thought in this particular design. So the software doesn't ever change this gate relay in the current configuration. It's just wired in the NC (normally connected) position, such that it will allow the flow of electricity when the output is set to 1. So when the system is powering up and let's just say all outputs go to a zero or a one, the gate should prevent them from activating regardless. I hope this makes sense. But let me know if you need clarification.

If you wanted to add the functionality to turn the gate pin off when not watering, you can definitely do that by modifying the following in control.py.

def Irrigate(platform, zonename, duration, json_data_filename):
    # *****************************************
    # Function: Irrigate
    # Input: platform, str zonename, int duration, str json_data_filename
    # Description: Turn on relay for duration
    # *****************************************
    errorcode = 0

    event = f"Turning on Zone: {zonename} for {duration} minutes."
    WriteLog(event)
    errorcode = errorcode + platform.setrelay(0, zonename) # Turning on Zone
        platform.setrelay(0, 'gate')  """ADD THIS LINE"""

    starttime = time.time()
    now = starttime

    while(now - starttime < (duration*60)):
        if(CheckOverride(json_data_filename) > 0):
            break
        else:
            time.sleep(1)  # Pause for 1 Second
        now = time.time()

    event = f"Turning off Zone: {zonename}."
    WriteLog(event)

    errorcode = errorcode + platform.setrelay(1, zonename) # Turning off Zone
    platform.setrelay(1, 'gate')  """ADD THIS LINE"""

        if (CheckOverride(json_data_filename) > 0):
        errorcode = 42

    return(errorcode)

OR you could optionally modify the following in the platform_raspi.py:

        def setrelay(self, value, zonename):
        try: 
            GPIO.output(int(self.outpins['gate']), not value) """ ADD THIS LINE """
                        GPIO.output(int(self.outpins[zonename]), value)
        except:
            print(f'An exception occurred when changing zone {zonename} to {value}')
            raise
            return(1)
        return(0) # Return ErrorCode = 0
Jibun-no-Kage commented 1 year ago

Yeah, I was thinking you where actively controlling the logic via the relay state, but I now see I missed that it was configured to NC, so it is acting like a logical AND gate, literally. It is pretty cool actually when I saw it. The python code illustrates well, thanks for including it. I actually have Tasmota on the ESP8266 that is integrated to my relay board, so I was planning to use MQTT via Node Red to create the front-end. But using python is an option as well.

I have always used Node Red or Python, but heck you could even use bash/shell script and drive the GPIO state directly as well, what where is the fun in that? :)