an4mon
reads from a Aranet4 CO2 monitor and optionally:
- Logs the data to an InfluxDB database.
- Sends a notification via Ntfy when the CO2 level rises above a certain threshold or stays above the threshold for a certain amount of time.
Unfortunately, as this is a Python application, some manual setup is required. You'll need a working Python installation with virtualenv
on your system. On macOS, I use Homebrew to manage Python and install virtualenv
.
To install this tool: clone the repository, then install the application's dependencies. The setup-deps.sh
script creates a virtualenv and installs the requirements for you:
git clone https://github.com/cdzombak/an4mon.git
./an4mon/setup-deps.sh
[!NOTE] > Why not Docker?
I like to distribute Python applications in Docker where possible, but from my Internet searches it seems like using Bluetooth from inside a Docker container running on a macOS host is difficult or impossible.
Working within the an4mon
directory, run the program with the --scan
flag to discover the address of your Aranet4 device:
./venv/bin/python ./main.py --scan
With the device's address in hand, you'll need to create a configuration JSON file. See config.example.json in this repository for an example. The configuration file is a single, valid JSON object that supports the following keys:
aranet_device_address
: The address of your Aranet4 device as discovered via--scan
. Required.healthcheck_ping_url
: If provided, this URL will receive a GET request after the program has successfully read from the Aranet4 device and completed notifications and/or logging to Influx. (Useful for monitoring via an Uptime Kuma push monitor.)
Notification-related keys:
notify
: Whether to send notifications when CO2 reaches 'red' or 'yellow' levels.ntfy_server
: The Ntfy server to use.ntfy_token
: The Ntfy auth token to use. This is a string beginning withtk_
.ntfy_topic
: The Ntfy topic to send to.notify_yellow_every
: Send a notification every N minutes when CO2 is in the 'yellow' range.notify_red_every
: Send a notification every N minutes when CO2 is in the 'red' range.notify_room_name
: The name of the room where the sensor is located, e.g. "Office".ntfy_priority_yellow
: Ntfy priority for 'yellow' CO2 level notifications.ntfy_priority_red
: Ntfy priority for 'red' CO2 level notifications.state_file
: Path where the program will keep track of the last time it sent a notification. Required ifnotify
istrue
.
Influx-related keys:
influx
: Whether to log data to InfluxDB.influx_bucket
: The InfluxDB bucket to log data to. Required ifinflux
istrue
.influx_host
: Your InfluxDB host, e.g.http://m-influx-on.lan
. Required ifinflux
istrue
.influx_port
: The InfluxDB port oninflux_host
.influx_username
: InfluxDB username.influx_password
: InfluxDB password.influx_measurement_name
: InfluxDB measurement name. Required ifinflux
istrue
.influx_nametag
: Name of the room/device. If provided this is stored in thearanet_name
tag on measurements written to InfluxDB.
./venv/bin/python ./main.py --config /path/to/config.json --print
The optional --print
argument will print the data from the Aranet4 sensor to standard output, in addition to handling logging to Influx and notifications.
Running the program every 2 minutes seems to result in sufficiently up-to-date data.
On macOS, do this by installing a launch agent. See com.dzombak.an4mon.plist
in this repository for an example. You'll need to modify the paths in that .plist
file to match your username, an4mon
installation, and config file path. Then, copy the .plist
file to ~/Library/LaunchAgents/
and load it with:
launchctl load ~/Library/LaunchAgents/com.dzombak.an4mon.plist
On Linux, running the program every few minutes via cron is an exercise left to the reader.
MIT; see LICENSE in this repository.
Chris Dzombak;