Sign inSign up

seanauff/metermon

By seanauff

•Updated over 1 year ago

rtlamr wrapper that outputs formatted json messages over mqtt

Image
0

7.9K

seanauff/metermon repository overview

⁠metermon

Metermon is a dockerized rtlamr⁠ wrapper that connects to an existing rtl_tcp instance and outputs formatted messages over MQTT for consumption by other software (e.g. telegraf for storage in influxdb and display in grafana).

The script can be run using docker (takes care of all dependencies) or standalone. It is design to run on Raspberry Pi or similar.

All credit for rtlamr⁠ goes to bemasher⁠.

⁠Usage

  1. Have a MQTT broker you can connect to. I use Mosquitto⁠.

  2. Ensure you have a rtl_tcp instance that is listening for new connections. I use this docker container⁠.

  3. Run the container or script using instructions below.

  4. Subscribe to the mqtt output topic, metermon/output, with the data consumer of your choice.

  5. Process with your data consumer of choice. An example telegraf config⁠ is provided.

⁠Output format

By default, metermon outputs JSON messages to the metermon/output mqtt topic. The metermon prefix can be changed by setting the MQTT_TOPIC_PREFIX environment variable. Metermon will then send its output messages on [MQTT_TOPIC_PREFIX]/output. Note that adding a trailing / to MQTT_TOPIC_PREFIX will create an empty level.

Value of MQTT_TOPIC_PREFIXmqtt output topic
metermonmetermon/output
sensors/meterssensors/meters/output
sensors/meters/sensors/meters//output
⁠JSON keys

The JSON message has a single level with the following keys:

KeyExampleDescription
ProtocolSCMThe protocol of the received message. See here⁠ for the list.
TypeElectricThe meter type of the received message, converted to generic utility type, e.g. "Electric", "Gas", or "Water". See here⁠ for mapping of numeric ERT type.
ID29163678The unique ID of the meter the received message originated from.
Consumption96948.54The current consumption value in the received message, processed into standard units (Ex.: electric meters report in 1/100 kWh, metermon divides this value by 100 to get kWh).
UnitkWhThe unit that metermon has converted the value to. Metermon decides this by knowing the type of meter and/or the protocol.

If the METERMON_SEND_RAW environment variable is set to true, metermon will send the entire unprocessed JSON message received from rtlamr⁠ to the [MQTT_TOPIC_PREFIX]/raw topic.

If the METERMON_SEND_BY_ID environment variable is set to true, metermon will also send the processed JSON message received from rtlamr⁠ to the [MQTT_TOPIC_PREFIX]/[UNIQUE_ID_OF_METER] topic. This, combined with the use of the RTLAMR_FILTERID environment variable, can make it easier for parsing just a few meters into Home Assistant.

⁠Status Messages

Metermon will report its status on the [MQTT_TOPIC_PREFIX]/status topic via retained messages. Metermon reports Online once it connects to the broker. Upon disconnect, the broker will report Offline.

⁠Performance Tuning

By adjusting the RTLAMR_SYMBOLLENGTH environment variable, sample rates can be modified to reduce CPU load. See documentation of this feature here⁠ and a discussion of the potential performance impacts here⁠.

⁠Running via Docker

Pull the image. If using raspberry pi or similar use arm in place of [tag]. The latest tag will pull the amd64 image:

docker pull seanauff/metermon:[tag]

Start the container with all default environment variables:

docker run -d seanauff/metermon:[tag]

Start the container with modified environment variables:

docker run -d -e MQTT_BROKER_HOST=[host] -e RTL_TCP_SERVER=[server] seanauff/metermon:[tag]
⁠Environment Variables
VariableDefault ValueNotes
MQTT_BROKER_HOST127.0.0.1IP or hostname of MQTT broker
MQTT_BROKER_PORT1883Port of MQTT broker
MQTT_CLIENT_IDmetermonChange this if the default is already in use by another client
MQTT_USERNAMEUsername for connecting to MQTT broker when using auth. TLS not currently supported
MQTT_PASSWORDPassword for connecting to MQTT broker when using auth. TLS not currently supported
MQTT_TOPIC_PREFIXmetermonSet the prefix to use for the MQTT topic that messages are sent to
RTL_TCP_SERVER127.0.0.1:1234server:port that your rtl_tcp instance is listening on
RTLAMR_MSGTYPEallList of message types to listen for. See rtlamr config⁠
RTLAMR_FILTERIDList of meter IDs to look for. See rtlamr config⁠
RTLAMR_SYMBOLLENGTH72Adjust sample rate by setting the length of each symbol. See rtlamr wiki⁠
RTLAMR_UNIQUEtrueSuppress duplicate messages from each meter. See rtlamr config⁠
METERMON_SEND_RAWfalseSet to true to enable sending the raw json from rtlamr to the [MQTT_TOPIC_PREFIX]/raw topic
METERMON_SEND_BY_IDfalseSet to true to enable sending the processed json to the [MQTT_TOPIC_PREFIX]/[UNIQUE_ID_OF_METER] topic.
METERMON_ELECTRIC_DIVISOR100.0Change this to correct the electricity units that your meter reports in to kWh
METERMON_WATER_DIVISOR10.0Change this to correct the water units that your meter reports in to gal
⁠Build the image yourself

Clone the repository and build the image:

git clone https://github.com/seanauff/metermon.git
docker build -t seanauff/metermon metermon

Tag summary

Content type

Image

Digest

sha256:01264bae1…

Size

303.8 MB

Last updated

over 1 year ago

docker pull seanauff/metermon