I’m, tearing my now non-existent hair out trying to get to grips with creating a date range in my data generator.
I want to create a chart, a bit like the solar chart on the energy screen, that shows 24 hours for today which I will display multiple data sets on. None of those sets have any timestamps, I only have an a array of 24 values to plot at hourly intervals.
I have created two sensors…one that creates a timestamp as a string in the format 2025-05-08T00:00:00.000000+01:00 and another that takes that value and generates a timestamp from it which results in 1746658800000.
All good so far…in the apexchart config I have the following…
- entity: sensor.algorithm
type: column
data_generator: |
let stamp = hass.states['sensor.today_time_midnight_timestamp'].state;
const now = new Date(stamp);
const data = [];
for(let i = 0; i < 24; i++) {
data.push([now.getTime() + (i * 1000 * 60 * 60), hass.states['sensor.algorithm'].attributes.data.distribution[i] ]);
}
return data;
But instead of spreading the data out one per hour, I just get one column for the first hour.
Now the weird part is, if I replace the stamp with either a string or unix timestamp, everything renders correctly.
So the following works properly…just hard coded the stamp value!
- entity: sensor.algorithm
type: column
data_generator: |
let stamp = 1746658800000;
const now = new Date(stamp);
const data = [];
for(let i = 0; i < 24; i++) {
data.push([now.getTime() + (i * 1000 * 60 * 60), hass.states['sensor.algorithm'].attributes.data.distribution[i] ]);
}
return data;
So what am I doing wrong here…the sensor has the right value, in fact I output it in place of the data for the columns to prove it was there.
I think I must be getting back a value that is not the unix timestamp, but if not…why? It displays fine in the template editor.
This is the last piece of my puzzle and it’s got me beat right now.