24 VDC 3 wire ball valve with Shelly 2.5

I am in the process of setting up some automations in Home Assistant to have my irrigation line turned off if it detects a high flow rate via a flow meter with a hall sensor. I think I have the flow meter side handled but need some feedback on the valve side. I bought a Shelly 2.5 for it’s 2 relays, a 24 VDC power supply, and this 3 Wire AC/DC ball valve.

The valve uses this wiring diagram to open and close:
Valve 3 Wire Diagram

Here is the Shelly 2.5 DC wiring diagram:
Shelly 2.5 DC

After finally getting all the parts and following the DC Wiring diagram for the Shelly it doesn’t seem like my original idea will work using just the Shelly 2.5 in shutter roller mode. Does anyone have any suggestion on making it work with the Shelly 2.5? Is there an alternative DC wiring where I can control the (+) through the valve’s (OPEN) & (CLOSE) wires since it only has one (-) wire? If not the Shelly 2.5 I am open to suggestions for controlling this ball valve with an ESP 8266/32 with a relay board and can use the Shelly 2.5 for a different light project.

Pretty sure the shelly will work.

The Shelly outputs negative, you need a positive so you may need some relays to added to switch things around

1 Like

Yes I see what you are meaning.

Two relays and a esp8266 or esp32 would do this easily. You will probably want to use an interlock so you cannot turn both on at the same time. GPIO Switch — ESPHome

1 Like

Yup. Interlock was the thing I was looking for with the Shelly roller mode. I have some ATOM Lites that just arrived. One is going to be used for the flowmeter over by the livestock and the other I’ll use for the valve. Off to order some dual relays.

Thanks all for feedback.

Do be careful with the interlock - the warning is on the page I pointed to.


These are software interlocks. As such, a software bug (which can always happen) can still activate both switches at the same time. Similarly, at reset time (before any of ESPHome’s code runs) the relay GPIO pins may have pull-ups active, so the relay may be active before ESPHome can manually deactivate them.

So it is highly recommended to use hardware interlocks (like SPDT-type relays) that ensure that two GPIOs are never active at the same time.

For sure. I found some info using relays as a hardware interlock for AC motors. Now trying to see how to apply that to the DC valve.

Actually quite simple I think. What do you want to be the “fail” condition. IE if the relay for some reason fails. Presumable to close the valve? I’ll draw a circuit and post it later.

I just received 2 of these 24V Dual Relay Boards.

The condition would just be that when power is applied to one of the (+) wires of the valve, say OPEN Valve, then the other (+) CLOSE Valve, shouldn’t have power across it. I’ll be using a M5Stack ATOM Lite as the ESP32 device to trigger the relays.

For completeness I am using this 24V 40W power supply for the relay and valve and this 12/24V to 5V buck converter for the ATOM Lite. Also bought a fused distribution block to all go into an outdoor enclosure.

Only one relay is required and in fact it ensures interlock. See attached.

When the relay is NOT activated, the 24v is connected to the close pin on the valve. When the relay IS activated, 24v is connected to the open pin on the valve.

EDIT: Drew a better pic with ground wires and the buck convertor.

1 Like

OMG Durrr thank you, thank you, thank you! I feel like a goof. Here is my relay diagram:

(C) are the commons and the (T) are the GPIO triggers. GPIO X pins will trigger the power relay and GPIO Y will trigger the valve opening or closing. This way the valve doesn’t have constant power to it as it’s not necessary. The valve has auto stop once it’s fully open or closed but doesn’t need power to stay open or close, you can even open it 1/4 or 1/2 way if you time it right. It just stops moving once it loses power, which I may or may not use. Maybe when re-opening the valve to prevent water hammer.

So to close the valve I just turn on the power relay, GPIO X. To open the valve I’ll trigger the open valve relay GPIO Y, then trigger the power relay GPIO X, add a delay so it opens completely, then turn off both of the triggers.

Thank you so much again. I’ll post the pictures and YAML once the project is completed to help anyone else that can use this info.

Your way is just as valid, but a little more complex than I think it needs to be.

I’m worried about the wear and tear on the valve electronics leaving 24V across it at all time. I don’t have enough experience yet. Relays are cheap but the valves are expensive. Who knows maybe I’ll keep it to one relay. Thank you though again for the help.

Here’s a copy of the ESPHome yaml for this project for others to reference:

  name: flow_meter_livestock
  platform: ESP32
  board: m5stack-core-esp32

  ssid: "XXXXXXXX"
  password: "XXXXXXXX"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Flow Meter Livestock"
    password: "XXXXXXXX"


# Enable logging

# Enable Home Assistant API
  password: "XXXXXXXX"

  password: "XXXXXXXX"

## Device-specific

  - platform: pulse_counter
    pin: 21 #Change for your specific device
    id: livestock_water_usage
    name: "Livestock Flow Rate (GPM)"
    update_interval: 5s
    - lambda: return (x * 0.1);  #0.1 is the 0.1 gallons per pulse for my specific flowmeter
    unit_of_measurement: "Gallons/minute gpm"
  - platform: integration
    name: "Livestock Total Water Usage"
    unit_of_measurement: "Gallons"
    sensor: livestock_water_usage
    time_unit: min
  - platform: gpio
    name: "Valve Power"
    id: valve_relay_power
      number: 33 #Change for your specific device
      inverted: yes
  - platform: gpio
    name: "Valve Open/Close"
    id: valve_relay_control
    pin: 23 #Change for your specific device