Skip to main content

See the current co2 emissions per kWh of electricity in the Netherlands

Project description

Table of Contents

  1. CO2 monitor
    1. cli
    2. tray
    3. screen
  2. Installation
    1. Development
  3. Pins
    1. Screen

CO2 monitor

This projects monitors the current CO₂ emissions per kWh of electricity being generated in the Netherlands. It obtains the data from ned.nl, and gets updated every 15 minutes. It has three modes:

$ co2monitor --help

Usage: co2monitor [OPTIONS] COMMAND [ARGS]...

  Shows the current CO2 emissions per kWh of electricity in the Netherlands.

Options:
  --debug / --no-debug
  --api-key TEXT        Override API_KEY environment variable.
  --api-url TEXT        [default: https://api.ned.nl/v1]
  --user-agent TEXT     Override USER_AGENT environment varaible.
  --polltime INTEGER    [default: 60]
  --version             Show the version and exit.
  -h, --help            Show this message and exit.

Commands:
  cli     Print emissions to the commandline.
  screen  Show emissions on an EPD screen connected via GPIO.
  tray    Add a system tray icon with emissions.

cli

This mode polls the API once per minute and outputs it in the current format:

2024-11-29 19:30: 310.45g CO2/kWh

tray

This creates a really ugly system tray icon showing the CO₂ emissions rounded to the nearest natural number, shown here below the tooltip:

img

screen

This mode shows the current emisions a small EPD screen connected to some GPIO pins of the Raspberry Pi. It assumes that we are running on a Raspberry Pi, and fails otherwise.

See here a photo of how it looks on my 2.9 inch screen:

img

It uses the current locale (specifically, LC_TIME) to determine how the date looks. See Pins for an overview of what pins need to be connected to the screen.

Installation

I show pip commands here. However, pip isn’t ideal for this: use pipx or, as I do, uv (uv tool install co2monitor[tray], for example).

$ pip install co2monitor

Is sufficient for the cli mode. The other modes require rather large libraries and are therefore excluded from the base package. Install the dependencies required for the tray mode (Qt, pillow) with

$ pip install co2monitor[tray]

And, shockingly,

$ pip install co2monitor[screen]

For the screen mode. This installs pillow, RPi.GPIO and spidev.

Development

See the Makefile for some handy dev commands. I use uv to manage my dependencies, but it does not really matter all that much.

pyproject.toml has an Entry Point, which means that it installs a binary called co2monitor in the virtual environment. If you have the virtual environment activated, you can run co2monitor. For uv, you can execute uv run co2monitor to run the project.

Pins

https://pinout.xyz/

Screen

Product

Name Function Color Pin number GPIO
VCC Power Grey 1 -
GND Ground Brown 6 -
DIN SPI MOSI Blue 19 10 (SPI0 MOSI)
CLK SPI Clock Yellow 23 11 (SPI0 SCLK)
CS SPI chip selection Orange 24 8 (SPI0 CE0)
DC Data/Command selection Green 22 25
RST Reset White 11 17
BUSY Busy status output Purple 18 24

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

co2monitor-2.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

co2monitor-2.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file co2monitor-2.0.tar.gz.

File metadata

  • Download URL: co2monitor-2.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for co2monitor-2.0.tar.gz
Algorithm Hash digest
SHA256 c1f04c6cb08cb809b2d25a4f72d0cfb8118aae1a809e642c853f2a4325da841a
MD5 123e962387e02299dc5391501b53fd4a
BLAKE2b-256 d7d6fe6e08fcafd8caabf34ae82a99fb8c00f6cfe79ca8b85fce5e7bc7a9b58d

See more details on using hashes here.

File details

Details for the file co2monitor-2.0-py3-none-any.whl.

File metadata

  • Download URL: co2monitor-2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for co2monitor-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c468897c43bb7f144472647b4a9a7fd63334b90379bf248b1aac33b3f88a110a
MD5 49b57f5ac9f3206ee7cb68c8b3d66a83
BLAKE2b-256 978bbcfc1cb4acaf57b1384a56d7279b10fb5a4e109794c5495ad799cc518428

See more details on using hashes here.

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