Skip to main content

Poll EV charging APIs and write station status events to TimescaleDB/PostgreSQL.

Project description

EV Charging Status

Python app that polls Shell Recharge/Greenlots and SEMA/Blink charger APIs and writes station status events to TimescaleDB/PostgreSQL.

Setup

uv sync
cp .env.example .env

Put real DB credentials and API tokens in .env. .env is ignored by git.

Run commands through uv run, for example:

uv run ev-status --help

Database

Initialize schema and seed default sites/statuses/stations:

uv run ev-status init-db

Only rows with sites.enabled = true are polled.

Run

First run, or after recreating/changing the database schema, initialize the database once:

uv run ev-status init-db

Routine one-time poll:

uv run ev-status poll

You can combine initialization and polling for a safe first run:

uv run ev-status poll --init-db

--init-db is not required for every poll. It only ensures the database, tables, indexes, default sites, default statuses, default stations, and TimescaleDB setup exist before polling.

Continuous 5-minute loop (or POLL_INTERVAL_SECONDS):

uv run ev-status run-loop

For a safe first continuous run:

uv run ev-status run-loop --init-db

Sync historical rows from the public Google Sheet CSV into station_status_events:

uv run ev-status sync-sheet

Set SYNC_SHEET_ID in .env. By default the command reads Sheet1 using:

https://docs.google.com/spreadsheets/d/<SYNC_SHEET_ID>/gviz/tq?tqx=out:csv&sheet=Sheet1

The sheet must include columns like current_time, station_name, and status. The sync command inserts only rows that do not already exist with the same (time, station_id, status). Rows for station IDs not present in the stations table are ignored.

You can override the tab or full CSV URL:

uv run ev-status sync-sheet --sheet-name Sheet1
uv run ev-status sync-sheet --url 'https://docs.google.com/spreadsheets/d/{SHEETID}/gviz/tq?tqx=out:csv&sheet=Sheet1'

Optimize station_status_events storage:

uv run ev-status optimize-db

This rounds existing event timestamps to second precision, drops the redundant (time DESC, station_id) index, and compresses TimescaleDB chunks older than 7 days. Timestamp precision is also second-level for new polls.

You can change the compression cutoff:

uv run ev-status optimize-db --compress-older-than '1 day'

Show total database size:

uv run ev-status db-size
# include table/relation sizes
uv run ev-status db-size --tables

Tables

  • sites: site enable/disable control
  • status_lookup: status IDs; new normalized statuses are inserted automatically
  • stations: station metadata inserted once on first sight
  • station_status_events: Timescale hypertable with exactly (time, station_id, status)
  • site_latest_snapshot: latest raw JSONB API response per site

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

ev_charging_status-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

ev_charging_status-0.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file ev_charging_status-0.1.0.tar.gz.

File metadata

  • Download URL: ev_charging_status-0.1.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ev_charging_status-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f5823d7ebe74ded38ef4a3e7f54e2a7a7d158b0c4642a6a1900ed5e8dc64e0fa
MD5 03afbcb4ad97c2aa85272708269cc0b6
BLAKE2b-256 265654c656dfa1f25fc08072e3ed660f2fedc2164536f1ba1077e17badb64dd7

See more details on using hashes here.

File details

Details for the file ev_charging_status-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ev_charging_status-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ev_charging_status-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aae5ec384c5a9690ade452047393b6033501e5aa51926e5300097a3716e8311d
MD5 9a87c21259caa2b812fa8d9d18569732
BLAKE2b-256 c8841f579fbb4980e57d3a605e6ed47015e4c14ba23ea69d7b0989b4e36ce324

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