{
  "version": 10,
  "name": "Electricity \u00b7 Oslo",
  "source": "endpoint",
  "tile": {
    "id": "8017E21C-CF53-5EEC-8A6B-A1256C2F31D6",
    "kind": "metric",
    "label": "NO1",
    "value": {
      "kind": "data",
      "value": "/price"
    },
    "maximum": {
      "kind": "literal",
      "value": "100"
    },
    "itemTitle": "/title",
    "itemSubtitle": "/subtitle",
    "icon": {
      "kind": "literal",
      "value": "bolt"
    },
    "iconPointSize": 14,
    "format": "number",
    "decimals": 2,
    "unit": "kr"
  },
  "popout": [
    {
      "id": "E56DC96F-FFE7-541E-98E8-62AD347C9CDF",
      "kind": "metric",
      "label": "Spot price \u00b7 NO1",
      "value": {
        "kind": "data",
        "value": "/price"
      },
      "maximum": {
        "kind": "literal",
        "value": "100"
      },
      "itemTitle": "/title",
      "itemSubtitle": "/subtitle",
      "textSize": "large",
      "format": "number",
      "decimals": 2,
      "unit": "kr/kWh"
    },
    {
      "id": "9954307D-486C-54D4-919F-4B1AAE3F9A5A",
      "kind": "graph",
      "label": "Today \u00b7 Oslo",
      "value": {
        "kind": "data",
        "value": "/history"
      },
      "maximum": {
        "kind": "literal",
        "value": "100"
      },
      "itemTitle": "/title",
      "itemSubtitle": "/subtitle",
      "graphDateField": "/date",
      "graphValueField": "/value",
      "format": "number",
      "decimals": 2,
      "unit": "kr/kWh",
      "color": "orange"
    },
    {
      "id": "98627462-D86F-56EE-99D8-6108BCD6B845",
      "kind": "text",
      "label": "",
      "value": {
        "kind": "literal",
        "value": "hvakosterstrommen.no \u00b7 Before VAT, grid fees, markups and support."
      },
      "maximum": {
        "kind": "literal",
        "value": "100"
      },
      "itemTitle": "/title",
      "itemSubtitle": "/subtitle",
      "textSize": "small"
    }
  ],
  "inputs": [],
  "transform": "function transform(response, { now }) {\n  if (!Array.isArray(response) || !response.length) throw new Error(\"No electricity prices for this day.\");\n  const rows = response.map(row => {\n    const start = Date.parse(row.time_start), end = Date.parse(row.time_end);\n    if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start || !Number.isFinite(row.NOK_per_kWh)) {\n      throw new Error(\"The price feed contains an invalid interval.\");\n    }\n    return { start, end, price: row.NOK_per_kWh };\n  }).sort((a, b) => a.start - b.start);\n  const current = Date.parse(now);\n  const active = rows.find(row => row.start <= current && current < row.end);\n  if (!active) throw new Error(\"Refresh to load prices covering the current time.\");\n  const time = value => new Intl.DateTimeFormat(\"en-GB\", {\n    timeZone: \"Europe/Oslo\", hour: \"2-digit\", minute: \"2-digit\", hourCycle: \"h23\"\n  }).format(new Date(value));\n  const lowest = rows.reduce((a, b) => b.price < a.price ? b : a);\n  const highest = rows.reduce((a, b) => b.price > a.price ? b : a);\n  const cheapestRemaining = rows.filter(row => row.end > current).reduce((a, b) => b.price < a.price ? b : a);\n  return {\n    price: active.price,\n    history: rows.map(row => ({ date: new Date(row.start).toISOString(), value: row.price })),\n    highlights: [\n      { title: \"Lowest today \u00b7 \" + time(lowest.start), subtitle: lowest.price.toFixed(2) + \" kr/kWh\", icon: \"arrow.down\" },\n      { title: \"Highest today \u00b7 \" + time(highest.start), subtitle: highest.price.toFixed(2) + \" kr/kWh\", icon: \"arrow.up\" },\n      { title: \"Cheapest remaining \u00b7 \" + time(cheapestRemaining.start), subtitle: cheapestRemaining.price.toFixed(2) + \" kr/kWh\", icon: \"clock\" }\n    ]\n  };\n}\n"
}
