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

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.1.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.1.0
File Size Uploaded Provenance Actions
enviroplussensorstomqtt-0.1.0.tar.gz 21.8 kB Without provenance Details for enviroplussensorstomqtt-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 41.7 kB

Release files / enviroplussensorstomqtt-0.1.0.tar.gz

Download URL enviroplussensorstomqtt-0.1.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
060a5dcf32731687edd29c3d4a81460bec396280163d27e80b41144c0746cab9
BLAKE2b-256 checksum
How to use checksums
9a84426b06d0000d9010d628ac300afe40a34e33d3a0fbc9a2e278efa86d5f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

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

Download URL enviroplussensorstomqtt-0.1.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0c96510b3b6fd658e3370d99812a8d0e2f729202ace3026749aa991fd11356d
BLAKE2b-256 checksum
How to use checksums
7e2109c85c364b867747d51923d4a956b53d46d013f0938ee0e88bcbafb1f919
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for enviroplussensorstomqtt 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1.0 This release

2 release files No 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