Tag Archives: RestMethod

List NordPool electric prices using powershell.

This is a small script using nordpoolgroup api to get todays electric prices for Kr.sand – Norway. This is the same API as their webpage uses. All the urls and parameters can be found using developermode in the browser. This code is only to demonstrate that it can be done. It all started when i first saw the Homeassistant integration on github .https://github.com/custom-components/nordpool

$today=Get-Date -Format "d-M-yyyy"
$url="https://www.nordpoolgroup.com/api/marketdata/page/23" #23 = Hourly ,24 = Daily, 25 = Weekly, 26 = Monthly, 27 = Yearly

$url+="?currency=,NOK,NOK,EUR&endDate=$today"
$response=Invoke-RestMethod -Uri $url
$prices=@()
foreach ($row in $response.data.rows){ 
    $localrow= $row.Columns | Where-Object {($_.name -like "Kr.sand")} 
 if($localrow.IsValid){
  [float]$cost=((($localrow[0].value).tostring()).Replace(' ','')).replace(',','.')
  [datetime]$datetime=$row.StartTime
    Write-Output "$($datetime) - øre/kWh ink mva $([math]::round(($cost/10 * 1.25),2))"
    $prices+=[math]::round(($cost * 1.25),2)
    }
}

$prices|Measure-Object -Average -Maximum -Minimum