Electronic Water or Gas Valve using ST_Anything HubDuino

Our buddy Jason Churchward is back with a new post, showing us how to automate a valve using ST_Anything Hubduino!

I required a solution to being able to turn on and off my main water valve to my house when for example flooding is detected inside the house in a specific location or when the house is set to holiday mode my wife and I like everything turned off as we might not be back for weeks. As such I started my search on my favourite site being AliExpress looking for components.

In addition, I reached out to Dan (ogiewon) who with his son developed the ST_Anything HubDuino platform (these guys are legends). He advised that he could create a new class for this valve to operate and swiftly and I mean swiftly created it ready for use… the guy is awesome!! Thanks again Dan!!

**initial concept idea design diagram

After some digging around on AliExpress I found the following components:

Note: you will obviously need some electrical cable, shrink wrap and a spare USB cable. I found all of this around the house to re-use that was perfectly fine for the job. In addition, I installed this all within a small water tight box from my local electronics store.

The physical wiring configuration I used to connect the WeMos D1 Mini to the 2-channel relay and the Water Valve to the relay module is shown below:

2 channel Relay Module – WeMos D1 Mini to 2-Channel Relay Module
5v pin on WeMos D1 Mini to VCC pin on 2-Channel Relay Module
GND pin on WeMos D1 Mini to GND pin on 2-Channel Relay Module
D5 pin on WeMos D1 Mini to IN1 pin on 2-Channel Relay Module
D6 pin on WeMos D1 Mini to IN2 pin on 2-Channel Relay Module

12v Power and DC Motor Valve Connections
DC Motor positive wire to 2-Channel Relay switch 1 COM input
DC Motor negative wire to 2-Channel Relay switch 2 COM input
3pin wiring 12v battery positive wire to Relay switch 1 NO & Relay switch 2 NO
3pin wiring 12v battery negative wire to Relay switch 1 NC & Relay switch 2 NC

Now onto the software side. I personally use Hubitat as my home automation system (sorry not sorry!!) so some of the following is specific to that system. On the WeMos D1 Mini I configured and installed ST_Anything HuDuino see (here). I won’t go into how you load the software and sketches using the Arduino IDE (here) and the specific configurations with ST_Anything HuDuino sketches as it’s fairly well documented in their Github site but I will call out some specific key sketch changes I needed to apply for this project to work.

#define PIN_TIMEDRELAY_1 D5 //SmartThings Capability “Relay Switch”
#define PIN_TIMEDRELAY_2 D6 //SmartThings Capability “Relay Switch”

static st::EX_TimedRelayPair executor1(F(“valve1”), PIN_TIMEDRELAY_1, PIN_TIMEDRELAY_2, HIGH, true, 7000, 7000);

Once you have configured and uploaded the sketch to the WeMos D1 Mini you then configure your Hubitat (HE) drivers but again no point going into this as it’s all well documented on their Github site too.

Anyways if you have any questions, I am sure you can get help from either the author of ST_Anything HuDuino or I am happy to help where I can too.

Anyways good luck and enjoy and I hope this article shed some light for you!!

SmarterHome.club is the website for our Facebook community, The Smarter Home Club – which is an umbrella for all kinds of smart home technologies – home automation, security, custom electronics, weather stations, alternative energy, you name it. DIY focused.

If you’re interested in joining the Smarter Home Club’s Facebook group, please follow this link:

The Smarter Home Club on Facebook