Home Assistant
OpenEnergyMonitor hardware can be integrated with Home Assistant in several ways. Which one suits you best depends on the hardware you have and whether you also want to log data with EmonCMS.
Route |
Hardware |
Data path |
EmonCMS required |
|---|---|---|---|
emonTx6, emonTx5 or emonTx4 + emonWiFi |
emonTx → emonWiFi (ESPHome) → Home Assistant |
No (optional) |
|
emonPi3, emonPi2, emonBase (any emonHub based system) |
emonHub → MQTT broker → Home Assistant |
No |
|
Any system logging to EmonCMS, local or emoncms.org |
EmonCMS feeds → Home Assistant |
Yes |
Choosing a route
New install, Home Assistant only: emonTx6 with an emonWiFi expander, running ESPHome. No Raspberry Pi needed, and data appears in Home Assistant as native sensors.
Existing emonPi / emonBase system: use MQTT to get real-time inputs into Home Assistant, while emonHub and EmonCMS keep running as before.
You already log to EmonCMS and just want the feeds in Home Assistant: use the Emoncms integration. This is the simplest to set up, but it polls once a minute.
ESPHome via emonWiFi
The emonWiFi is a small ESP32-C3 expander that plugs into the emonTx6, emonTx5 or emonTx4 and reads the emonTx serial output. It runs ESPHome, which has native support for the emonTx through the emontx component.
Each channel (voltage, power, energy, temperature, pulse count) is exposed as a Home Assistant sensor, and energy sensors can be used directly in the Home Assistant Energy dashboard.
ESPHome can additionally forward the data to EmonCMS over HTTP(S) or MQTT, so you can use both.
The emonTx can be configured directly from Home Assistant, see Configuring the emonTx from Home Assistant below.
Warning
Never plug the emonWiFi USB-C cable in while it is fitted to an emonTx, this can damage the emonTx. Read the hardware installation notes in the emonWiFi repository before fitting it.
Getting started:
Fit the emonWiFi to the emonTx, following the instructions for your emonTx version in the emonWiFi repository.
Install the ESPHome Device Builder (available as a Home Assistant App).
Create a configuration using the example in the emonWiFi repository, and flash the emonWiFi over USB the first time. Later updates can be done over WiFi.
Adopt the device in Home Assistant: it will be discovered automatically.
A minimal sensor configuration looks like this (the emonWiFi uses GPIO20/GPIO21 for the serial link):
uart:
id: emontx_uart
rx_pin: GPIO20
tx_pin: GPIO21
baud_rate: 115200
rx_buffer_size: 2048
emontx:
sensor:
- platform: emontx
tag_name: "P1"
name: "Power CT1"
- platform: emontx
tag_name: "E1"
name: "Energy CT1"
See the ESPHome emontx documentation for the full list of tags and options.
Configuring the emonTx from Home Assistant
The emonPi/Tx Configuration integration, available through HACS, adds a configuration panel to Home Assistant, so there is no need to send serial commands by hand. It provides:
CT and voltage calibration, radio settings and other device settings, applied in one go
Friendly names for CT, voltage, pulse and temperature channels
Live readings, energy and pulse counter reset, and a serial terminal
A generator for the ESPHome sensor configuration of the active channels
Firmware update checks and wireless firmware updates for the emonTx6/emonPi3
Support for several devices, and for 3-phase emonPi3 setups
Requirements: the emonWiFi must be added to the ESPHome integration in Home Assistant, and its ESPHome configuration must include these components:
emontx_ha_bridge: connects the emonTx to the integration (sends commands, forwards responses and data)emontx_updater: downloads and flashes emonTx firmware updates over WiFi. It needshttp_requestwithbuffer_size_rx: 4096.emontx: must be loaded from the same source as the two components above, as that version keeps the ESP32 responsive during long firmware uploads
Note
emontx_ha_bridge and emontx_updater are not yet part of mainline ESPHome. All three components must be loaded via external_components:
external_components:
- source:
type: git
url: https://github.com/FredM67/esphome
ref: emontx-ha-bridge
components: [emontx, emontx_ha_bridge, emontx_updater]
See the integration documentation for a complete example configuration.
Wireless firmware updates (emonTx6/emonPi3) need the emonTx to use the UART bootloader instead of the default USB (UF2) bootloader. Switching is a one-time step over USB: copy change-bootloader-uart.uf2 from the emon32-fw releases onto the EMONBOOT drive. After that, firmware updates can be installed from Home Assistant, and the USB bootloader can be restored from the integration if needed.
Installation:
In HACS, add
https://github.com/FredM67/ha-emon-configas a custom repository (type Integration) and install emonPi/Tx Configuration.Restart Home Assistant.
Go to
Settings > Devices & services > Add Integrationand search for emonPi/Tx Configuration.
MQTT via emonHub
On emonPi3, emonPi2, emonBase and other systems running emonHub, every input is published to the local MQTT broker (mosquitto). By default each value is published on its own topic using the node variable format:
emon/<node name>/<input name>
For example, an emonPi3 publishes under the EmonPi3 node name. The exact input names can be seen on the EmonCMS Setup > Inputs page, or by subscribing to emon/# with an MQTT client.
To use these values in Home Assistant:
Add the MQTT integration in Home Assistant and point it at the broker on the emonPi/emonBase. The default credentials are listed in the emonSD documentation. Change them if your system is reachable from outside your local network.
emonHub does not publish Home Assistant MQTT discovery messages, so define each sensor manually in
configuration.yaml:
mqtt:
sensor:
- name: "emonPi3 Power CT1"
state_topic: "emon/EmonPi3/P1"
unit_of_measurement: "W"
device_class: power
state_class: measurement
- name: "emonPi3 Energy CT1"
state_topic: "emon/EmonPi3/E1"
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
Adjust the topics to match the input names shown on your system.
Emoncms integration
Home Assistant has a built-in Emoncms integration that reads feeds from any EmonCMS server, either a local emonPi/emonBase or emoncms.org.
In Home Assistant, go to
Settings > Devices & services > Add Integrationand select Emoncms.Enter the server URL, e.g.
http://emonpi.localorhttps://emoncms.org.Enter the read-only API key, found in EmonCMS under
My Account.
Feeds are polled every 60 seconds and appear as sensors. Note that this integration reads feeds, not inputs, so the inputs need to be logged to feeds in EmonCMS first.
To send data the other way, from Home Assistant into EmonCMS, use the Emoncms History integration.