Webhook icon
Schedule icon
WorkingDirectory icon
Commands icon
Script icon
Process icon
If icon
Loop icon
Request icon
Create icon
SlackIncomingWebhook icon
Log icon

Audit every charging session before a bad one costs you a charger

Audit EV charging sessions for failed, zero duration, connector mismatch and overstay anomalies, then raise CMMS work orders, a GitHub issue and Slack alerts.

Categories
BusinessInfrastructure

Charging sessions go wrong quietly. A charge point forgets to close a session, a meter records nothing, a driver leaves a vehicle plugged in for eight hours after the battery is full, and the only complaint arrives weeks later as a disputed invoice or a connector that failed an inspection. This flow runs on every session end notice the charger backend posts to the keyed webhook, or on the hourly sweep once the disabled schedule is switched on, reads the sessions.json register, applies the four audit rules and counts every record that trips one. Anomalies are turned into one CMMS work order each, rolled up into a single GitHub issue and summarized in Slack, while a clean register is logged as healthy.

How it works

  1. on_session_end (io.kestra.plugin.core.trigger.Webhook) accepts a POST from the charge point management system whenever a driver unplugs, so the register is re audited the moment a session closes.
  2. hourly_reconciliation (io.kestra.plugin.core.trigger.Schedule, cron 0 * * * *) sits disabled as the net to switch on for a continuous sweep of the register.
  3. workspace (io.kestra.plugin.core.flow.WorkingDirectory) gives the fixture and the auditor one directory, so both touch the same sessions.json.
  4. write_sessions (io.kestra.plugin.scripts.shell.Commands) drops sessions.json from a heredoc of eight sessions covering a clean 30 kWh charge, a failed mid session with no stop time, a zero duration plug, a connector mismatch and an eight hour overstay.
  5. audit_sessions (io.kestra.plugin.scripts.python.Script on the Process runner) applies the four rules, counts every hit and prints one ::{"outputs": ...}:: line carrying verdict, anomaly_count, sessions and anomalies.
  6. anomaly_gate (io.kestra.plugin.core.flow.If) escalates only when anomaly_count is above zero.
  7. In the escalation branch raise_work_orders (io.kestra.plugin.core.flow.Loop) runs post_work_order (io.kestra.plugin.core.http.Request) once per anomaly against the CMMS API, open_audit_issue (io.kestra.plugin.github.issues.Create) files one labeled issue holding the full table, and alert_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the summary; the other branch records the quiet outcome with log_clean (io.kestra.plugin.core.log.Log).
  8. The errors handler pings Slack when the run itself breaks, because a silent failure looks exactly like a clean register.

What you get

  • verdict (STRING): ANOMALIES_FOUND when at least one session trips a rule, CLEAN when every session is closed, charged, matched and inside the stay limit, NO_DATA when the register holds no usable row.
  • anomaly_count (INT): rule breach records across the register, zero on a clean run.
  • sessions (INT): rows audited, so a zero count means the register itself is the problem.
  • anomalies (ARRAY): one object per breach with session_id, connector_id, rule and detail, ordered as the auditor walked the register so the first entry is the earliest session.
  • One CMMS work order per anomaly plus one GitHub rollup issue and a Slack summary when escalation fires, and a log line only when it does not.

Who it's for

  • Fleet and depot operators who own a bank of chargers and need every session closed with real energy before the utility invoice and the maintenance ticket disagree.
  • Energy managers who suspect vehicles are overstaying their bay and want the limit expressed as an input rather than a report filter.
  • Reliability engineers who want connector mismatches and half finished sessions caught by a workflow in version control instead of a dashboard nobody opens.

Why orchestrate this with Kestra

Session auditing usually lives as a scheduled export that somebody reads after the invoice lands, by which point the charger has already been dispatched twice. Kestra puts the session webhook, the disabled hourly sweep, the register write, the rule audit, the gate, the per anomaly loop and the three notifications into one versioned file: the gate is declarative, every execution leaves its verdict, anomaly count and anomaly list as typed outputs, and an email rule would only forward a message with no record. The loop turns one audit into one actionable CMMS work order per breach, and the errors handler keeps a broken run visible.

Prerequisites

  • A Kestra instance with the HTTP, GitHub and Slack plugins available to the worker.
  • A charge point management system that can POST a session end notice to the webhook URL.
  • A CMMS endpoint that accepts a JSON work order and a token able to authenticate against it.
  • A GitHub personal access token able to open issues in the fleet repository.
  • A Slack incoming webhook for the escalation summary and for failure alerts.
  • A sessions.json register shaped as session_id, site_id, connector_id, connector_type, vehicle_connector, started_at, stopped_at, energy_kwh, supplied through the heredoc fixture or replaced with your own export task.

Secrets

  • SESSION_END_WEBHOOK_KEY: key segment guarding the webhook URL, so only your charger backend can post session end notices.
  • CMMS_WORKORDER_URL: CMMS endpoint that receives one work order per anomaly record.
  • CMMS_API_TOKEN: bearer token sent with every work order request to authenticate against the CMMS.
  • GITHUB_TOKEN: token used by open_audit_issue to file the rollup issue.
  • SLACK_WEBHOOK_URL: Slack incoming webhook used for the escalation summary and for failure alerts.

Quick start

  1. Add the five secrets to your namespace and import the flow.
  2. Leave overstay_hours at 6 or set it to the bay policy you actually enforce, and point github_repository at the repo that should receive the audit issues.
  3. Execute the flow once against the fixture and read verdict, anomaly_count, sessions and anomalies in the outputs.
  4. Point the charger backend at /api/v1/{tenant}/executions/webhook/{namespace}/ev-charger-session-audit/SESSION_END_WEBHOOK_KEY, then confirm the CMMS work orders, the rollup issue and the Slack summary.
  5. Switch on hourly_reconciliation when you want the register swept every hour instead of only on a session end notice.

How to extend

  • Replace the heredoc with an export from your charge point management system, or a jdbc query against the charging database, and keep the same python rules.
  • Split the overstay limit per site by reading a second input inside audit_sessions when depots enforce different bay policies.
  • Add a delayed_close rule that compares a running session against the current hour when sessions are expected to be short.
  • Write every verdict to a table with io.kestra.plugin.jdbc.postgresql.Queries to build an anomaly trend across many executions.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.