Creating Sensors and filtering specific JSON Value from Curb Energy API

Sure can.

First things first. After reaching out for more than 8 months to Curb’s customer support, They point me to a github page that helped to set up the integration. (I don’t know if this was available before. As I was searching for a solution for a long time)

Curb v2 Third Party App Integration

You need to send a curl POST command with this information:

curl -X POST \
  https://energycurb.auth0.com/oauth/token \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
	"grant_type": "password",
	"audience": "app.energycurb.com/api",
	"username": "{{USER_EMAIL}}",
	"password": "{{USER_PASSWORD}}",
	"client_id": "iKAoRkr3qyFSnJSr3bodZRZZ6Hm3GqC3",
	"client_secret": "dSoqbfwujF72a1DhwmjnqP4VAiBTqFt3WLLUtnpGDmCf6_CMQms3WEy8DxCQR3KY"
}'

Then add to the previous code your username and password that you use to login to Curb’s Montioring Website

Note that the client_id and client_secret are taken from Curb’s GitHub:

We provide an example pair of client credentials that you can use to get up and running with our API quickly and easily.

Client ID : iKAoRkr3qyFSnJSr3bodZRZZ6Hm3GqC3
Client Secret : dSoqbfwujF72a1DhwmjnqP4VAiBTqFt3WLLUtnpGDmCf6_CMQms3WEy8DxCQR3KY"

After you filled that up send the command and you should receive the following response:

With the received access_token you can call Curb’s API, as per the documentation to get the parameters required to call the circuit data:

GET /api/v3/locations - Get all of the users’s locations.

curl -X GET https://app.energycurb.com/api/v3/locations -H 'authorization: Bearer {{access_token}}'

Replace {{access_token}} with the access token received on the previous command, and don’t forget the ' at the end of the curl command.

You should receive a response with other details, but what you are interested in, is the “location_id” or just “id”) section:

    "address": "1524 S IH 35",
    "country": "USA",`Preformatted text`
    "geocode": "30.24306,-97.73605500000001",
    "name": "CURB Office",
    "id": "32d23ga8-re33-4294-a382-7fga34m4ff28",
    "postcode": "78704",
    "hasProduction": true

Copy this “location_id” or just “id” into the next section of the code to get the circuit data:

  • GET /latest/:locationId - Get the latest averaged minute sample snapshot of all circuits, plus the consumption, production, and net values.
curl -X GET https://app.energycurb.com/api/v3/latest/{{location_id}} -H 'authorization: Bearer {{acces_token}}'

Replace {{location_id}} with the id received on the previous command and also replace {{access_token}} with the access token, and don’t forget the ' at the end of the curl command.

Received information:

{
	"timestamp": 1683652080,
	"locationId": "32d23ga8-re33-4294-a382-7fga34m4ff28",
	"consumption": 1624,
	"production": 0,
	"storage": 0,
	"net": 1624,
	"circuits": [{
		"grid": false,
		"production": false,
		"battery": false,
		"circuit_type": "consumption",
		"label": "Fridge and Freezer",
		"id": "a7e5f658-bbd0-42f6-9778-a7a2259899b4",
		"w": 144,
		"main": false

With this information I went to https://jsonpathfinder.com/ as suggested by @tom_l and I was able to find the path to my circuits on the JSON string and create a rest api and a template sensor for each of the circuits on my data.

This following information is stored under my sensor.yaml (As I have separted it from the configuration.yaml to avoid many lines on that configuration.yaml file)

  - platform: rest
    name: curb_fridge
    resource: https://app.energycurb.com/api/v3/latest/32d29fe8-be29-4184-a159-7fde34a4ff34
    headers:
      Authorization: !secret curb_secret_token
      Content-Type: application/json
    json_attributes_path: "$.circuits.[0]"
    json_attributes:
      - w
    scan_interval: 50
    value_template: "{{value_json.curb_fridge_watts}}"
    method: GET
  - platform: template
    sensors:
      curb_fridge_consumption:
        value_template: "{{ state_attr('sensor.curb_fridge', 'w')}}"

Note: To capture the first circuit that shows up on your data the “json_attributes_path” would be “$.circuits.[0]”, the second circuit would be “$.circuits.[1]” and so on…

The authorization on this rest api sensor includes a line on the secrets.yaml file as this:

curb_secret_token: Bearer {{access_token}} #(Replace with your own access token taken before)


Rest Api Sensor with the W (watts) attributes of the specific breaker


Template sensor of the Watts taken from the Rest Api Sensor.

I am sure there’s better way to create the sensors, I am open to ideas as I am not an expert at all on this.

On the down side of this integration:

  • acces_token get’s revoked every 24 hours (I am trying to reach out to Curb’s Customer Support to see if it can be changed to something more permanent)

  • Circuit Data information is not “live”, meaning when you input the cURL * GET ‘/latest/:locationId’ - You get the latest averaged minute sample snapshot of all circuits. (It updates every minute not every second)

I am hoping to get real live data on Home Assistant via the simple-browser-client from Curb’s but so far I am not able to web-scrape the data from there due to my limited knowledge (it seems as if the server first need to call a javascript to sign in and then access the data. If there’s anyone with some insight for this please jump in.

Thanks