UtilityAPI.com integration with energy

I’m trying to integrate UtilityAPI.com with HA though the configuration.yaml. Here is what I have so far, but it doesn’t seem to be working.

Configuration for UtilityAPI

utilityapi:
base_url: “https://utilityapi.com/api/v2
authorization:
token: “your_api_token_here”

Configuration for meter data collection

meters:

  • uid: “1495712”
    endpoint: “/files/meters_lineitems_csv”
    fields:
    • meter_uid
    • utility
    • utility_service_id
1 Like

Any luck getting this working?

I was able to get this to return back the meter reading as a sensor entry. (replace “YOURMETER” with your meter UID and “YOUR_BEARER_TOKEN” with your unique information.

sensor:
  - platform: rest
    name: "Electric Usage"
    resource_template: >
      https://utilityapi.com/api/v2/intervals?meters=YOURMETER&order=latest_first&end={{ (now() - timedelta(hours=48)).isoformat() }}
  # start={{ (now() - timedelta(hours=49)).isoformat() }}
  # 
    headers:
      Authorization: "Bearer YOUR_BEARER_TOKEN"
    value_template: "{{ value_json.intervals[0].readings[0].kwh }}"
    unit_of_measurement: "kWh"
    device_class: "Energy"
    state_class: "total_increasing"
    scan_interval: 3600

However, the data is 24 hours old, and Home Assistant’s built-in sensor platform doesn’t support backfilling historical data directly. The sensor state in Home Assistant is always the current state, and it doesn’t allow for manually setting timestamps of the past states.

My next thought is to try:

  1. Database Insertion: directly inserting the historical data into the Home Assistant database (SQLite).
  2. Custom Component: create a custom component that uses the history.set_state service to set past states.
  3. Third-Party Tools: There are third-party tools and add-ons like InfluxDB that can store time-series data.

I’m already running mariaDB, but I’m just not sure how to create a custom sensor that can render in the energy dashboard with the historical data I can create/load. It sounds like this is something the community is looking for as well…

let me know if that code works for you as well

1 Like

Hey @dhellerstedt, thanks for the information, this is great. Quick question though, how much are you having to pay to get this data from UtilityAPI? From what I can tell, all of their pricing is geared towards businesses. It looks like if I wanted to get daily usage for my meter, it’d cost $30 per month. At that point I’d rather just go into my utility company’s dashboard and export the data. Is there some way you’re getting around that? Or do they have a personal-use version? Thanks!

Your right, it is geared toward businesses. I would not recommend you pay for this. I suspect my utility company uses utilityapi as a data platform/aggregator. My guess is that each utility company negotiates the number of calls they get monthly which also allows for some predetermined access for the utility’s customers. In my case my Consumers Energy account allows me access to the data associated with my meters at no cost (I think P&E does too?). Why build my own RTL-SDR meter reader if I can just get it free from the utility? The problem is that the data access for my account level is only updated once a day (so it is at least 24 hours old) and its only “read” in hourly increments. But hey, it is better than nothing.

1 Like

You might look at how this works:

Note the energy panel works off of statistics, not regular history. So you don’t want to insert records into the history table but into the statistics table. A rest sensor is probably the wrong way to go for that.

With this integration that should work. You can create the needed import file (e.g. csv) and call the service to import the data directly afterwards. Let me know if you are successful.

Have you made any progress on this? I am looking at integrating this as well.

Also, I too have consumersenergy. It’s been awhile since I set up the Utiltiy API account so I don’t remember setting it up. I am not seeing any payment settings on my Utility API dashboard, but the utilityapi pricing pages are confusing. Are you successfully daily monitoring without being charged? I am slightly afraid to turn it on because I don’t want to rack up a balance, but again I don’t see anything in my account indicating any payment methods or charges.