Apex Charts data_generator, entity.attributes aren't series data

I’m attempting to add a series to an Apex Chart that only return the oldest and newest values. Every example I see has something like…

- entity: sensor.scale
  data_generator: >
     return entity.attributes.weight.map(function() {
        ...
     });

The problem is, the sensors I’m interest only have strings in their .attributes like…

state_class: measurement
unit_of_measurement: kg
icon: mdi:scale-bathroom
friendly_name: Scale Weight

I was under the impression that’s how entity.attributes worked, they’re static info about the sensor itself. So all I have access to is the current entity.state. So my two questions are; why don’t my entities have series data in attributes? How do I get my series data if not available there?

I’m guessing you’re being misled a bit by the example in the card’s documentation. It’s a bit contrived - not sure why anybody would have a sensor with arrays of attributes for time and value. But attributes can be anything, not just static info.

HA stores the time series as separate records - each time the state (or attributes) change, a new record is created with the date/time. You never really access the full series yourself and there’s no clean and simple way to do it.

I’m not really clear on what you want to achieve. If the series only returns the oldest and newest values, are you wanting to plot a straight line between the two? If this is the case, then getting the newest value is easy - that’s the state. Getting the oldest value is the challenge. From within the card you’ve only got access to “hass” which is not going to give you history. If you’re happy to have it at a fixed time period in the past (eg. 4 days ago), you could create another entity using a SQL Sensor to get the state at that point from the database. But I suspect I’m misunderstanding what you want.

fwiw the only time I’ve used data_generator is to plot odd weeks vs even weeks (with fill) so I can see some semblance of time in a chart.

Hah, great, glad I’m not imagining those example are kinda weird.

I’m not really clear on what you want to achieve

Basically I want the rise over run for a given chart/duration.

That SQL sensor might do the trick. I found a mediocre solution using hass.callWS to query recorder/statistics_during_period but this is finicky so far and needs more tweaking. I’ll give the SQL sensor a spin.