Struggling to understand Energy Dashboard, Rest Sensor Values, and necessary YAML configs

Greetings everyone. I’ve been running HA for several months now and the community has been nothing short of amazing in terms of quality information. But this past week, I’ve finally hit an issue that I am conceptually struggling to put together across several threads, my current understanding of HA, and my configuration.

Where I’m at after about a week/today
I’m able to pull my kWh usage from my energy provider via a Rest API. They provide readings every 15 minutes. This means that every 15 minutes I have a different value that could be higher or lower than the previous value, but it will always be a positive value. After some tuning/looking through the community I eventually arrived on the following.

- platform: rest
  resource: https://myrestendpoint
  name: Energy Reading
  unique_id: lysESISM
  verify_ssl: true
  method: GET
  scan_interval: 900
  json_attributes:
    - Measure
  value_template: "{{ value_json.Measure | float }}"
  unit_of_measurement: "kWh"
  device_class: energy
  state_class: total_increasing

This works perfectly (at least so I think). When I lookup this sensor via Settings → Devices & Services → Entities, I see it with the current kWh reading although it sometimes says Unavailable. But in any case, values are stored, and I have a chart that shows these readings with the values that directly match those from my energy provider.

I’m then able to select this in the energy dashboard, by virtue of/my current understanding that the sensor has a Device_Class = energy. I did this, and then an hour later I had my first reading in the Energy Dashboard but it was completely off/not following the reading I was expecting per the sensor (should have been 5.36kWh for the given hour). I let this go on several hours, and my readings range from either negative e.g. I’m returning power to the grid (which I am not) or I’m consuming barely anything (i.e. 0.01kWh or 0.05kWh). But the sensor values, when added up for a given hour, were always correct.

Through my searching I came across what appear to be 2 incredibly relevant threads:

And this is where I’m struggling/don’t entirely know how to move forward. So I’m going to “type/think outloud” here with what is currently kicking around in my head, what I’m trying to sniff out between the three threads above, and thus say some potentially false things that I’m looking for correction/education on.

  • The Rest Sensor has to be configured correctly. I see values that I’m expecting.
  • The Energy Dashboard is performing some kind of math on the Rest Sensor every 5 minutes thereby throwing off a calculation that it uses to render
  • If the Energy Dashboard is not performing some calculation (because its the presentation layer, it feels weird if it was doing something unique), then the Rest Sensor lacks a configuration that isn’t entirely clear to me. I saw mention of an Availability Template, but I’m not sure I understand the relationship between the Dashboard/selecting an energy source, a Template, an Availability Template, and the underlying Rest Sensor. If this is the path to pursue, what does that configuration even look like? Would I have a sensor, template, and an availability template? Is that three separate configs? two? one? Do those become selectable in the Energy Dashboard? Do they compliment/integrate somehow with each other?
    • If the above point is true, then it feels like the energy dashboard doesn’t know how to handle “Unavailable” on the underlying rest sensor, and is leading to unexplainable numbers, thus requiring use of a Template (somewhere) to compensate for this?

If you read this, thanks for your time! :slight_smile: