An MQTT bridge for unleashing your Beenera data

This project provides a bridge to receive data from the Beenera project (https://beenera.de/, formerly Enera) and pass it on to another MQTT broker.

This way, the provided information can easily be used in home automation systems like OpenHAB, Home Assistant, FHEM, iobroker or all others that provide some means to access data via MQTT.

Contents

setting up an MQTT broker

If you do not currently have an MQTT broker available, you can simply install one. The easiest is to install it on the same machine as your home automation system.

Example installation on Debian:

apt update
apt install -y mosquitto mosquitto-clients
⚠️
The default install allows anonymous and unencrypted traffic from all machines! This is, if at all, only suitable in your internal home network.

The broker should automatically start up on reboot. If that’s not the case, a simple

systemctl enable mosquitto

should be enough.

setting up beenera-mqtt-bridge

using Docker

If you are looking for a one-liner, try the following:

docker run \
    --name beenera-mqtt-bridge \
    -e BEENERA_USER=<username> \
    -e BEENERA_PASSWORD=<password> \
    -e LOGLEVEL=INFO \
    -e MQTT_HOST=localhost \
    -e MQTT_TOPIC_BASE=power/ \
    --network host \
    --restart unless-stopped \
    --detach
    oliverrahner/beenera-mqtt-bridge

Or, using docker compose, a docker-compose.yml could look like this:

version: "3.7"
services:
  beenera-mqtt-bridge:
    image: oliverrahner/beenera-mqtt-bridge
    restart: unless-stopped
    environment:
      - BEENERA_USER=<username>
      - BEENERA_PASSWORD=<password>
      - LOGLEVEL=INFO
      - MQTT_HOST=localhost
      - MQTT_TOPIC_BASE=power/
    # this is only required when the MQTT_HOST is localhost
    network_mode: host

retrieve Meter ID

You can easily look it up in the Beenera app, by examining the log output of the bridge or by plain looking at your meter 😉

The bridge will log a line like this:

First time publishing data to topic 'power/1EMH000....'

where 1EMH000…​ is your meter ID.

setting up your home automation solution

OpenHAB

To get the MQTT values into OpenHAB, create the following configuration:

Things

/etc/openhab/things/beenera.things:

// this line is only needed if you don't have an MQTT broker set up currently
// be sure to change the host if needed
Bridge mqtt:broker:broker [ host="localhost", secure=false, clientid="openhab"]

Thing mqtt:topic:power:<Meter ID> "Beenera <Meter ID>" (mqtt:broker:broker) {
// you can freely rename the channels, just be sure to change the items accordingly
    Channels:
        Type number : CurrentPower            [stateTopic="power/<Meter ID>", transformationPattern="JSONPATH:$.items[0].values[?(@.obis=='1-0:16.7.0*255')].value"]
        Type number : PowerConsumptionMeter   [stateTopic="power/<Meter ID>", transformationPattern="JSONPATH:$.items[0].values[?(@.obis=='1-0:1.8.0*255')].value"]
        Type number : PowerDeliveryMeter      [stateTopic="power/<Meter ID>", transformationPattern="JSONPATH:$.items[0].values[?(@.obis=='1-0:2.8.0*255')].value"]
}

Be sure to replace <Meter ID> with your actual meter ID.

Items

You can either create the Items via the UI if this is what you usually do, or you can define them in a file:

/etc/openhab/items/beenera.items

Number pow_beenera_CurrentPower "Current Power [%.1f W]" { channel="mqtt:topic:power:<Meter ID>:CurrentPower" }
Number pow_beenera_DeliveryMeter "Meter Reading Delivery [%.1f Wh]" { channel="mqtt:topic:power:<Meter ID>:PowerDeliveryMeter" }
Number pow_beenera_ConsumptionMeter "Meter Reading Consumption [%.1f Wh]" { channel="mqtt:topic:power:<Meter ID>:PowerConsumptionMeter" }

Again, replace the <Meter ID> everywhere.

Home Assistant

First, configure the MQTT integration: Settings >> Devices & Services >> Integrations >> Add Integration >> MQTT

The configuration should be straightforward.

Add the following snippet to your configuration.yaml:

mqtt:
  sensor:
    - name: "current_power"
      state_topic: "power/<Meter ID>"
      state_class: measurement
      unit_of_measurement: W
      device_class: power
      expire_after: 60
      icon: mdi:home-lightning-bolt
      value_template: >
        {{ (value_json["items"][0]["values"]|selectattr('obis', 'eq', '1-0:16.7.0*255')|list|first)["value"] }}
    - name: "power_consumption_total"
      state_topic: "power/<Meter ID>"
      state_class: total
      unit_of_measurement: Wh
      device_class: energy
      icon: mdi:transmission-tower-import
      value_template: >
        {{ (value_json["items"][0]["values"]|selectattr('obis', 'eq', '1-0:1.8.0*255')|list|first)["value"] }}
    - name: "power_delivery_total"
      state_topic: "power/<Meter ID>"
      state_class: total
      unit_of_measurement: Wh
      device_class: energy
      icon: mdi:transmission-tower-export
      value_template: >
        {{ (value_json["items"][0]["values"]|selectattr('obis', 'eq', '1-0:2.8.0*255')|list|first)["value"] }}

# if you want to use the Home Assistant energy dashboard, you will need this:
utility_meter:
  energy_in:
    source: sensor.power_consumption_total
  energy_out:
    source: sensor.power_delivery_total

Replace <Meter ID> by your meter ID.