How can we improve Hive Active Heating™ and what would you like to see developed next?

Temperature history exporting data

So now in January all the heating data for the last 12 months has gone. Could we either having a rolling 12 months available or have the option to export the data for use elsewhere.

22 votes
Vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
You have left! (?) (thinking…)
Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

3 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • Anonymous commented  ·   ·  Flag as inappropriate

    Hi I tried the powershell option on windows and got several options is this code still up to date?

  • Anonymous commented  ·   ·  Flag as inappropriate

    Technically this is available, there's just no interface for it. It looks mega complicated but I wrote this PowerShell script that will extract temperature history for the daily average. You need to add your information, desired dates and the name of your heating zone on the first 8 lines only. If you're on Windows 10, use Windows Powershell which is already installed. If you're on MacOS, you'll need to install PowerShell Core 6.0. Same with Linux users. Copy everything in to a text file, edit as required then, simply paste in to a PowerShell console if you wish or rename the text file to .ps1 and run it via the console.

    $Username = 'user@domain.com' # Username
    $Password = 'this is my password' # Password

    # Need the name of the zone or your one thermostat to work out what device has the history
    $ZoneName = 'Main'

    $StartDate = Get-Date 01/01/2018 # This is the older date - no more than 128 days in the past
    $EndDate = Get-Date 17/01/2018 # This is the newer date

    # Some required headers to send in the requests.
    [hashtable] $Headers = @{
    'Accept' = '*/*'
    'Content-Type' = 'application/json'
    }

    # The body, which includes your username and password which is TLS encrypted...
    $Settings = [psobject]@{
    username = $Username
    password = $Password
    devices = $true
    products = $true
    }

    # A function to convert date time to unix time in milliseconds so we can provide dates in a format we all can read.
    function DateTimeToUnixTimestamp ([datetime] $dateTime) {
    Return ($dateTime.ToUniversalTime() - [datetime]::new(1970, 1, 1, 0, 0, 0, 0, [DateTimeKind]::Utc)).TotalMilliseconds
    }

    # A function to convert Unix time in milliseconds to a local datetime object - so you can read the dates from the history information
    function ConvertUnixTime([long] $Milliseconds) {
    Return [System.DateTimeOffset]::FromUnixTimeMilliseconds($Milliseconds).LocalDateTime
    }

    # First we need to log in and get a token back from the API that we use on subsequent requests.
    $Response = Invoke-RestMethod -Method Post -Uri 'https://beekeeper.hivehome.com/1.0/global/login'; -Body (ConvertTo-Json $Settings) -Headers $Headers

    # Add the token to the headers.
    $Headers.Add('Authorization', $Response.token)

    # Set up some additional variables that we'll use to work out which device we want the history from and which API endpoint (UK, US, IT etc.) we want the request to be sent to.
    $ApiUrl = $Response.platform.endpoint
    $Devices = $Response.devices
    $Products = $Response.products

    # Work out the ID of the zone we are sending the history request for.
    $ThermostatZone = $Products | Where-Object {$_.type -eq "heating" -and $_.state.name -eq $ZoneName}

    # Get the raw history data between the start and end dates for the zone we want.
    $RawHistory = Invoke-RestMethod -Method Get -Uri "$($ApiUrl)/history/heating/$($ThermostatZone.id)?start=$(DateTimeToUnixTimestamp($StartDate))&end=$(DateTimeToUnixTimestamp($EndDate))&timeUnit=DAYS&rate=1&operation=AVG" -Headers $Headers

    # Re-jiggle the object to make processing dates easier in the next step
    $HistoryData = $RawHistory.data

    # Convert the unix timestamps in the response to date time objects so they can be read easily and round our temperature to 2 digits, we aren't scientists.
    for ($i = 0; $i -le ($HistoryData.Count - 1); $i++) {
    $HistoryData[$i].date = ConvertUnixTime($HistoryData[$i].date)
    $HistoryData[$i].temperature = [Math]::Round(($HistoryData[$i].temperature), 2)
    }

    # Export the data in the HistoryData object to a comma separated values file that we can use with Excel, Google Sheets etc. to draw our desired charts.
    $HistoryData | Export-Csv -Path D:\History.csv

Feedback and Knowledge Base