How do I display nested values from an API sensor for Reposit

I’m trying to display power consumption and generation values from a power usage system called Reposit (repositpower.com) which I already have installed. I’ve managed to interrogate the iOS app and I have found the API URL. The output is displayed within a browser (following authentication) as:

{
  "data": {
    "battery": {
      "message": null,
      "state": "ONLINE",
      "val": 0.0
    },
    "battery_soc": {
      "val": 0
    },
    "display_scale": {
      "max": 5.139999866485596,
      "min": 0
    },
    "grid": {
      "message": null,
      "state": "ONLINE",
      "val": 0.09839528143469448
    },
    "house": {
      "message": null,
      "state": "ONLINE",
      "val": 4.794253064432299
    },
    "solar": {
      "message": null,
      "state": "ONLINE",
      "val": -4.695857782997605
    }
  }
}

I’m running the latest version of hass.io on my raspberry pi and I have so far put together the following code, based off the description given here (https://www.home-assistant.io/integrations/rest/):

# Reposit
  - platform: rest
    name: reposit
    resource: https://urlforapi
    username: username
    password: password
    authentication: basic
    json_attributes:
      - data
    value_template: 'OK'
    scan_interval: 5
  - platform: template
    sensors:
      reposit_grid:
        value_template: '{{ states.sensor.reposit.attributes["data"]["grid"]["val"] }}'
        device_class: power
        unit_of_measurement: 'kW'
      reposit_house:
        value_template: '{{ states.sensor.reposit.attributes["data"]["house"]["val"] }}'
        device_class: power
        unit_of_measurement: kW
      reposit_solar:
        value_template: '{{ states.sensor.reposit.attributes["data"]["solar"]["val"] }}'
        device_class: power
        unit_of_measurement: 'kW'

I’m guessing that I’ve made a simple mistake but if anyone can nudge me in the right direction, it would be greatly appreciated.

Thanks,
Mat

Hi @mathewryan . Have you made any progress with the Reposit interface? I have one as well, and would love some way of interfacing Home Assistant to it.

Was your response string above using the web API, or were you able to pull this data locally?

Cheers. Mark.

Hi @stibbzy and @mathewryan

I don’t have a reposit box (interested in the tech though) so I can’t help you with the URL in @mathewryan’s example…
However if you manage to find out that URL, I’ve done enough wrangling with the rest module to help solve @mathewryan’s original question should he come back.

# Reposit
  - platform: rest
    name: reposit
    resource: https://urlforapi
    username: username
    password: password
    authentication: basic
    json_attributes_path: "$.data"
    json_attributes:
      - grid
      - house
      - solar
    value_template: 'OK'
    scan_interval: 5
  - platform: template
    sensors:
      reposit_grid:
        value_template: '{{ state_attr("states.sensor.reposit", "grid").val }}'
        device_class: power
        unit_of_measurement: 'kW'
      reposit_house:
        value_template: '{{ state_attr("states.sensor.reposit", "house").val }}'
        device_class: power
        unit_of_measurement: kW
      reposit_solar:
        value_template: '{{ state_attr("states.sensor.reposit", "sol").val }}'
        device_class: power
        unit_of_measurement: 'kW'

Hi @stibbzy

I haven’t made a whole lot of progress. I can successfully gain access to the API data in a browser, but when I use the same credentials in HA i’m now getting the error:

{ “error”: “unauthorized”, “message”: “Unauthorized.”, “status”: “error”}

so my issue now seems to be with gaining access to the API. For reference, after interrogating the app, the URL i’m using is:

https://api.repositpower.com/v2/deployments/########/summary/now

where the ######## represents my user key as determined from:

https://api.repositpower.com/docs/

@harrisony, Thanks for cleaning up the code for me, without being able to get past my authentication issue, I can’t comment of how effective it is, but I did need to remove the value_template: 'OK' as it was masking my error message.

Thanks,
Mat

Can you add to your configuration:

logger:
  rest: debug
  aiohttp: debug

restart HA and then look through the logs for anything reposit related.

I’m not sure if either will provide the detail we’re looking for but it’s worth a shot

EDIT: if you’re using the user key, I’m assuming you’re not including username, password and authentication keys in the config

I’m trying to get reposit data but I’m not clear re the Token as every time I run the curl command from RB pi command it generates new token. What should I replace theuserkey with.

Can you please share a working example ?

Guys did you make any progress being able to pull data from the reposit power API into home assistant?