Update
Smart Water Meter now uses an API created using FRAPI to update a MySQL database. The Photon code also includes HTTP Digest Authentication which is needed to access the REST API.
This project was conceived when I received a large water bill, and wanted to find out how much water was used by an appliance and when it was used. I already have a water meter installed by the water company, but it only tells me how much has been used since it was installed.
I searched online for a smart water meter but couldn't find any, so I decided to build my own using a Particle Photon and a standard analogue water meter with pulse output. The water meter has a dial and and 8 digits. The dial revolves once every tenth of a litre. The digits are split into 2 parts, red digits measuring water volume in litres, and black digits measuring water in metres cubed. The pulse output clicks closed every 10 litres and stays closed for about 1 litre. The pulse output is taken as an 80cm grey sheathed cable containing a black wire and a red wire. For testing, a single pole double throw slide switch is wired-in to simulate the relay closing and opening.
To measure volume used, I designed a very simple circuit to determine when the relay is closed, indicate this with an an LED, add 10 to the volume and then publish it to ThingSpeak. The LED changes back when the relay is open again.
This worked OK but the photon seemed to hang when it couldn't find the web site, whether because the Internet connection is slow or the WiFi is dropped. This caused the Photon to reboot, and because the data isn't persistent across reboots, the amount of water measured was lost.
Initially I used the loop in the Photon code to run all the processing and calculations, but when the Photon kept hanging I split the processes up and added threads to run each part independently. This helped in diagnosing that the problem with the rebooting photon was that it was losing the WiFi connection. This was probably a combination of proximity to mains wiring and the location of the Photon in the garage, with the WiFi signal having to pass through several walls. I had already attached the external antenna from the Photon Kit, but I didn't realise that it had to be activated. Once I put "WiFi.SelectAntenna(EXTERNAL)" into the setup function, the Photon stayed up and could communicate with the web.
The on-board mini blue LED is used to indicate that the water meter code is working. Although not necessary, it provides a feel-good factor. The multicoloured LED indicates the state of the Photon; relay open, relay closed and communicating with the Internet. The pins/colours chosen were random and could have been chosen to better indicate status.
1. Relay open (Red and Green = Yellow)
2. Relay closed (Red and Blue = Magenta)
3. Relay open and communicating with the Internet (Green)
4. Relay closed and communicating with the Internet (Blue)
The code has a couple of interesting points which add to its reliability
1. Use of threads to keep the main loop free
2. Use of the external antenna to keep the WiFi connected
I need to do some re-writes because the code is somewhat hacked together but the principle is there for anyone to follow.
The code reports the volume of water used, but with a small change it could report the cost of the water consumed. This is how the data is displayed in ThingSpeak
It's very obvious when water is being used, and when showers are being taken, and the washing machine and dish washer are being used. I can also see when the water softener is running its regeneration cycle.
Has it made me more aware of how much water I use? Yes, and how much each appliance uses.
Was my water bill correct? Yes, unfortunately. But at least now I know what is causing high volumes of water to be used.
Update:
Using the FRAPI API version, I can see exactly when activity occurred and post-process the data to get the information I want. This also has the advantage that I don't have to rely on a third-party and have all my data under my control. I currently have the service installed on a local Linux box but it could be in the Cloud or anywhere that is accessible to the Photon.
Comments