Docker image to receive wireless sensor data and publish them via MQTT.
This project is not maintained anymore. It is no longer required since merbanan/rtl_433 added support for MQTT and Klimalogg sensors. Users of tfrec-mqtt are encouraged to migrate to rtl_433.
This configuraton covers the basics for a migration:
---
services:
rtl_433:
image: hertzg/rtl_433
container_name: rtl_433
restart: unless-stopped
init: true
devices:
- "/dev/bus/usb:/dev/bus/usb"
command: [
"-R", "150",
"-f", "868.325M",
"-s", "1.536M",
"-M", "level",
"-F", "mqtt://broker,events=rtl_433[/id]"
]
Additional options might be required to align the SDR setup,
e.g. gain (-g
) or demodulator options like -Y minlevel=-25
.
Furthermore, rtl_433 allows to reduce the CPU load by lowering the sample rate (-s
)
or adding -Y squelch
. See the rtl_433 documentation for a complete reference.
MQTT messages have different structure but contain the same (and additional) information:
tfrec-mqtt
tfrec/1a2b/json { "sensor_id":"1a2b", "temperature":9.1, "humidity":78, "seq":0, "lowbat":0, "rssi":82, "flags":0, "timestamp":1588303401 }
rtl_433
rtl_433/6699 {"time":"2020-05-01 03:23:21","model":"Klimalogg-Pro","id":6699,"battery_ok":1,"temperature_C":9.1,"humidity":78,"sequence_nr":0,"mic":"CRC","mod":"ASK","freq":868.28416,"rssi":-9.76374,"snr":27.60925,"noise":-37.373}
Start a container to publish sensor data via MQTT.
- Create a run configuration
compose.yml
, e.g.--- services: tfrec-mqtt: image: ckware/tfrec-mqtt container_name: tfrec-mqtt restart: unless-stopped init: true devices: - "/dev/bus/usb:/dev/bus/usb" environment: MQTT_OPTIONS: "-h broker" command: [ "tfrec", "-q", "-e", "mqtt-publish" ]
- Start a container:
$ docker compose up -d
$ docker run --device /dev/bus/usb -e "MQTT_OPTIONS=-h broker" --init -d ckware/tfrec-mqtt tfrec -q -e mqtt-publish
$ mosquitto_sub -v -h broker -t tfrec/#
tfrec/1a2b/json { "sensor_id":"1a2b", "temperature":9.1, "humidity":78, "seq":0, "lowbat":0, "rssi":82, "flags":0, "timestamp":1588303401 }
tfrec/c3d4/json { "sensor_id":"c3d4", "temperature":15.6, "humidity":69, "seq":0, "lowbat":0, "rssi":79, "flags":0, "timestamp":1588303402 }
- RTL2832-based USB-Adapter
- One or more thermo/hygro sensors made by or compatible to TFA Dostmann, Technoline or LaCrosse (see sensors.txt for a list)
- Required: Docker
- Recommended: Docker Compose
The Docker Compose documentation contains a comprehensive guide explaining several install options. On recent debian-based systems, Docker Compose may be installed by calling
$ sudo apt-get install docker-compose-plugin
The configuration is based on environment variables.
Variable | Description | Allowed values | Default | Example |
---|---|---|---|---|
MQTT_OPTIONS |
MQTT options | All options supported by mosquitto_pub |
none | -v -h broker |
MQTT_TOPIC |
MQTT topic for publishing sensor data | Topic names | tfrec |
devices/sensors |
MQTT_TOPIC_APPEND_ID |
Append sensor ID to topic? | true / false |
true |
true |
MQTT_TOPIC_APPEND_FORMAT |
Append format (one of: json , raw ) to topic? |
true / false |
true |
true |
FORMAT_JSON |
Publish sensor data in JSON format? | true / false |
true |
true |
FORMAT_JSON_LOWBAT_AS_BOOLEAN |
Convert native lowbat value (0 or 1 ) to JSON boolean type? |
true / false |
false |
false |
FORMAT_RAW |
Publish sensor data in raw format? | true / false |
false |
false |
FORMAT_RAW_SEPARATOR |
Field separator for raw format | String | Whitespace (\u0020 ) |
, |
CLIENT_MOSQUITTO |
Use Mosquitto as MQTT client? | true / false |
true |
false |
LOG_FILE |
If set, topic and message are appended to a log file | File path | not set | /var/log/tfrec-mqtt.log |
LOG_FORMAT |
Format to write topic and message to log file | printf -compatible syntax for 2 arguments |
%s %s\n |
{"topic":"%s","message":%s}\n |
This section contains example configurations to use the sensor values within FHEM.
define mosquitto MQTT2_CLIENT localhost:1883
define mqtt_air_kitchen MQTT2_DEVICE
attr mqtt_air_kitchen readingList tfrec/1a2b/json:.* { json2nameValue($EVENT) }
attr mqtt_air_kitchen stateFormat T: temperature H: humidity
define mosquitto MQTT localhost:1883
define mqtt_air_kitchen MQTT_DEVICE
attr mqtt_air_kitchen subscribeReading_json tfrec/1a2b/json
attr mqtt_air_kitchen stateFormat T: temperature H: humidity
define expandjson_mqtt_air expandJSON mqtt_air_.+.json:.\{.*\}
- This project is an integration of
- History and details (in German): Temperatur/Feuchte-Sender mit tfrec und MQTT