Skip to main content

mqtt2influxdb

PyPI GitHub Actions GitHub Actions GitHub Release GitHub License

A Python bridge between MQTT messaging and InfluxDB v3 time-series database. Subscribe to MQTT topics, process incoming messages, and write data points to InfluxDB.


Features

  • Subscribe to multiple MQTT topics with wildcard support (+, #)
  • Write data to InfluxDB v3 with tags and fields
  • Support for both JSON and raw string payloads
  • JSONPath extraction from message payloads
  • Mathematical expressions for computed fields
  • Cron-based scheduling for conditional writes
  • HTTP forwarding of processed data
  • Base64 decoding support
  • Daemon mode with automatic reconnection

Requirements

  • Python 3.10+
  • InfluxDB v3 instance (Cloud or self-hosted)
  • MQTT broker (Mosquitto, etc.)

Installation

Using uv (recommended):

uv tool install mqtt2influxdb

Using pip:

pip install mqtt2influxdb

Quick Start

  1. Create a configuration file config.yml:
mqtt:
  host: localhost
  port: 1883

influxdb:
  host: localhost
  port: 8181
  token: your-api-token
  org: your-organization
  bucket: your-bucket

points:
  - measurement: temperature
    topic: sensors/+/temperature
    fields:
      value: $.payload
    tags:
      sensor_id: $.topic[1]
  1. Run the bridge:
mqtt2influxdb -c config.yml

CLI Usage

mqtt2influxdb [OPTIONS]

Options:
  -c, --config FILE  Path to configuration file (YAML)  [required]
  -D, --debug        Enable debug logging
  -o, --output FILE  Log output file path
  -t, --test         Validate configuration without running
  -d, --daemon       Daemon mode: retry on error
  --version          Show version
  --help             Show this message and exit

Configuration Reference

MQTT Section

mqtt:
  host: localhost          # Broker hostname
  port: 1883               # Broker port
  username: user           # Optional authentication
  password: pass
  cafile: /path/to/ca.crt  # Optional TLS
  certfile: /path/to/cert
  keyfile: /path/to/key

InfluxDB Section

influxdb:
  host: localhost          # InfluxDB hostname
  port: 8181               # InfluxDB port
  token: your-api-token    # API token
  org: your-organization   # Organization name
  bucket: your-bucket      # Default bucket
  enable_gzip: false       # Optional gzip compression

Points Section

points:
  - measurement: temperature
    topic: node/+/thermometer/+/temperature
    bucket: custom_bucket   # Optional: override default bucket
    schedule: '0 * * * *'   # Optional: cron filter
    fields:
      value: $.payload
      converted:
        value: $.payload.raw
        type: float
      calculated: = 32 + ($.payload.celsius * 9 / 5)
    tags:
      id: $.topic[1]
      channel: $.topic[3]

Type Conversion

Fields support optional type conversion:

fields:
  temperature:
    value: $.payload.temp
    type: float
Type Description Example
float Floating-point number "123" → 123.0
int Integer number "42" → 42
str String 123 → "123"
bool Boolean 1 → true
booltoint Boolean converted to 0/1 true → 1

Payload Formats

Both JSON and raw string payloads are supported:

Payload Parsed As $.payload Value
25.5 JSON number 25.5 (float)
{"temp": 25} JSON object {"temp": 25}
[1, 2, 3] JSON array [1, 2, 3]
"hello" JSON string "hello"
ON Raw string "ON"
Device ready Raw string "Device ready"

Raw strings are useful for simple MQTT messages like Tasmota power states (ON/OFF) or status messages.

JSONPath Syntax

  • $.payload - Entire payload (JSON or raw string)
  • $.payload.temperature - Nested field (JSON only)
  • $.payload.data[0] - Array index (JSON only)
  • $.topic[n] - Topic segment (0-indexed)
  • $.payload['pm2.5'] - Field with special characters (dot, space, etc.)

Special Characters: Use bracket notation with quotes for field names containing dots, spaces, or other reserved characters:

# For payload: {"air_quality_sensor": {"pm2.5": 5}}
fields:
  pm25: $.payload.air_quality_sensor['pm2.5']

Environment Variables

Use ${VAR} or ${VAR:default} syntax to substitute environment variables in any string value.

mqtt:
  host: ${MQTT2INFLUXDB_MQTT_HOST:localhost}
  port: ${MQTT2INFLUXDB_MQTT_PORT:1883}
  username: ${MQTT2INFLUXDB_MQTT_USERNAME:}
  password: ${MQTT2INFLUXDB_MQTT_PASSWORD:}

influxdb:
  host: ${MQTT2INFLUXDB_INFLUXDB_HOST:localhost}
  port: ${MQTT2INFLUXDB_INFLUXDB_PORT:8181}
  token: ${MQTT2INFLUXDB_INFLUXDB_TOKEN}
  org: ${MQTT2INFLUXDB_INFLUXDB_ORG:default}
  bucket: ${MQTT2INFLUXDB_INFLUXDB_BUCKET:metrics}
  • ${VAR} - Required variable (error if not set)
  • ${VAR:default} - Optional variable with default value
  • ${VAR:} - Optional variable with empty default

Optional HTTP Forwarding

http:
  destination: https://example.com/api
  action: post
  username: user
  password: pass

Optional Base64 Decoding

base64decode:
  source: $.payload.data
  target: data

Development

git clone https://github.com/hardwario/mqtt2influxdb.git
cd mqtt2influxdb
uv sync
uv run mqtt2influxdb -c config-tower.yml --debug

License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤ by HARDWARIO a.s. in the heart of Europe.

Metadata

Release files for mqtt2influxdb 2.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mqtt2influxdb 2.0.6
File Size Uploaded
mqtt2influxdb-2.0.6.tar.gz 68.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mqtt2influxdb 2.0.6
File Interpreter ABI Platform
mqtt2influxdb-2.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 83.6 kB

Release files / mqtt2influxdb-2.0.6.tar.gz

Download URL mqtt2influxdb-2.0.6.tar.gz
Size 68.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4eb0fdca8441cfa1f42312054f095a189ecba82435b82d7da4eb207811efe83b
BLAKE2b-256 checksum
How to use checksums
5560ca16c182fd4e7ea0b67b58542c54f9e563543731986643498bc6b3e47cf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 30, 2025.

Transparency log

Release files / mqtt2influxdb-2.0.6-py3-none-any.whl

Download URL mqtt2influxdb-2.0.6-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b6ef3aa61557a9c0300b6b56edaf5ce92cccfdaa2c2a4d509fc05e00c567d90
BLAKE2b-256 checksum
How to use checksums
4166fc1e2bee35c44e721907b791f4590371abd66c18f954b2c07619487bd082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.6 This release

2 release files

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page