Software apps and online services
Hand tools and fabrication machines
My oldest daughter is nearly a teenager, and I've learned that the length of hot showers frequently expands to the capacity of our hot water heater.
Hopping into the shower, only to discover that the hot water is nearly gone is a chilling experience. I designed and built the Hot Water Monitor to measure hot water flow and the water temperatures necessary to approximate the heated state of my hot water heater.
Now I have an Alexa Skill, and I can ask "How long can I shower?"
This project has many components and things that must be configured properly. The code auto configures itself whenever possible, but that isn’t always possible. The code is currently set up to work with an electric hot water heater, and report values in gallons. Adjustments can be made to accomodate gas heaters as well as report values in metric units.
I highly recommend building this on a breadboard first for testing, and then wiring it up on a protoboard. If you don’t have one for the Wemos D1 Mini, you can easily use any generic protoboard cut down to the right size.
Most of the connections are Ground and Vcc (3.3v) connections. Each of the three components have a resistor as well.
The flow meter comes with a female JST connector. I found the easiest way to test this on a breadboard was by soldering some header pins to a male JST connector for easy connection to the breadboard. The 100 ohm resistor is used to pull the data pin to ground.
The specs indicate that the flow meter expects 5 volts, but it works reliably at 3.3 volts. You can (carefully) run water through the sensor from a faucet to test, but blowing through it works fine for generating test data.
We use two identical temperature sensors to measure the temperature of the inbound and outbound water temperatures on your hot water heater. You’ll need to measure the sensor placements in advance to know how long to make the wires.
These MAX31820 sensors are 1-Wire sensors, and are connected to the same pins on the Arduino.
A 4.74 kohm resistor ties the temperature sensor data pin high. 1-Wire devices can use power from the data pin, but I supplied power to the power pins anyway.
Neopixel Status Light
The Neopixel status light will help indicate problems with the wifi connection. You’ll see it change color when it connects, and if it fails to report values, it’ll change colors to help you know that is happening as well.
Any Neopixel will work here. I used one pixel from a strip leftover from a previous project, but you can use any other form factor and it’ll work fine.
Do remember to use a 330 ohm resistor on the data pin. The connection was short enough that I just used the resistor as the data wire!
If you don’t want to spend for a neopixel, you can leave it off or modify the code and replace it with a simple LED.
Installing the Flow Meter
Installing the flow meter will require adjusting your water input pipes, but doesn’t require general plumbing skills. We’ll be installing the sensor on the water input pipe. This pipe will generally be colder when hot water is running. Don’t leave the flow meter connected to your microcontroller when you do this. There is a risk of water splashing out onto your board and causing issues.
Before you loosen the existing pipe connections, make sure to turn off the hot water heater and TURN OFF THE WATER SUPPLY. You can shut off the whole house, or just turn off the water input to the hot water if you have a valve there. Even with the water turned off, you’ll have some water come out of the connection. Depending on your plumbing setup, this may be a few gallons or more. Have a few towels on hand and a small bucket or plastic tub to catch the water. When you loosen the connection, don’t undo it all the way until water has stopped draining out. I ‘paused’ it several times by tightening the connection, and then emptying my plastic tray. Some of this water may be hot, if water is being pushed backwards through the hot water heater during draining. If the water is too hot, give it a few hours for the water to cool down before continuing.
Unscrew the one end, then screw the meter in on the end of the old pipe. Make sure you get the flow direction correct for the flow meter. There is an arrow on the outside indicating proper flow direction. Screw your new section of flexible pipe on the end of the sensor, then back onto the pipe you disconnected it from earlier. You’ll need to use your wrenches to tighten the connection, but don’t over tighten them. The rubber gaskets in the end of each pipe will compress to form a watertight seal.
You’ll need to bend the flexible copper pipes to get them into position. Go slowly, and be careful not to crease the pipe. If you do crease the pipe by bending it too tightly, you’ll need to replace that pipe or risk a water leak. You may want to make sure you do this installation during hours when a hardware store is open, in case you need another pipe.
When you have all the connections made, slowly turn the water back on. You’ll hear some water flowing to replace the water that drained out, but no water should be leaking from any of your connections. If there is any water leaking at all, turn the water back off and tighten the connection.
For both Lambda and the API Gateway, you’ll need an AWS developer account. You can get started for free, and limited use falls within a free tier. Get your account and login to the AWS console at (https://aws.amazon.com/)
We’ll need two lambda functions: HotWater_Update for receiving new data from the device, and HotWater_Alexa for answering Alexa requests. The code for both of these functions is in the code repository. Each folder in the awslambda code directory contains a lambda_function.py file with the source code, and a zip file. It is best to upload the Zip file, as dependencies are packaged up with the source. After uploading, you’ll be able to view and edit the source using an online editor.
- Sign into the AWS Console
- Navigate to AWS Lambda
Do the following twice, once for
- Click Create Function Button
- Select Author from Scratch
- Name the function: HotWater_Update
- Python 3.6
- Create Custom Role
- IAM Role: Create a new IAM Role
- Role name: HotWater_Update
- Now Choose HotWater_Update under Existing Role
- Your new function will now display.
- Under Code Entry Type, select ‘Upload a .ZIP file’, and select the appropriate zip file for the function from the code repository.
- Hit the Save button (upper right)
- Now, you can see and update the code.
HotWater_Alexahas several configuration variables that you may need to update. Edit them and then hit the Save button again.
In the HotWater_Alexa function, copy and paste the ARN of the function. You’ll find it at the top right of the page, and it looks like
arn:aws:lambda:us-east-1:000000000:function:HotWater_Alexa. You’ll need this when you configure the Alexa Skill later on.
- Now your functions are uploaded but we need to add some permissions first. Navigate to the Identity and Access Management (IAM) section of the AWS console.
- First, click Policies in the left menu.
- Click Create Policy, then on the JSON tab.
- Copy and paste the contents of the
- Click Review Policy, and name it “
- Click Create Policy.
Next, we need to give our new roles access to this policy.
- Click on Roles in the left menu, and you should see your
HotWater_Alexaroles in the list.
- Click on each, then on Attach Policy.
- Change the filter to Customer Managed, and you should see your
- Click the checkbox, and click Attach Policy.
We will use the AWS API Gateway to allow our microcontroller to send data updates over HTTPS.
- Navigate to API Gateway in the AWS Console.
- Click Create API, then Import from Swagger
- Copy and paste the contents of
HotWaterAPI-swagger.yamlinto the textbox, and click Import.
- Click POST under /HotWater_Update.
- Integration Type: Lambda Function
- Check the Use Lambda Proxy Integration checkbox
- Select us-east-1 or whatever region you created your Lambda functions in.
- For Lambda Function, type HotWater_Update. This should auto-complete.
- Click Save, then Ok, when asked to confirm adding a permission to the lambda function.
- From the Actions menu, select Deploy API.
- Deployment stage: [New Stage]
- Stage Name: prod
- Click Deploy
- Copy the Invoke URL, and save it for later. You’ll need to update the Arduino code with this URL.
We’ll create a special API key for use in calling this API. This prevents anybody else from calling this API method.
- Click API Keys on the left menu.
- Click Actions, then Create API Key.
- Name: HotWater
- Click Save
- Select API > HotWaterAPI
- Select Stage > prod
- Click Add.
- Click Show after API key, and copy and save the API Key for later. You’ll need to update the Arduino Code with this value.
Included with the project files are a 3D printed case for the electronics, and some clips to hold the temperature sensors to the input and output pipes. These are not necessary for the correct functioning of the project, but do make it look nice. During testing, you can just secure the temperature sensors to the pipes with blue painters tape, and even tape the electronics to the wall. If you use a board different than the WeMos D1 Mini, you’ll need to modify the case to make it fit.
You can use any filament, though translucent filaments will best show the status light. I used a blue translucent filament, because that's the only translucent option I had at the public library where I printed the case and clips.
You’ll also need to install additional board configurations. You can get these by Opening File > Preferences, and adding this to the Additional Boards Manager URLs:
Open the hotwater-arduino.ino, and update the following information
- Update apigateway destination
- Update apigateway accesstoken
- Update wifi ssid and password
- Update wattage and efficiency
Plug in the WeMos D1 Mini, select the proper port, and upload.
You’ll need to create a new Alexa Skill in the Amazon Developer Console (https://developer.amazon.com/alexa/console/ask) Note that this is different from the AWS Console.
- Hit Create Skill
- Name it HotWater, and hit next.
- Select Custom model, and hit create skill button.
- Under Interaction Model on the left, choose JSON Editor. Drag the
AlexaSkillInteractionModel.jsonfile onto the box, or copy and replace the displayed JSON with the contents of the file.
- Hit Save Model, then Build Model. The building will take a few minutes.
- Select Endpoint from the left menu, and choose AWS Lambda ARN.
- Copy and Paste the ARN from the
HotWater_AlexaLambda Function that you built earlier.
At this point, you should be ready to go! Use your Echo device or mobile app, and try out the commands that are available.
The skill is called Hot Water, so begin by saying “Alexa, open Hot Water”
Then you can try any of the included phrases:
- How long can I shower.
- How much water is left.
- How much did we use today/yesterday/this week/last week/etc.
- How much did we use in the last 3 days/17 minutes/3 hours/etc.
For just a quick question, you can just give it a single phrase, like this:
“Alexa, ask Hot Water How long I can shower” This will give you an answer immediately, and then exit the skill.
This project uses AWS CloudWatch to store data for its use. For extra fun, you can log into the AWS console and see the graphs it uses in the CloudWatch console.