Background

Puget Sound Energy (PSE) recently upgraded my house to include a smart meter which allows them to automatically take meter readings instead of having to physically visit my house. A side effect of this upgrade is that I can now get real-time energy readings with the purchase of a small device that will communicate with the meter itself.

Rainforest EMU-2

Enter the Rainforest EMU-2, which is made available to PSE customers at a discount and comes preprogrammed to connect to your meter and provide real-time energy readings as soon as it's turned on. The device itself comes with a display and two buttons allowing me to navigate through a series of screens and see various information from my meter. The most interesting screen, displayed below, gives me the current power usage and associated cost.

Rainforest EMU-2
Rainforest EMU-2

While being able to see real-time power readings from my meter is great, the historical view from the device left a lot of be desired and I wanted more. Doing some searching I quickly found that Rainforest has a GitHub account that includes an EMU-2 Python library which interfaced with the device through the serial port! Now to get started integrating the device into Home Assistant

Home Assistant Integration

Being my first time writing in a Home Assistant integration, and actually writing in Python, I immediately started trawling through their documentation and samples to see if I could cobble something together. I started by installing the docker image in a WSL2 container on my Windows machine and connecting the device, then immediately ran into a brick wall when I remembered that WSL 2 doesn't support USB devices.

After trying to get usbipd-win working with some success, I eventually gave up as I was hitting into random crashing and locking up when writing to the serial port within the WSL2 container. Instead, I downgraded the container to WSL1 which supports USB devices and kept going. While much slower, I was no longer seeing the crashing problem and I was able to successfully write to the device and read the response.

From here I created a loop to read the power output (kW) from the device and create my first Home Assistant sensor.

Creating the Sensors

My goal here was to integrate into Home Assistant's new Energy Dashboard as a consumption sensor which would enable me to track energy use and costs over time. To do this I needed two new sensors:

  1. A measure of the total energy consumed in kiloWatt hours (kWh)
  2. The current cost per kiloWatt hour ($/kWh)

This data was available by interrogating the device with the get_current_period_usage and get_current_price commands. After creating the two additional sensors, my device now contained the following information:

Rainforest EMU-2 integration

Energy Dashboard

Heading over to the Energy Dashboard configuration, I next added a Grid Consumption and chose the Period Usage sensor along with the Current Price sensor:

Home Assistant Consumption Configuration

The final dashboard was now complete. Looking at the Energy dashboard, I can now view hourly, daily and monthly aggregated data from my meter. It's going to be a while before the monthly view populates out, but already looking at the hourly view, it's nice to be able to point out parts of the day when appliances like the water heater and dryer turn on and what impact this has on my overall power usage.

Home Assistant Energy Dashboard with EMU-2 integration

Try it Out

I have published the source code on GitHub and have opened a pull request with HACS so the integration should be available in the Community Store very soon. Until then you can add this as a custom repository with your Home Assistant..