Skip to content

Instantly share code, notes, and snippets.

@ConnorGriffin
Last active December 4, 2019 20:44
Show Gist options
  • Save ConnorGriffin/421ca0291f88a9aec01b170d911db44b to your computer and use it in GitHub Desktop.
Save ConnorGriffin/421ca0291f88a9aec01b170d911db44b to your computer and use it in GitHub Desktop.
Get SRP (Salt River Project) power usage per hour using PowerShell
# Set the SRP base url and get yesterday's date in a format that the report expects
$baseUrl = 'https://myaccount.srpnet.com'
$yesterday = (Get-Date).AddDays(-1).ToString('M/d/yyyy')
# Start a session, pull the form data
$r = Invoke-WebRequest $baseUrl -SessionVariable session
# Identify the username/password form
$loginForm = $r.Forms.Where{$_.Fields.Keys -contains 'UserName'}
# Enter your username and password into the form, then submit the form
$loginForm.Fields.UserName = 'username'
$loginForm.Fields.Password = 'password'
$r = Invoke-WebRequest "$baseUrl/$($loginForm.Action)" -WebSession $session -body $loginForm.Fields -Method Post
# get the power account list, use the first account in the list. You can hardcode a value if you want
$account = $r.ParsedHtml.getElementById('ElectricAccountSelect').children[0].innerHTML.replace('-',$null)
# Set the URL query options
$exportParams = @(
"billAccount=$account",
"viewDataType=DisplayCostkWh",
'reportOption=Hourly',
"startDate=$yesterday",
"endDate=$yesterday",
"displayCost=false"
) -join '&'
# Generate the CSV report
$r = Invoke-WebRequest -Uri "$baseUrl/MyAccount/Usage/ExportToExcel?$exportParams" -Method Get -WebSession $session
# Get the CSV report as an object
$powerTable = $r.Content | ConvertFrom-Csv
# Example
> $powerTable | Format-Table
Usage Date Hour kWh Cost Rate
---------- ---- --- ---- ----
6/24/2018 12:00 AM 2.9 $0.30 off-peak
6/24/2018 1:00 AM 2.1 $0.23 off-peak
6/24/2018 2:00 AM 2.5 $0.26 off-peak
6/24/2018 3:00 AM 2.4 $0.25 off-peak
6/24/2018 4:00 AM 1.7 $0.19 off-peak
6/24/2018 5:00 AM 2.3 $0.24 off-peak
6/24/2018 6:00 AM 1.6 $0.18 off-peak
6/24/2018 7:00 AM 1.6 $0.18 off-peak
6/24/2018 8:00 AM 1.6 $0.18 off-peak
6/24/2018 9:00 AM 0.5 $0.07 off-peak
6/24/2018 10:00 AM 0.5 $0.08 off-peak
6/24/2018 11:00 AM 0.5 $0.08 off-peak
6/24/2018 12:00 PM 2.8 $0.29 off-peak
6/24/2018 1:00 PM 3.1 $0.32 off-peak
6/24/2018 2:00 PM 1.8 $0.20 off-peak
6/24/2018 3:00 PM 4.7 $0.46 off-peak
6/24/2018 4:00 PM 2.5 $0.26 off-peak
6/24/2018 5:00 PM 0.5 $0.08 off-peak
6/24/2018 6:00 PM 1.1 $0.13 off-peak
6/24/2018 7:00 PM 4.4 $0.44 off-peak
6/24/2018 8:00 PM 4.1 $0.41 off-peak
6/24/2018 9:00 PM 4.0 $0.40 off-peak
6/24/2018 10:00 PM 2.6 $0.27 off-peak
6/24/2018 11:00 PM 4.4 $0.44 off-peak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment