Creating Sensors and filtering specific JSON Value from Curb Energy API

I haven’t updated to the latest version 2023.8. I’m using 2023.7

But it seems that the problem is within the sensor created by the rest platform.

Can you show us the full yaml config of the rest sensors? Specifically the part that show the class for the sensors created

Like this:


    sensor:
      - name: "Curb Water Pump & Deck"
        device_class: power
        unit_of_measurement: W
        value_template: "{{ value_json.circuits[6].w }}"
        unique_id: curb-0
      - name: "Curb Office Bath and Old Kitchen"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[1].w }}"
        unique_id: curb-1
      - name: "Curb AC Master"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[2].w }}"
        unique_id: curb-2
      - name: "Curb AC Living Room"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[3].w }}"
        unique_id: curb-3
      - name: "Curb Washer and Dryer"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[4].w }}"
        unique_id: curb-4
      - name: "Curb Mini Bar Wine Cooler"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[5].w }}"
        unique_id: curb-5
      - name: "Curb Fridge and Freezer"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[0].w }}"
        unique_id: curb-6
      - name: "Curb AC Baby Room"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[7].w }}"     
        unique_id: curb-7
      - name: "Curb Baby Room and Bathroom"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[8].w }}"
        unique_id: curb-8
      - name: "Curb Dishwasher Disposal"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[9].w }}"
        unique_id: curb-9
      - name: "Curb Solar Panels 1"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[10].w }}"
        unique_id: curb-10
      - name: "Curb Living Dining and Office Equip"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[11].w }}"
        unique_id: curb-11
      - name: "Curb AC Office"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[12].w }}"
        unique_id: curb-12
      - name: "Curb Master Bathroom"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[13].w }}"
        unique_id: curb-13
      - name: "Curb Garage Door"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[14].w }}"
        unique_id: curb-14
      - name: "Curb Solar Panels 2"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[15].w }}"
        unique_id: curb-15

I ended up updating to the same version as you. The newest version broke too many other things I had setup and I don’t have the time to track down fixes for all of them.

Thanks

Well I updated to 2023.8 and I don’t have any problems with the sensors or the rest platform. If you have the time share your full rest config for curb so we can see what might be causing it.

Hello, I know this is much later, but I am going through this thread trying to recreate this for my Curb setup. I am able to pull my access token and get all my values via curl commands as you have documented above, so I am hoping that I am just missing something.

I don’t see any evidence of it failing in the logs, but I don’t see my sample sensor show up for sensor 0.

Here’s what I have:

configuration.yaml:

rest:
  - resource: https://app.energycurb.com/api/latest/11-22-33-my-id
    scan_interval: 10
    method: GET
    headers:
      Authorization: >
        Bearer {{ state_attr('sensor.curb_token_request', 'access_token') }}
      Content-Type: application/json
    sensor:
      - name: "Zebra"
        value_template: "{{ value_json.circuits[0].w }}"
        unique_id: curb-0

secrets.yaml:

curb_secret_token: Bearer e123myaccesstoken #(Replace with your own access token taken before)

sensors.yaml:

### CURB ACCESS_TOKEN REFRESH ###
  - platform: rest
    name: curb_token_request
    resource: https://energycurb.auth0.com/oauth/token
    method: POST
    headers:
      Content-Type: application/json
      Cache-Control: no-cache
    payload: '{"grant_type": "password", "audience": "app.energycurb.com/api", "username": "[email protected]", "password": "password123", "client_id": "iKAoRkr3qyFSnJSr3bodZRZZ6Hm3GqC3", "client_secret": "dSoqbfwujF72a1DhwmjnqP4VAiBTqFt3WLLUtnpGDmCf6_CMQms3WEy8DxCQR3KY"}'  
    value_template: 'OK'
    scan_interval: 43200
    json_attributes:
      - access_token
rest:
  - resource: https://app.energycurb.com/api/latest/11-22-33-my-id
    scan_interval: 10
    method: GET
    headers:
      Authorization: >
        Bearer {{ state_attr('sensor.curb_token_request', 'access_token') }}
      Content-Type: application/json
    sensor:
      - name: "Zebra"
        value_template: "{{ value_json.circuits[0].w }}"
        unique_id: curb-0

Instead of https://app.energycurb.com/api/latest/11-22-33-my-id use this address instead

https://app.energycurb.com/api/v3/latest/11-22-33-my-id

I think adding the v3 will fix it.

Thank you! This thread has been awesome and has helped me get Curb up and running when the search results normally seem to imply it can’t be done. This has been a huge help, if there’s a way to buy you a coffee let me know. Also for anyone else finding this, I had a typo in my configuration.yaml, here’s a working example:

rest:
  - resource: https://app.energycurb.com/api/v3/latest/my-crub-id-123456
    scan_interval: 10
    method: GET
    headers:
      Authorization: >
        Bearer {{ state_attr('sensor.curb_token_request', 'access_token') }}
      Content-Type: application/json
    sensor:
      - name: "curb_power_workbench"
        device_class: power
        unit_of_measurement: "W"
        value_template: "{{ value_json.circuits[0].w }}"
        unique_id: curb-0

I’m glad to help and that you solved your problem, currently I’m still trying to get live data from curb and not 1 min refresh data into Home Assistant, if I make it happen I’ll update this same thread.

If you wish to buy me a coffee you can do so here.

Thanks