Skip to main content

Parsing P1 serial to Influx DB

Project description

p1-influx-db

Python package for reading DSMR/P1 telegrams from a smart meter and publishing the parsed values either to InfluxDB 2 over HTTP or to an MQTT broker.

What it does

The package exposes a module named p1_influx_db that reads telegrams from the configured serial device, parses the selected DSMR values, and forwards them using one of these output modes:

  • influx2: write parsed measurements to InfluxDB 2 using the HTTP API
  • mqtt: publish parsed measurements as JSON messages over MQTT

The active behavior is driven by a TOML configuration file. A packaged example is available at p1_influx_db/example_config.toml.

Requirements

  • Python 3.11 or newer
  • Access to the P1 serial device exposed by your meter
  • One configured output target: InfluxDB 2 or MQTT

Installation

Install from PyPI:

pip install p1-influx-db

Install from source with Poetry:

python -m poetry install

The project metadata currently defines mqtt, influxdb, and publishmethods extras, but the base install already includes both transport dependencies.

Running

Run the module with an explicit config file:

python -m p1_influx_db --config /path/to/config.toml

If --config is omitted, the module falls back to ./p1_influx_db/example_config.toml.

Configuration

The config file must contain:

  • a [p1] section with the serial device settings
  • either an [influx2] section or an [mqtt] section

If both [mqtt] and [influx2] are present, the current entrypoint selects MQTT first.

All keys entries under [p1.*] should match DSMR field names exposed by dsmr-parser, such as ELECTRICITY_USED_TARIFF_1 or INSTANTANEOUS_VOLTAGE_L1.

Example configuration:

# TOML-based config
[influx2]
url = "http://localhost:8086"
org = "my-org"
token = "my-token"

[mqtt]
broker = "localhost"
port = 433
client_id = "client_id"
ca_certs = "/etc/certificate/abc"
certfile = "/etc/certificate/abc"
key = "etc/certificate/key"
max_times = 60

[p1]
device = "/dev/serial0"

[p1.electricity]
keys = ["ELECTRICITY_USED_TARIFF_1",
        "ELECTRICITY_USED_TARIFF_2",
        "ELECTRICITY_DELIVERED_TARIFF_1",
        "ELECTRICITY_DELIVERED_TARIFF_2"]

[p1.electricity_current]
keys = ["CURRENT_ELECTRICITY_USAGE",
        "CURRENT_ELECTRICITY_DELIVERY",
        "INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE",
        "INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE",
        "INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE",
        "INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE",
        "INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE",
        "INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE"]

[p1.voltage]
keys = ["INSTANTANEOUS_VOLTAGE_L1",
        "INSTANTANEOUS_VOLTAGE_L2",
        "INSTANTANEOUS_VOLTAGE_L3"]

[p1.current]
keys = ["INSTANTANEOUS_CURRENT_L1",
        "INSTANTANEOUS_CURRENT_L2",
        "INSTANTANEOUS_CURRENT_L3"]

[p1.gas]
keys = ["HOURLY_GAS_METER_READING"]

Output behavior

  • InfluxDB mode reads the influx2 configuration from the same TOML file and writes parsed measurements asynchronously.
  • MQTT mode publishes JSON payloads under topics prefixed with p1/.
  • MQTT TLS certificates are required by the current client implementation because TLS is always enabled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p1_influx_db-3.0.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p1_influx_db-3.0.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file p1_influx_db-3.0.0.tar.gz.

File metadata

  • Download URL: p1_influx_db-3.0.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for p1_influx_db-3.0.0.tar.gz
Algorithm Hash digest
SHA256 7ef94470ae7dc285f6c5c5672a509a3e0f810ee44b1daa47caa4cf1a04fdf31a
MD5 7d215b052355fb5f77d130eb02dc874b
BLAKE2b-256 1e472afecf60db85b9d15c167f8f18c8026f7c1f1ecc5f721f68b6baa66620b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for p1_influx_db-3.0.0.tar.gz:

Publisher: python-package.yml on yfredrix/p1-influx-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file p1_influx_db-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: p1_influx_db-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for p1_influx_db-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 638056292ce59a0606117762a5c2c54c3231cde3f17c2e9da35ce7301dd468ab
MD5 c57c82c1bf070b924ad6601062b64ba8
BLAKE2b-256 a7140516735197ff8ca10f1f4eebd8b4f2449716185188154ae01ffd85f411df

See more details on using hashes here.

Provenance

The following attestation bundles were made for p1_influx_db-3.0.0-py3-none-any.whl:

Publisher: python-package.yml on yfredrix/p1-influx-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page