Skip to main content

Enviroplus Sensors to MQTT

Python 3.11+ License: MIT uv Ruff

A robust Python service that reads environmental sensor data from a Pimoroni Enviro+ HAT on a Raspberry Pi and publishes structured JSON payloads to an MQTT broker.


Features

  • Sensors supported: BME280 (temperature, humidity, pressure), MICS6814 (reducing, oxidising, NH3 gas resistance), MEMS microphone (noise low/mid/high/amp), and PMS5003 particulate matter sensor (PM1, PM2.5, PM10).
  • Fault-isolated sampling: Transient I2C/serial/sensor errors are handled cleanly per sensor group rather than crashing the service.
  • Self-heating compensation: Configurable temperature offset (--temperature_offset / temperature_offset).
  • Resilient MQTT loop: Long-lived connection with automatic reconnect, error-checked publishing, and Last Will and Testament (LWT) offline messaging.
  • systemd-first architecture: Direct console logging formatted for journald with graceful shutdown on SIGTERM / SIGINT.
  • Environment variable secrets: Secure credential loading via MQTT_HOST, MQTT_USERNAME, and MQTT_PASSWORD.

Hardware & System Prerequisites (Raspberry Pi)

Ensure the required Raspberry Pi hardware interfaces are enabled via raspi-config:

  • I2C: Enabled (Interface Options -> I2C)
  • SPI: Enabled (Interface Options -> SPI)
  • Serial Port: Hardware serial enabled, serial console disabled (Interface Options -> Serial Port)
  • Microphone: If using the MEMS noise sensor, ensure the microphone audio overlay is enabled in /boot/config.txt.

Install system libraries required by the sensor hardware stacks:

sudo apt-get update
sudo apt-get install -y python3-dev gcc i2c-tools cmake libffi-dev libopenblas0

Installation & Setup

enviroplussensorstomqtt can be installed in an isolated environment or executed on the fly without cloning the source repository:

Using pipx:

# Install as an isolated CLI command
pipx install enviroplussensorstomqtt

# Or run directly on the fly
pipx run enviroplussensorstomqtt --help

Using uv:

# Install globally into an isolated tool environment
uv tool install enviroplussensorstomqtt

# Or run directly on the fly via uvx
uvx enviroplussensorstomqtt --help

2. Developer / Git Installation

We recommend using uv for fast, deterministic installs:

# Clone the repository
git clone https://github.com/hellqvio86/enviroplus-sensors-to-mqtt.git
cd enviroplus-sensors-to-mqtt

# Install dependencies into local virtualenv
make install

Running Tests & Linting

make test

Configuration

Configuration is loaded and merged with the following precedence (highest to lowest):

  1. Command-line flags
  2. Environment variables (MQTT_HOST, MQTT_USERNAME, MQTT_PASSWORD)
  3. YAML config file (--config_file <path>, /etc/enviroplussensorstomqtt.yaml, or ./config.yaml)
  4. Built-in defaults

Configuration Reference

Option CLI Flag Environment Variable Default Description
host --host MQTT_HOST (required) MQTT broker hostname or IP
port --port - 1883 MQTT broker port (1-65535)
topics --topics - (required) Comma-separated list of MQTT topics
username --username MQTT_USERNAME None MQTT broker username (optional)
password --password MQTT_PASSWORD None MQTT broker password (optional)
interval --interval - 60.0 Seconds between measurement cycles
measurements --measurements - 3 Number of samples to median per cycle
temperature_offset --temperature_offset - 0.0 °C offset to subtract for board self-heating
enable_ltr559 --disable-ltr559 - true Enable/disable LTR559 light and proximity sensor
client_id --client_id - None Optional MQTT client ID
tls --tls / --no-tls - false Enable TLS encryption for MQTT broker connection
tls_ca_certs --tls_ca_certs - None Path to CA certificates file for TLS verification
tls_certfile --tls_certfile - None Path to client certificate file for mutual TLS
tls_keyfile --tls_keyfile - None Path to client private key file for mutual TLS
tls_insecure --tls_insecure / --no-tls_insecure - false Disable server certificate hostname verification
per_metric_topics --per_metric_topics / --no-per_metric_topics - false Also publish individual values to {topic}/{metric} subtopics
ha_discovery --ha_discovery / --no-ha_discovery - false Enable Home Assistant MQTT Discovery registration
ha_discovery_prefix --ha_discovery_prefix - homeassistant MQTT topic prefix for Home Assistant discovery
device_id --device_id - enviroplus Unique device identifier for Home Assistant discovery
qos - - 1 MQTT QoS level (0, 1, or 2)
retain - - true Retain published MQTT messages
debug -D, --debug - false Enable verbose debug logging
log_file --log_file - None Optional file path for file logging

YAML Configuration Example

Save as /etc/enviroplussensorstomqtt.yaml or config.yaml with permissions chmod 600 config.yaml:

host: "192.168.1.50"
port: 1883
username: "mqtt_user"
password: "secure_password"
topics:
  - "home/sensors/livingroom/enviroplus"
interval: 60.0
measurements: 3
temperature_offset: 2.5
enable_ltr559: true
qos: 1
retain: true
debug: false

Example MQTT Payload

Readings are published as a retained JSON object:

{
  "temperature": 21.45,
  "unit_of_temperature": "C",
  "humidity": 45.20,
  "unit_of_humidity": "%",
  "pressure": 1013.2,
  "unit_of_pressure": "mbar",
  "noise_low": 0.12,
  "noise_mid": 0.08,
  "noise_high": 0.05,
  "noise_amp": 0.02,
  "gas_oxidising": 182500,
  "unit_of_gas_oxidising": "Ohms",
  "gas_reducing": 245000,
  "unit_of_gas_reducing": "Ohms",
  "gas_nh3": 312000,
  "unit_of_gas_nh3": "Ohms",
  "pm1": 2,
  "pm25": 6,
  "pm10": 9,
  "lux": 150.25,
  "unit_of_lux": "Lux",
  "proximity": 38,
  "time_utc": "2026-10-09T08:30:00.000000"
}

Systemd Service Installation

To install as a background service:

make install-service
sudo systemctl enable enviroplussensorstomqtt
sudo systemctl start enviroplussensorstomqtt

Check status and follow logs:

sudo systemctl status enviroplussensorstomqtt
journalctl -u enviroplussensorstomqtt -f

Buy Me a Coffee

Metadata

Release files for enviroplussensorstomqtt 0.2.0

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

Source distribution (sdist)

Source distribution for enviroplussensorstomqtt 0.2.0
File Size Uploaded Provenance Actions
enviroplussensorstomqtt-0.2.0.tar.gz 19.6 kB With provenance Details for enviroplussensorstomqtt-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 39.6 kB

Release files / enviroplussensorstomqtt-0.2.0.tar.gz

Download URL enviroplussensorstomqtt-0.2.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c0375dd721ef7b559a0d5ff85b9e16ecff829412583be7e04531d1ad4c95d9cb
BLAKE2b-256 checksum
How to use checksums
d5f1b853a772b1f742fbcf87d7ed06292c5d9abf94521a0ce6e380e47425bb6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

Release files / enviroplussensorstomqtt-0.2.0-py3-none-any.whl

Download URL enviroplussensorstomqtt-0.2.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
922780b0a7b182959490bfab0a2bc9ceae2f1a969a8959123250a86a95b1ffba
BLAKE2b-256 checksum
How to use checksums
9edc41c33e6ed4d49e50c2956c7d957ab024e527e51493f4a9c7188a7fe35cfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

Security for enviroplussensorstomqtt 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for enviroplussensorstomqtt-0.2.0.tar.gz

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 Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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