Historical data

Needs an API key with the battery:historical scope.

Home Assistant keeps its own history of the live sensors. This guide adds what Aotea works out from your battery's records: today's energy totals, by trading period, and the wholesale price for the current half hour.

  1. Step 1: Add the sensors

    Add this to configuration.yaml. It fetches today's 48 half-hour trading periods every 5 minutes.

    Fills in every snippet in these docs. It stays in your browser.

    configuration.yaml
    rest:
      - resource_template: >-
          {% set tz = 'Pacific/Auckland' %}
          {% set start = today_at().strftime('%Y-%m-%d 00:00:00') ~ ' ' ~ tz %}
          {% set end = (today_at() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') ~ ' ' ~ tz %}
          https://api.aoteaenergy.com/api/v1.0.1/battery/data/YOUR_BATTERY_ID?start={{ start | urlencode }}&end={{ end | urlencode }}&intervals=48
        headers:
          Authorization: !secret aotea_api_key
        scan_interval: 300
        sensor:
          - name: "Aotea solar energy today"
            unique_id: aotea_solar_energy_today
            device_class: energy
            state_class: total_increasing
            unit_of_measurement: "kWh"
            value_template: >-
              {{ (value_json.solar_data | select('number') | sum * 0.5) | round(2) }}
    
          - name: "Aotea home energy today"
            unique_id: aotea_home_energy_today
            device_class: energy
            state_class: total_increasing
            unit_of_measurement: "kWh"
            value_template: >-
              {{ (value_json.home_data | select('number') | sum * 0.5) | round(2) }}
    
          - name: "Aotea grid import today"
            unique_id: aotea_grid_import_today
            device_class: energy
            state_class: total_increasing
            unit_of_measurement: "kWh"
            value_template: >-
              {{ (value_json.grid_data | select('number') | select('gt', 0) | sum * 0.5) | round(2) }}
    
          - name: "Aotea grid export today"
            unique_id: aotea_grid_export_today
            device_class: energy
            state_class: total_increasing
            unit_of_measurement: "kWh"
            value_template: >-
              {{ (value_json.grid_data | select('number') | select('lt', 0) | sum * -0.5) | round(2) }}
    
          - name: "Aotea wholesale price now"
            unique_id: aotea_wholesale_price_now
            state_class: measurement
            unit_of_measurement: "NZD/kWh"
            value_template: >-
              {% set i = ((now() - today_at()).total_seconds() // 1800) | int %}
              {% set p = value_json.price_data[i] | default(none) %}
              {{ (p / 1000) | round(4) if p is number else none }}
    SensorShows
    Aotea solar energy todaySolar generated since midnight, kWh.
    Aotea home energy todayHousehold use since midnight, kWh.
    Aotea grid import todayBought from the grid since midnight, kWh.
    Aotea grid export todaySold to the grid since midnight, kWh.
    Aotea wholesale price nowWholesale price for this trading period, $/kWh.

    The energy totals reset at midnight, so they go straight into the Energy dashboard. Grid is netted each half hour, the way trading periods are settled. On daylight-saving change days they're approximate.

  2. Step 2: Restart Home Assistant

    Go to Settings → System → Restart, then search for “Aotea” under Settings → Devices & services → Entities.