Skip to content
varkeyPublic

About

A self-hosted service that automatically downloads Indian electricity bills on a cron schedule, stores PDFs locally (or on Google Drive), and serves a read-only web dashboard. Runs as a single Docker container with no external runtime dependencies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Lumos

Lumos

A self-hosted service that automatically downloads Indian electricity bills on a cron schedule, stores PDFs locally (or on Google Drive), and serves a read-only web dashboard. Runs as a single Docker container with no external runtime dependencies.


What works

Providers

Provider Bill list PDF download Notes
BESCOM ✅ ✅ No login — static API key; 12-month history
KSEB ✅ ✅ Session-based login; full history back to 2015

Storage backends

Backend Status
Local filesystem ✅
Google Drive ✅ (service account)

Features

  • Incremental sync — SQLite tracks downloaded bills; subsequent runs only fetch new ones
  • Full backfill on first run — KSEB returns full history (~10 years); BESCOM configurable up to 12 months
  • GDrive sync job — a separate cron job (default 03:00 daily) uploads all local PDFs (including historical and KSEB supplement PDFs) and versioned SQLite DB snapshots to Google Drive; idempotent and never overwrites existing PDFs
  • DB backup versioning — daily / weekly / monthly SQLite snapshots in GDrive with configurable retention (default: 10 days, 8 weeks, 12 months)
  • PDF detail extraction — meter readings, charges, and consumption data extracted from PDFs and shown in an expandable Details panel; BESCOM readings fetched from the provider API for accuracy
  • Payment status — BESCOM via payment history API (heuristic matching); KSEB directly from bill record (paidAmnt)
  • Door-closed bill handling — KSEB estimated (door-closed) bills are merged with interim or in-place corrections automatically on each run; corrective PDFs downloadable per period
  • Bimonthly bill support — KSEB bills cover 2 months; chart data is expanded to proportional monthly points
  • Consumer aliases — configure a name per consumer; used in UI headings, nav dropdown, and chart legends
  • Display timezone — configurable (timezone: "Asia/Kolkata" default); KSEB timestamps are IST and display correctly
  • Prometheus metrics — lumos_bills_downloaded_total, lumos_download_errors_total, lumos_last_run_timestamp_seconds{source}, lumos_job_duration_seconds{source}, lumos_runs_total{source,status}, lumos_backup_runs_total, lumos_backup_duration_seconds, lumos_backup_last_success_timestamp_seconds, lumos_backup_items_processed_total, lumos_backup_items_failed_total; source is one of startup | cron | retry | on-demand
  • SMTP notifications — optional email on job errors
  • PDF retry — BESCOM PDF generation fails intermittently; configurable retries with delay
  • KSEB connection retry — retries up to 3× on network errors and HTTP 5xx (server instability)
  • On-demand refresh — a ⟳ button next to the "Current as of" timestamp on each consumer page triggers an immediate data fetch for that consumer without waiting for the next cron run; sends a new-bill notification email if new bills are discovered
  • Multi-account — multiple connections (same or different provider) in one config file
  • CI/CD — GitHub Actions builds linux/amd64 + linux/arm64 images, pushes to GHCR on merge and version tags

What does not work yet

  • Live energy consumption — future: ingest real-time data from sensors (Shelly EM, Tasmota, Home Assistant) into the same metrics endpoint

Quick start

cp config.example.yaml config.yaml
# Edit config.yaml — add your consumers, set storage path

mkdir -p data
go run ./cmd --config config.yaml

Or with Docker:

docker run -d \
  -v $(pwd)/config.yaml:/config/config.yaml:ro \
  -v $(pwd)/data:/data \
  -e KSEB_USERNAME=1234567890123 \
  -e KSEB_PASSWORD=yourpassword \
  -p 9090:9090 \
  ghcr.io/varkey/lumos:latest

Docker Compose

cp config.example.yaml config.yaml
# Add KSEB_USERNAME and KSEB_PASSWORD to your environment or a .env file
docker compose up -d

Configuration

See config.example.yaml for all options with inline documentation.

BESCOM setup

Both values are on your electricity bill:

  • consumer_number — the RR Number (e.g. RR1234567)
  • account_number — the Account ID / Consumer Account Number (e.g. 1000000001)
consumers:
  - type: bescom
    name: "Home Bangalore"
    consumer_number: "RR1234567"
    account_number: "1000000001"

KSEB setup

The consumer number is on your bill. Credentials are environment variables only — never in config.yaml:

consumers:
  - type: kseb
    name: "Home Kerala"
    consumer_number: "1234567890123"
export KSEB_USERNAME=1234567890123   # usually same as consumer_number
export KSEB_PASSWORD=yourpassword

Note on login time: KSEB's portal initialises sessions server-side, which can take 30 seconds to 2 minutes depending on server load. Login happens once per job run regardless of how many KSEB consumers are configured (shared session).


Google Drive setup

See docs/gdrive-setup.md for a step-by-step guide to creating a service account, downloading the JSON key, finding the folder ID, and sharing the folder with the service account.


Storage layout

Bills are always written to local_bills_dir so the web UI can serve them. When backend: gdrive, a separate sync job also uploads them to Google Drive.

Local path format: {local_bills_dir}/{provider}/{consumer_number}/{account_number}-{YYYY-MM}.pdf

Example with local_bills_dir: /data/bills:

/data/bills/
  bescom/RR1234567/1000000001-2026-05.pdf
  bescom/RR1234567/1000000001-2026-04.pdf
  kseb/1234567890123/1234567890123-2026-03.pdf     ← main bill
  kseb/1234567890123/1234567890123-2026-01.pdf
  kseb/1234567890123/1234567890123-2026-03-supp-987654.pdf  ← KSEB supplement PDF

When backend: gdrive, the sync job mirrors this structure in Drive and additionally stores DB snapshots:

db/
  lumos-daily-2026-05-18.db    ← daily snapshot (kept for last 10 days)
  lumos-weekly-2026-W20.db     ← weekly snapshot (kept for last 8 weeks)
  lumos-monthly-2026-05.db     ← monthly snapshot (kept for last 12 months)

Versioning

Images are tagged by git tag:

git tag v0.1.0
git push origin v0.1.0
# → ghcr.io/varkey/lumos:0.1.0, :0.1, :latest

Every merge to main also updates ghcr.io/varkey/lumos:latest.


Running tests

# Unit + crypto tests
go test ./...

# PDF extraction integration test (no network — runs against a local PDF)
PDF_FILE=/path/to/bill.pdf PDF_PROVIDER=bescom go test ./internal/pdfextract/ -run TestExtractFromFile -v
PDF_FILE=/path/to/bill.pdf PDF_PROVIDER=kseb   go test ./internal/pdfextract/ -run TestExtractFromFile -v
# Add DUMP_TEXT=1 to print the raw extracted text before parsing

# BESCOM integration (hits real API)
export BESCOM_ACCOUNT_NUMBER=1000000001
export BESCOM_CONSUMER_NUMBER=RR1234567
go test ./internal/provider/bescom/ -run TestIntegration -v

# KSEB integration (hits real portal — allow up to 15 min for slow login)
export KSEB_USERNAME=1234567890123
export KSEB_PASSWORD=yourpassword
export KSEB_CONSUMER_NUMBER=1234567890123
go test ./internal/provider/kseb/ -run TestIntegration -v -timeout 15m

CLI flags

Flag Description
--config <path> Config file path (default config.yaml)
--reextract-pdf Re-run PDF extraction on all downloaded bills, then exit. Clears existing bill_pdf_details rows first. Useful after upgrading to a newer extraction version.

About

A self-hosted service that automatically downloads Indian electricity bills on a cron schedule, stores PDFs locally (or on Google Drive), and serves a read-only web dashboard. Runs as a single Docker container with no external runtime dependencies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages