3.13 EPC Government Integration & grouped Navigation Workflow
Instead of asking AI agents to search for legacy links or guess energy performance metrics, we run a deterministic scraper that queries the official UK Government EPC Register by postcode and address, extracts the current active certificate, and updates the database.
1. The UK Government EPC Integration Engine (backfill-uk-epc-ratings.py)
Instead of asking AI agents to search for legacy links or guess energy performance metrics, we run a deterministic scraper that queries the official UK Government EPC Register by postcode and address, extracts the current active certificate, and updates the database.
🔄 The 5-Step Extraction & Storage Logic:
-
UK Postcode Query: The script pulls the address postcode from
tbl_addresses. It makes a direct GET request to the official UK Government search portal:
https://find-energy-certificate.service.gov.uk/find-a-certificate/search-by-postcode?postcode=[postcode] - HTML Table Parsing: The script parses the returned table rows. It isolates the specific property in the results (filtering by building name/number and street) and grabs the matching certificate link.
- Certificate Scraping: It crawls the matching certificate detail page and extracts the current **energy rating (A-G)**, the **expiration date**, and the **report URL**.
-
Bilateral Gas Cross-Check: The script parses the HTML body's "breakdown of property's energy performance" section. It scans the main heating and fuel types for strings like *"gas"*, *"electric"*, or *"communal"* and updates the property's
tbl_amenities.gas_statustoconfirmed_noorconfirmed_yesprogrammatically (enforcing ADR-163). -
Supabase Update: It upserts the retrieved rating directly to the
public.tbl_energy_ratingstable, settingis_current = true.
2. Database Schema: Energy Ratings Table
EPC results are written strictly to tbl_energy_ratings. S3 or GDrive links are not used to store active rating letters; we record the official UK government certificate URL for legal validity.
-- The Canonical Energy Ratings Schema CREATE TABLE public.tbl_energy_ratings ( rating_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), asset_id UUID NOT NULL REFERENCES tbl_assets(asset_id) ON DELETE CASCADE, organisation_id UUID NOT NULL REFERENCES tbl_organisations(organisation_id) ON DELETE CASCADE, scheme TEXT NOT NULL DEFAULT 'epc', -- 'epc' (UK), 'tree' (Thailand), etc. rating_letter CHAR(1) NOT NULL, -- 'A', 'B', 'C', 'D', 'E', 'F', 'G' score_numeric INT, -- e.g. 39 (Rating E) expires_at DATE NOT NULL, certificate_url TEXT, -- https://find-energy-certificate.service.gov.uk/energy-certificate/xxxx-xxxx is_current BOOLEAN DEFAULT true, created_at TIMESTAMPTZ DEFAULT now(), updated_at TIMESTAMPTZ DEFAULT now() );
3. Grouped Side Navigation Architecture (EPC & Utility Meters)
To streamline compliance monitoring, we have grouped **Energy Performance Certificates (EPC)** and **Utility Meters** under a single, high-visibility compliance navigation drawer in the portal sidebar.
📟 New Sidebar Group: "EPC & UTILITY METERS"
A new collapsible sidebar block is introduced in the client portal, grouping:
- Energy Compliance Dashboard: Live A-G ratings, expiration countdowns, and quick PDF generators.
- Meter & Supplier Register: Smart MPAN (electricity) and MPRN (gas) numbers linked directly to
tbl_metersandtbl_meter_readings.
📐 Frontend Component Structure (AppNav.tsx)
The grouped item is configured as a single parent category with children, ensuring clean layout separation:
{
label: "EPC & Utility Meters",
icon: ,
children: [
{ label: "Energy Ratings (EPC)", route: "/dashboard/compliance/epc" },
{ label: "Utility & Smart Meters", route: "/dashboard/compliance/meters" }
]
}
Repository Code
The live codebase implementation for this textbook logic sits within the following repository folder: