I’ve been using Home Assistant (HA) in my own home for years as a kitchen dashboard display. I started using HA when configuration via .yaml
files was the only way to configure it, hence most of my config is still done this way. However, HA has advanced a lot over the years, and it’s now possible to configure everything via the UI and auto-detection of devices plays a big role in this.
To get data from OpenEnergyMonitor hardware into HA there are currently two options:
-
Emoncms: Use the Emoncms HA integration to get feeds from Emoncms into HA
-
MQTT: Get the data locally from the MQTT server running on the emonPi / emonBase
I imagine most people currently use option 1, but option 2 has a number of advantages it also provides the most real-time data via lightweight MQTT and gives the option to use OpenEnergyMonitor hardware with HA without having to configure Emoncms.
2. MQTT
All emonPi and emonBase units run an MQTT server on port 1882, data is published to MQTT topics with the following format:
basetopic/node/keyname
e.g
emon/emonth6/temperature
The manual way to configure to subscribe to an MQTT topic in HA was to configure it manually in configuration.yaml
e.g
mqtt:
sensor:
- name: "emonth6-temperature"
state_topic: "emon/emonth6/temperature"
device_class: "Temperature"
unit_of_measurement: "°C"
However, wouldn’t it be great if all the OpenEnergyMonitor sensor data would just appear automagically in HA!
This will be possible in the future once we implement HA MQTT auto-detection. The purpose of the remainder of this post is to explain how this works, the user would not normally need to be aware of this.
Autodetection works by using HA MQTT Discovery, we tell HA in advance what each MQTT topic contains by posting a JSON string to the HA MQTT Discovery topic, for a sensor by default this is:
homeassistant/sensor/<vendor-name>/<device-name>/config
For our emonth6 temperature example we would post to the topic
homeassistant/sensor/openenergymonitor/emonth6_temperature/config
The following json string;
{
"stat_t": "emon/emonth6/temperature",
"device": {
"identifiers": "emonth6",
"name": "emonth6",
"manufacturer": "OpenEnergyMonitor"
},
"uniq_id": "emonth6_temperature",
"name": "emonth6 Temperature",
"unit_of_meas": "°C",
"device_class": "Temperature"
}
and then do the same for the humidity reading also coming from emonth6
homeassistant/sensor/openenergymonitor/emonth6_humidity/config
{
"stat_t": "emon/emonth6/humidity",
"device": {
"identifiers": "emonth6",
"name": "emonth6",
"manufacturer": "OpenEnergyMonitor"
},
"uniq_id": "emonth6_humidity",
"name": "emonth6 Humidity",
"unit_of_meas": "%",
"device_class": "Humidity"
}
and finally the same for the battery voltage from emonth6
homeassistant/sensor/openenergymonitor/emonth6_battery/config
{
"stat_t": "emon/emonth6/battery",
"device": {
"identifiers": "emonth6",
"name": "emonth6",
"manufacturer": "OpenEnergyMonitor"
},
"uniq_id": "emonth6_battery",
"name": "emonth6 Battery",
"unit_of_meas": "V",
"device_class": "Voltage"
}
Note: the config should be published with persistence flag and persistence should be enabled in the MQTT broker for reliable device config.
Now if look under Settings > Devices & Services > MQTT in HA we see the following device
Clicking on the devices shows the sensors associated with this emonth6 devices:
These sensors are now being logged to HA can now be easily added to any HA dashboard or used in automations