get_electricity_tariff
Retrieve Swiss electricity tariffs by municipality with price breakdowns for energy, grid, and taxes from 2011 to 2026.
Instructions
Get Swiss electricity tariff (price in Rappen/kWh) for a municipality from ElCom (Swiss Federal Electricity Commission). Returns total price and price breakdown by component (energy, grid, taxes). Valid years: 2011–2026.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| municipality | Yes | Municipality BFS number (e.g. '261' for Zürich, '351' for Bern, '6621' for Genève). Use search_municipality_energy to find the ID. | |
| category | No | Electricity category. Household: H1–H8 (H4 is default, ~4500 kWh/year). Commercial: C1–C7. Default: H4. | |
| year | No | Tariff year (2011–2026). Default: current year (2026). |
Implementation Reference
- src/modules/energy.ts:202-253 (handler)The implementation of the get_electricity_tariff tool handler, which processes the input arguments, fetches data from the ElCom GraphQL API, and formats the response.
switch (name) { case "get_electricity_tariff": { const municipality = args.municipality as string; const category = (args.category as string | undefined) ?? "H4"; const year = (args.year as string | undefined) ?? CURRENT_YEAR; if (!municipality?.trim()) { throw new Error("municipality is required. Use search_municipality_energy to find the BFS number."); } const raw = await getTariffWithComponents(municipality, category, year); const observations = raw.observations as Array<Record<string, unknown>>; if (!observations.length) { return JSON.stringify({ error: "No tariff data found", municipality, category, year, hint: "Check the municipality BFS number with search_municipality_energy. Not all municipalities have tariff data for every year.", source: "https://www.strompreis.elcom.admin.ch", }, null, 2); } // If multiple operators, return all (some municipalities served by multiple operators) const result = observations.map((obs) => ({ municipality: obs.municipalityLabel, municipalityId: obs.municipality, canton: obs.cantonLabel, operator: obs.operatorLabel, category, categoryDescription: CATEGORY_DESCRIPTIONS[category] ?? category, year, tariff: { total_rp_per_kwh: obs.total, components: { energy_rp_per_kwh: obs.energy, grid_usage_rp_per_kwh: obs.gridusage, municipality_charge_rp_per_kwh: obs.charge, federal_levy_rp_per_kwh: obs.aidfee, fixed_costs_rp_per_kwh: obs.fixcosts, metering_rate_rp_per_kwh: obs.meteringrate, annual_metering_cost_rp_per_kwh: obs.annualmeteringcost, }, }, coverageRatio: obs.coverageRatio, note: "Prices in Rappen per kWh (1 CHF = 100 Rappen)", source: `https://www.strompreis.elcom.admin.ch/municipality/${municipality}`, })); return JSON.stringify(result.length === 1 ? result[0] : result, null, 2); } - src/modules/energy.ts:85-111 (schema)Tool definition and input schema for get_electricity_tariff.
export const energyTools = [ { name: "get_electricity_tariff", description: "Get Swiss electricity tariff (price in Rappen/kWh) for a municipality from ElCom (Swiss Federal Electricity Commission). Returns total price and price breakdown by component (energy, grid, taxes). Valid years: 2011–2026.", inputSchema: { type: "object", required: ["municipality"], properties: { municipality: { type: "string", description: "Municipality BFS number (e.g. '261' for Zürich, '351' for Bern, '6621' for Genève). Use search_municipality_energy to find the ID.", }, category: { type: "string", description: "Electricity category. Household: H1–H8 (H4 is default, ~4500 kWh/year). Commercial: C1–C7. Default: H4.", enum: ["H1","H2","H3","H4","H5","H6","H7","H8","C1","C2","C3","C4","C5","C6","C7"], }, year: { type: "string", description: "Tariff year (2011–2026). Default: current year (2026).", }, }, }, }, - src/modules/energy.ts:159-194 (helper)Helper function getTariffWithComponents that encapsulates the GraphQL query logic for fetching electricity tariffs.
async function getTariffWithComponents(municipality: string, category: string, year: string): Promise<Record<string, unknown>> { // Fetch all price components via aliased query const query = ` query ObservationsWithAllPriceComponents($locale: String!, $filters: ObservationFilters!) { observations(locale: $locale, filters: $filters) { period municipality municipalityLabel operator operatorLabel canton cantonLabel category total: value(priceComponent: total) energy: value(priceComponent: energy) gridusage: value(priceComponent: gridusage) charge: value(priceComponent: charge) aidfee: value(priceComponent: aidfee) fixcosts: value(priceComponent: fixcosts) meteringrate: value(priceComponent: meteringrate) annualmeteringcost: value(priceComponent: annualmeteringcost) } } `; const data = await gql<{ observations: Array<Record<string, unknown>> }>(query, { locale: "de", filters: { period: [year], municipality: [municipality], category: [category], }, }); return { observations: data.observations ?? [] }; }