Rainforest Automation EMU-2 (Energy Component)

I recently installed HA and pricked up the EMU 2. I followed the instructions on the Git feed to install and configure but i’m getting an error in my log. Not sure if my serial port is bad or if I do not have the "rainforest’ integration setup proper. Here is the log error:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/hassio/init.py:599
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 5:08:23 PM (12 occurrences)
Last logged: 5:39:27 PM

  • [140685815848672] The system cannot restart because the configuration is not valid: Platform error sensor.rainforest - Integration ‘rainforest’ not found.
  • [140685722211952] The system cannot restart because the configuration is not valid: Platform error sensor.rainforest - Integration ‘rainforest’ not found.

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 185, in handle_call_service await hass.services.async_call( File “/usr/src/homeassistant/homeassistant/core.py”, line 1495, in async_call task.result() File “/usr/src/homeassistant/homeassistant/core.py”, line 1530, in _execute_service await handler.job.target(service_call) File “/usr/src/homeassistant/homeassistant/components/hassio/init.py”, line 599, in async_handle_core_service raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Platform error sensor.rainforest - Integration ‘rainforest’ not found.

I think your problem stems from an update in HA. (Ive had the same issue.) I brought it up with the Devs on discord, but i seem to have fallen on deaf ears.

Anyway, the post 2 below yours is what I used to fix mine and allow me to add my meter to my consumption (it has something to do with output being kW vs Kwh)

# Enery Monitoring
sensor:
  - platform: rainforest
    port: '/dev/ttyACM0'
  - platform: template
    sensors: 
      grid_energy_delivered:
        unique_id: delivered_kWh
        friendly_name: "Delivered kWh"
        unit_of_measurement: 'kWh'
        value_template: "{{ state_attr('sensor.rainforest_energy_monitoring_unit','Delivered kWh') }}"
        device_class: energy

and

utility_meter:
  grid_energy_consumed: 
    source: sensor.grid_energy_delivered 
    name: 'Grid Energy Consumed'

reboot and see if you can add it now :slight_smile:

I just got my EMU-2 from PSE, and for a brief moment I was able to get Home Assistant to load the rainforest integration, but now whenever I try to restart HA I get:

In my sensor.yaml I have:

  - platform: rainforest
    port: '/dev/ttyACM1'

This is because my Zwave stick is on ttyACM0. I was able to verify that the rainforest stick is present via ha hw info

I have:

Reinstalled the Rainforest component via HACS a few times
Removed the batteries (per this forum)
Replaced the USB cable (but it still shows as connected when I check the hardware)
Restarted Home Assistant multiple times.

I am kind of at a loss.

Ok, well, I say that, and then I carefully checked the thread again, and changed my repo for Rainforest to:

And now it works so credit to

@damienheiser for the fix!

Good to see another Puget Sounder here. Just got mine yesterday and integrated with Home Assistant today using the same method. Waiting for the Energy dashboard to update now.

Mine just started updating, though I don’t yet have the $$ per KWh. Not sure if that is a feature that still needs to be added. Though, I don’t see $$/KWh on the device itself either, so I guess they are working on that as we are the beta testers.

Was curious about the power price on mine as well. In Home Assistant i just figured out the rate and put that in as a static value. PSE upgraded my gas meter rececntly to Zigbee as well. Wonder if theyll expand EMU2 to support gas consumption as well.

They might, though I already have Gas Consumption (Propane) via the Tank Utility integration. I am too far out in the boonies for natural gas.

Has anyone gotten this work properly via the HASS container?

I have installed the alternative HACS integration along with the recommended configuration.yaml components. I left off sections about power put back into the grid as I’m only consuming, not returning power from the grid. I have the device connected to a Mac Mini running Ubuntu and Home Assistant 2021.12.8 in a Docker container.

I also am passing the tty device into my container by id to prevent it moving around on me:

--device=/dev/serial/by-id/usb-Rainforest_Automation__Inc._RFA-Z105-2_HW2.7.3_EMU-2-if00:/dev/ttyACM0

However, I do not seem to be receiving data properly. When I cat the device inside the container, I only very sporadically am able to see any xml content and the sensors do not seem to be updating inside of Home Assistant.

sensor:
  - platform: rainforest
    port: '/dev/ttyACM0'
  - platform: template
    sensors: 
      grid_energy_delivered:
        unique_id: delivered_kWh
        friendly_name: "Delivered kWh"
        unit_of_measurement: 'kWh'
        value_template: "{{ state_attr('sensor.rainforest_energy_monitoring_unit','Delivered kWh') }}"
        device_class: energy

utility_meter:
  grid_energy_consumed: 
    source: sensor.grid_energy_delivered 
    name: 'Grid Energy Consumed'

No errors are being output in either the docker or home assistant logs. I am also one of the newer people to have received the EMU-2 through PSE.

I’m happy to try anything and everything to get this working! :slight_smile:

Update: FWIW, I added debug logging to the rainforest custom_component and while I can see it starting the loop, it never receives any data to then process

I’m running Home Assistant container on Debian on a Proxmox machine. Just mentioning because there are a few subtle differences in our setups.

I passthrough the EMU2 from Proxmox to the VM. It shows up as /dev/ttyACM1.

Then my docker-compose.yaml lets Home Assistant run privileged and on host networking which simplifies a ton of things.

    network_mode: host
    privileged: true

Then it still shows up as /dev/ttyACM1 in my container.
Here is my sensors setup:

  - platform: rainforest
    port: '/dev/ttyACM1'
    name: emu2

Then I get a sensor.emu2 with current usage as the state and a bunch of attributes. The current usage populates right away, but the attributes take some time.

Asking the stupid question, are you sure it reads your meter from where your server is? Just asking because mine is in a closet in the center of the house. I’m actually surprised it reads my meter OK in that location, but it does work.

Thanks @gregg098 - the privileged mode was my problem! I’m not sure why passing the device in wasn’t working, but I’m now getting data in completely as expected.

Unfortunately I did have to switch to specifying the device by name (eg: /dev/ttyACM1) as the serial/by-id directory is not exposed to docker containers.

I’m not using docker compose, but rather just directly starting it from docker which also auto-restarts in case the host restarts. If others are interested, here’s my command string.

docker run -d --name="hass" --net=host --restart always -v /mnt/macmini/config-hass:/config -e "TZ=America/Los_Angeles" --privileged homeassistant/home-assistant

Thanks and I’m happy to join the rest of you with a working EMU-2!

@gregg098 @Mr_Flibble Have you figured out pricing data? I know I can set a static price in the Energy section of Home Assistant, however that doesn’t take into account the tiered pricing model. I currently just statically set it at 0.1 but I’d like to see something more accurate. The EMU-2 display does show pricing per kwh, but it doesn’t seem to be exposed in the XML.

No. Those values all read “null” in Home Assistant. Honestly I dont think it read anything on the EMU2 last I looked. Its buried in a closet right now where my Home Automation stuff is. I just did fixed price. Last power bill / total kWh from bill.

I reached out to Rainforest asking if this can be exposed. We will see if there is a response.

Been doing some troubleshooting here and noticed that the device seems to bounce around between ttyACM0 and ttyACM1. This could explain some of the ‘cable’ issues people have been commenting on. I have three cables and it hasn’t truly seemed to matter, so long as they are not charge only cables.
Not sure how to ensure the device will come up consistently when it can come up as one or the other. I am guessing that the device does a connect, disconnect, and reconnect while starting and because there is enough capacitance to hold through momentary disconnect, it get seen as another new device to be registered.
Just thoughts. I am still very new to raspberry and HA.

I’d presume the problem there is that the Pi can’t consistently supply enough power for the device, so it intermittently looses power. Perhaps use batteries in it to act as a UPS? Several of us have it plugged into something more powerful (I’m using a Mac Mini running Ubuntu) that is capable of supplying more power to the USB ports than a typical Pi can.

Consider that the USB power adapter supplied by Rainforest outputs 1A of power and the Pi is typically limited to 1.2A max for ALL USB ports (depending on how the Pi is being powered). That very quickly decreases available power to the EMU-2.

how did you get it to add to the dashboard? i see no matching statistics for consumption?

for anyone with issues getting this to run in a container or if the device just doesnt read, try the following after trying all else above:

inside the container run: stty -F /dev/ttyACM1 115200

once done you can run: cat /dev/ttyACM1

you should see data now.

replace ttyACM1 with whatever your particular device id is.

I am running Home Assistant Blue (Odroid). I just got my EMU-2 in the mail today, and I got everything hooked up to the point where I had an entity showing real time kWh in history, but after about 30 minutes the data stopped. I was playing with the configuration to try and get the device to show up in the energy dashboard, but I kept getting the “No Matching Statistics” error. Now my entity no longer shows data. I got my configuration from one of the comments on this thread, but it didn’t seem to work.

Here is my configuration:

sensor:
  - platform: rainforest
    port: "/dev/ttyACM0"
    name: "EMU-2"
  - platform: template
    sensors:
      grid_energy_delivered:
        unique_id: delivered_kWh
        friendly_name: "Delivered kWh"
        unit_of_measurement: "kWh"
        value_template: "{{ state_attr('sensor.rainforest_energy_monitoring_unit','Delivered kWh') }}"
        device_class: energy
      grid_energy_received:
        unique_id: received_kWh
        friendly_name: "Received kWh"
        unit_of_measurement: "kWh"
        value_template: "{{ state_attr('sensor.rainforest_energy_monitoring_unit','Received kWh') }}"
        device_class: energy
utility_meter:
  grid_energy_consumed:
    source: sensor.grid_energy_delivered
    name: "Grid Energy Consumed"
  grid_energy_returned:
    source: sensor.grid_energy_received
    name: "Grid Energy Returned"

I see 2 sets of messages that seem to be a problem:

ERROR (Thread-3) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/config/custom_components/rainforest/sensor.py", line 140, in serial_read
    if msgStr != [] and msgStr[0] == '<':
IndexError: string index out of range

AND

ERROR (MainThread) [homeassistant.components.utility_meter.sensor] Could not restore state <unknown>. Resetting utility_meter.Grid Energy Consumed
ERROR (MainThread) [homeassistant.components.utility_meter.sensor] Could not restore state <unknown>. Resetting utility_meter.Grid Energy Returned

I can also see the output XML when I type cat /dev/ttyACM0. Any help or suggestions to try and get things back up and running?

I solved the uncaught thread exception by changing line 140 or sensor.py to be len(msgStr) > 0 instead of msgStr != [].

I also connected the EMU-2 to a powered USB hub, and now the device consistently get an update every few seconds.

However, the Units on the entity are in kW, and it appears my template for sensor.grid_energy_delivered and utility_meter.get_energy_consumed must have some problem because they can’t be added to the Energy dashboard.