Last modified: 5.7.2018

started: 7.8.2017

My goal is to be able to control water flow to and from my hot-tub from the internet. I will be using the system VoffCon to handle the commands via the internet.

I will probably need to connect my pipes like I drew on the image below. By doing it that way I should be able to control the water both manually and electricity. When I will be controlling the water electricity I will open(turn on) the Heat-mixer and close both of the manual valves. In both cases I will be able to make water flow, to and from the hot tub.

The plan

Controlling the water flow to and from the hottub electricity:

  • Start by turning on the Water heat-mixer (Blöndunartæki) and closing H1 and H2
  • Make water flow
    to the hot
    by opening R1 and closing R2
    from the hot tub
    by closing R1 and opening R2


Inni í skúr
Inside my garage
Blöndunar tæki
Water heat-mixer (like the one you use in your bath-tub)
Þetta rör liggur út
This pipe leads out and to the drain
Þetta rör liggur í pottinn
This pipe leads to the hotTub
90° bend
T shaped pipe snippet
Loki Handvirkur
manual valve
Loki Rafmagn
Electric valve

I will need to buy

Loki - Handvirkur
Loki - Rafmagn

How to it's wired up

This drawing of mine illustrates how I connected this project. We have three kinds of voltages. 220 Volts, to move the valves. 5 Volts to open and trigger the relays and give the micro controller(Esp32) power. The Esp32 pins data pins operate on 3.3 volts so we need to be careful only to connect the 5V to the VIN on the micro controller. But it is ok to connect the pins directly to the IN1, IN2, IN3 and IN4 pins on the relay. 5V and the 3.3V can and should share the same GND.

How to wire the circuits

Images of the project

Images from my garage 11.1.2018 : 10:02

image 1 image 2
image 3

The project prototype in action

Wooden box around the project

You can click this image to view the design in 3D.

Box built, and with 4 light diodes added

The Code

I will be using a motorized valve for R1 which will take time to open, and time to close. For R2 was going to use a solenoid valve but decided to use a motorized valve for that also.

I wanted to be able to control how much the valve should be open. For that I wrote the class Valve. You can see the class file valve.h here below.

And to use the class, I wrote a small program which will read a number from the Serial and open or close the valve according to the value given. I do not know how long it will take to fully open the motorized valve because I have not yet received the valve I ordered from aliexpress. Here I'm guessing it will take 3 seconds. I will need to experiment to figure out how long this takes.

#include "Valve.h"

const int closePin = 5;
const int openPin = 6;

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

Valve valve(openPin, closePin, 255, 3000);

void setup() {

void onSerialCommandComplete(){
  inputString.replace("\n", "");
  stringComplete = false;
  int newValue = inputString.toInt();
void loop() {
  if (stringComplete) {

  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
void serialEvent() {
  while (Serial.available()) {
    char inChar = (char);
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;

This is how the deviceServer hottub.ino for the Esp32 looks like. It is not much modified from the original device server. It includes and uses the Valve class (valve.h). And there are added some constraints when setting the valve values to be sure that no one is able to ruin the valves them selves. I would think that the valves could be destroyed if current was flowing through relays "R1 open" and "R1 close".

To see the changes look for the values valveFill (R1) and valveDrain (R2).

I‘ve created a control Card and a control for the hot tub. They are both written in JavaScript and are run by the VoffCon server.

The VoffCon control Card:

    // Comming soon

VoffCon Control javascript class:

//comming soon 

VoffCon Control html template:

//comming soon 

The pipes

4.7.2018 we layed the pipes like this. Out side the garage (other side of the wodden board there are garden hoses to carry the water to and from the hottub. The orange boxes with the motors have not yet been put on on R1 and R2.

How we layed the pipes

The project in action

5.7.2018 connected the project and put the electric motors on the valves R1 and R2. This is the final result. I consider this project a success, I am able to fill and drain my hottub from anywhere.

2.8.2018 Now giving voice commands to the hot tub :)

By using Goolge Assistant and I am now able to control the hot tub by talking to it.