Work in progress
This feature lives on branch feature/remote-meter-through-mqtt (not yet merged to develop) and is tested via an integration branch on real hardware. Config field names may still change.
MQTT Meter Integration
Why
Meters for external/third-party circuits (e.g. vZEV community participants) are read via MQTT instead of Modbus, since we don't have physical/wired access to them. First concrete use case: Shelly Pro EM-50 (Gen2 RPC) energy meter.
Concept
io.openems.edge.bridge.mqtt(upstream, untouched) provides the raw broker connection (Bridge.Mqttcomponent).io.openems.edge.meter.mqtt.api(custom) definesMqttMeterAdapter: one implementation per device family, translating that family's topic/payload layout into a neutralMeterSample.io.openems.edge.meter.mqtt.shelly(custom) is the first adapter + Meter component, for Shelly Gen2em1:xchannels.
To support a new device family later (e.g. WhatWatt Go), copy MeterMqttShellyImpl as a template and implement a new MqttMeterAdapter — no changes needed to the Bridge or the API bundle. See io.openems.edge.meter.mqtt.api/readme.adoc and io.openems.edge.meter.mqtt.shelly/readme.adoc in the openems repo for full details (config tables, live-broker test procedure).
Broker Setup (Mosquitto)
Broker runs as the mosquitto container in openems-docker (eclipse-mosquitto:2, TLS on 8883, reusing the Let's-Encrypt cert for the domain). Auth is username/password + ACL, one MQTT user per physical device, restricted to that device's own topic namespace:
# mosquitto acl file — one block per device
user shelly01
topic readwrite shelly01/#
Create the user with mosquitto_passwd, add the ACL block, restart the mosquitto container.
Shelly Device Config (Web-UI)
On the Shelly Gen2 device itself (Settings → MQTT):
| Field | Value |
|---|---|
| Enable MQTT | on |
| Server | broker host:port (8883, TLS) |
| Username / Password | the device's own broker user (e.g. shelly01) |
| Topic prefix | defaults to the username — keep it that way, OpenEMS assumes topicPrefix == username |
| Enable RPC over MQTT | on |
Verify independently of OpenEMS with mosquitto_sub -h <host> -p 8883 --tls-version tlsv1.2 -u shelly01 -P <pw> -t 'shelly01/#' -v — expect shelly01/online true and periodic shelly01/events/rpc {...NotifyStatus...}.
OpenEMS Component Config
Bridge.Mqtt— one instance per device (matches the broker credentials above):id,host,port=8883,secureConnect=true,username/password= the device's broker user.-
Meter.Mqtt.Shelly— one instance per measured channel:Field Value mqtt_idID of the Bridge.Mqttinstance from step 1topicPrefixdevice's topic prefix, e.g. shelly01channelShelly em1:xchannel,0or1phasephysical phase this channel represents typeMeterType(GRID,PRODUCTION, ...)invertfixes reversed CT-clamp wiring only — not device sign conventions addToSumdefault false— these Meters represent external/community circuits, not our own grid connection
Adding the Next Sensor
- Create the broker user + ACL block for the new device.
- Configure MQTT on the device (Web-UI).
mosquitto_subcheck that it's publishing.- Add
Bridge.Mqttinstance. - Add
Meter.Mqtt.Shellyinstance (newchannel/phase, same or newBridge.Mqttper device). - Check
MqttCommunicationFailedstaysfalseand values update in the OpenEMS UI.
Troubleshooting
MqttCommunicationFailed=true/ valuesUNDEFINED→ device offline, ortopicPrefixdoesn't match the broker username.- No data at all → check ACL block matches the username exactly, check
Bridge.Mqtt'sCONNECTEDchannel.