Monitor CO2 levels with Prometheus and/or HomeKit
Project description
CO2 monitoring with Prometheus
This reads from the CO2 Meter and makes it available as a Prometheus service. The core logic comes from this hackaday article.
Setup
Note this assumes you are running on a Raspberry Pi running Raspberry Pi OS (Bullseye)
- Install Python 3
- Install the monitor with
python3 -m pip install co2mini[homekit]
(remove[homekit]
if you don't use HomeKit) - Set up CO2 udev rules by copying
90-co2mini.rules
to/etc/udev/rules.d/90-co2mini.rules
- Set up the service by copying
co2mini.service
to/etc/systemd/system/co2mini.service
- (Optional) Put a configuration file (see Configuration section below) in
/etc/co2mini.env
- Run
systemctl enable co2mini.service
Configuration
The /etc/co2mini.env
file contains the environment variables used to configure co2mini beyond the defaults.
This is mostly necessary when enabling MQTT.
Example:
MQTT_ENABLED=true
MQTT_BROKER=localhost
MQTT/Home Assistant
The MQTT feature is meant to work with Home Assistant, although nothing bad will happen if you just want to use the MQTT messages directly.
When co2mini starts up, it will send out the discovery message that Home Assistant expects, as well as responding to homeassistant's status when coming online. Be sure those are enabled in the Home Assistant MQTT integration (usually is enabled by default) if you have any issues.
To configure co2mini, the following environment variables are available:
Variable | Default | Description |
---|---|---|
NAME |
co2mini |
This is used for the default display name of the device in Home Assistant |
MQTT_ENABLED |
False |
Used to enable/disable sending information over MQTT |
MQTT_BROKER |
localhost |
MQTT Broker hostname |
MQTT_PORT |
1883 |
MQTT broker port number (1883 is the standard MQTT broker port) |
MQTT_USERNAME |
Username for authenticating to MQTT broker (leave blank if no authentication is needed) | |
MQTT_PASSWORD |
Password for authenticating to MQTT broker (leave blank if no authentication is needed) | |
MQTT_DISCOVERY_PREFIX |
homeassistant |
Prefix for sending MQTT discovery and state messages. |
MQTT_RETAIN_DISCOVERY |
False |
Flag to enable setting retain=True on the discovery messages. You probably don't need this. |
MQTT_OBJECT_ID |
co2mini_{HOSTNAME} |
Override for setting the object_id in Home Assistant. Default builds using the hostname of the device. |
Homekit
If you have the homekit
dependencies installed, on the first startup you will need to check the logs to get the setup code to integrate with Homekit.
You can find the code using journalctl -u co2mini.service
or possibly by checking the status with systemctl status co2mini.service
.
Note also that it's sometimes possible that co2mini will have some errors logged and won't be reporting in Homekit anymore.
If this happens, it seems like the easiest thing to do is to remove the device from your homekit, remove the accessory.state
file in your home (rm accessory.state
) and restart co2mini
(sudo systemctl restart co2mini.service
) to get a new code to pair.
Special notes for Dietpi users
- Be sure to install
Python3 pip
as well (ID130
) - Make sure the dietpi user is in
plugdev
group (sudo usermod -aG plugdev dietpi
)
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
Built Distribution
File details
Details for the file co2mini-0.4.0.tar.gz
.
File metadata
- Download URL: co2mini-0.4.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca63ee2baa05ed509f854bf6de322f7cb872af35b40a66d26d15a19bc940493d |
|
MD5 | c2051dd91c3ffc30b77cc7363dcd801a |
|
BLAKE2b-256 | a0531a1171d7c12aa9d57da9e36ab815d4aee960fd67d6a13a78b67c8be80a49 |
File details
Details for the file co2mini-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: co2mini-0.4.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b5d48f3aa80041573c6d603a0b0e075e58fbb054ba90c2f73fee388ed4edbbb |
|
MD5 | 2bed9a876622c7a224cf75d9e2e1b50f |
|
BLAKE2b-256 | 92b04490688f5079ec908f2d7f03335448a1fd43c444891a3628ea628cdaef76 |