i am a beginner with coding and home assistant and i have a question about an apexcharts data generator.
i would like a line chart where the following is calculated.
Easiest is via a template sensor. The only other thing I know of is using statistics via the websocket api. Sadly this is not well documented as I would expect there would also be a solution for the states.
With below you can add a similar set for entity2 and subtract that in ‘let stat =…’
The benefit of using statistics is that they are all on the same time so you donot have to (possibly) align the datetime-stamps of both sensors…the downside is that statistics are on a much lower frequency
data_generator: |
const stat_entity1 = 'sensor.yoursensor1';
var statistics1 = await hass.callWS({type: 'recorder/statistics_during_period',
start_time: new Date(start).toISOString(), end_time: new Date(end).toISOString(),
statistic_ids: [stat_entity1], period: 'hour'});
var stats1 = statistics1[stat_entity1];
var result = [];
var len = stats1.length;
for (let i = 0; i < len; i++) {let stat = stats1[i].state;
result.push([(new Date(stats1[i].start).getTime()),stat]);}
return result;
How does the statistics and group_by work together?
My LTS statistics is a monotonically growing sensor that increases each time an event occurs. I would like to track number of events per month for past 12 months.
I have a apexchart card and inside apex_config I have two annotations to draw a limit tolerance, but I want to point second limit (24.8) not a fixed value, I need to be equal to a entity value: