I’ve been interested in adding utility measurement features to my Home Assistant installation for over a year. After a number of tries, I finally have most of the functionality I set out to implement. My impetus for adding detailed utility measurement goes back to a quote by entrepreneur (and founder of GoDaddy) Bob Parsons, “Anything that is measured and watched, improves.” Now that I have water and electricity usage displayed on my kitchen wall in real time via HADashboard, I can see the immediate effects of my actions and hopefully lower my bills a little. For instance, I was very surprised that having my patio power washed used almost 1,000 gallons of water in one morning. (I won’t be getting that done again!)
So what does it take to get Home Assistant to display this data? Let’s start with the overall system architecture. Due to the number of different programs that I need to run, I decided to rebuild my Home Assistant setup using Docker on Ubuntu 16 server. Docker does take some getting used to and a slightly different mindset but in the end it makes the setup so much easier to manage. Basically, each program or group of programs runs in its own tiny virtual environment known as a “container” that includes all of the dependencies the program requires. These are not full virtual machines though, since each container relies on pieces of the host operating system as well. Once you have more than two or three containers running, I highly recommend learning to use a “Docker Compose” file to organize your containers. With one command, you can stop, start or view the status of all your running containers. Below is a diagram of my current system:
Previously I had used the Hassbian image of Home Assistant on a Raspberry Pi 3 that also included AppDaemon. The new Docker version runs on a sixth generation Core i5 and regularly runs at less than 10% of processor capacity. I plan to use this extra capacity to add Plex and other useful containers. In a recent post I described how I set up a water meter that provides a pulsed output to a Raspberry Pi GPIO pin. Custom Python code on that Pi converts the pulses to MQTT packets that are sent to the Mosquito broker that is connected to Home Assistant. I’ve replaced the stock Home Assistant SQLite database with InfluxDB, a database that is designed to hold a high volume of unstructured data. That data is regularly queried by some custom Python code in another container. That container also holds a SQLite database with recent utility bill cost data. This information allows the code to calculate daily and monthly costs and then send that data as MQTT packets to the broker. That data then becomes available to Home Assistant and HADashboard for display.
A web server running a single PHP page makes utility bill data entry a bit easier than using the SQLite command line. Basically I just enter the water/electricity usage amount and total cost when each bill arrives. That automatically resets the monthly totals and then subsequent calculations use the rate derived from the previous billing period. It also allows me to verify the bills. (They have been very close to my measurements.)
The electricity meter works in a similar manner. It is a standard Aeotec Z-Wave Gen 5 Home Energy Meter. You can pair it to your Home Assistant installation like any other Z-Wave device, and then power and energy data will be available. To add the utility cost data, I use additional Python code that reads the usage data from the InfluxDB and then calculates the cost based on cost data in the SQLite database.
Obviously I have not provided all the details here needed to replicate this system. That would take many pages of text. My goal in describing this setup is to show what is possible and how different pieces can fit together. With a little creativity, a lot of Googling and some basic coding skills, you can come up with some amazing Home Assistant displays and automations!