Skip to content

keeth/levity

Repository files navigation

Levity

Levity is a barebones, no-GUI, SQLite-backed, single-threaded, async OCPP server. Complementary tools like Prometheus, Grafana, Fluentd, and Litestream make it something like a complete package.

Why this exists

I needed a program to manage a fleet of 20 EV chargers (Grizzl-e Smart) at my cohousing development, to track energy use and give observability into the charger network.

My first prototype was overengineered (Django, Postgres, Docker, RabbitMQ, nginx, etc) and over time I realized that I would be better served by something smaller and simpler, with a strong focus on reliability and low resource usage.

I run Levity onsite on a Raspberry Pi with attached SSD storage. It sends metrics and audit logs up to a cloud instance (Hetzner / Coolify).

  • Grafana: alerts and monitoring (not just the service itself but the status of each charger, total energy use, active charging sessions, network disconnections, etc)

  • Fluentd: complete bidirectional network logging of OCPP traffic for audit/debug purposes

  • Litestream: replicate the SQLite database to S3 for durability and data exploration

Example Grafana dashboard:

Example Grafana dashboard showing various charging system metrics

Status of the project

I fix bugs as I find them in my own installation. Though I'm scratching my own itch here, I've tried to build things in an extensible way, and welcome contributions.

OCPP support

Core OCPP 1.6 JSON protocol is supported - BootNotification, Heartbeat, Status, Transactions, MeterValues

Quick Start

# Install
uv sync

# Run server
levity --port 9000 --metrics-port 9090

# Connect charge points to: ws://localhost:9000/ws/{charge_point_id}

CLI Options

--host              WebSocket host (default: 0.0.0.0)
--port              WebSocket port (default: 9000)
--db                SQLite database path (default: levity.db)
--metrics-port      Prometheus metrics port (enables metrics)
--enable-auto-start When a vehicle is plugged in, start charging immediately
--fluentd-endpoint  Fluentd endpoint (host:port) for audit logging
--log-level         DEBUG, INFO, WARNING, ERROR (default: INFO)

Development

make test      # Run all tests
make lint      # Check code quality
make format    # Format code
make run       # Start server

Pre-commit hooks run automatically on commit. Install with: uv run pre-commit install

Plugins

Built-in plugins: PrometheusMetrics, OrphanedTransaction, AutoRemoteStart, FluentdAudit.

See PLUGINS.md for creating custom plugins.

Project Structure

src/levity/
├── handlers/      # OCPP message handlers
├── plugins/       # Plugin framework + built-in plugins
├── repositories/  # Database access layer
├── models/        # Domain models
├── database/      # Connection management
├── server.py      # WebSocket server
└── main.py        # Entry point

License

MIT

About

A simple OCPP system built with SQLite and Python ⚡️

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published