Closed mwolter805 closed 11 months ago
I see the same error (HA 2023.10.5).
It looks to me like 1-off bug because when I have a graph displaying last 18 hours, in debugger I see only 17 values were loaded (which may be by design - I don't know).
Looking at websocket communication:
{"type":"recorder/statistics_during_period","start_time":"2023-10-27T22:24:30.823Z","end_time":"2023-10-28T16:24:30.824Z","statistic_ids":["sensor.solary_tracker_on"],"period":"hour","id":35}
returns 17 records:
{"id":35,"type":"result","success":true,"result":{"sensor.solary_tracker_on":[{"start":1698447600000,"end":1698451200000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698451200000,"end":1698454800000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698454800000,"end":1698458400000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698458400000,"end":1698462000000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698462000000,"end":1698465600000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698465600000,"end":1698469200000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698469200000,"end":1698472800000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698472800000,"end":1698476400000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698476400000,"end":1698480000000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698480000000,"end":1698483600000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698483600000,"end":1698487200000,"last_reset":null,"state":10.25,"sum":2164.25,"change":10.25},{"start":1698487200000,"end":1698490800000,"last_reset":null,"state":48.5,"sum":2212.75,"change":48.5},{"start":1698490800000,"end":1698494400000,"last_reset":null,"state":22.0,"sum":2234.75,"change":22.0},{"start":1698494400000,"end":1698498000000,"last_reset":null,"state":0.0,"sum":2234.75,"change":0.0},{"start":1698498000000,"end":1698501600000,"last_reset":null,"state":9.24,"sum":2243.99,"change":9.239999999999782},{"start":1698501600000,"end":1698505200000,"last_reset":null,"state":0.0,"sum":2243.99,"change":0.0},{"start":1698505200000,"end":1698508800000,"last_reset":null,"state":0.0,"sum":2243.99,"change":0.0}]}}
Moving the graph a little:
{"type":"recorder/statistics_during_period","start_time":"2023-10-27T20:22:54.151Z","end_time":"2023-10-27T22:21:06.576Z","statistic_ids":["sensor.solary_tracker_on"],"period":"hour","id":36}
results:
{"id":36,"type":"result","success":true,"result":{"sensor.solary_tracker_on":[{"start":1698440400000,"end":1698444000000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0},{"start":1698444000000,"end":1698447600000,"last_reset":null,"state":0.0,"sum":2154.0,"change":0.0}]}}
The graph does not show 1:00 my local time but the data is there (1698447600000 epoch time; this is after move)
Thanks for the in depth analysis. So this means HA is sending the data but this card isn't considering it, correct?
Home assistant probably stopped sending a fake first datapoint, so this line is causing issues: https://github.com/dbuezas/lovelace-plotly-graph-card/blob/ef1834ac403a30e0d0495e3dfa552315c71c2dd5/src/cache/Cache.ts#L123
I would guess this is the change in HA: https://github.com/home-assistant/core/pull/92823
I've removed fake boundary handling in my local build it looks good to me. I will try to issue PR with proper code change later.
Oh cool! One thing you can do to confirm that this works correctly:
refresh_interval: 1s
entities:
- entity: sensor.some_sensor_that_updates_frequently
line:
shape: linear
The result should be a plot that doesn't go in steps, but that connects the dots with direct lines. If it goes in steps, it means that the algorithm is adding faux datapoints.
It does not work correctly for me with refresh_interval: 1s
- the graph does not auto-scroll anymore if I use it.
Without it, it scrolls fine. In both cases, lines look fine to me:
type: custom:plotly-graph
entities:
- entity: sensor.main_power_channel_a_power
line:
shape: linear
- entity: sensor.main_power_channel_b_power
line:
shape: linear
- entity: sensor.main_power_channel_c_power
line:
shape: linear
hours_to_show: 0.1
This means that there is a problem with fetching. Removing update interval is equivalent to setting it to auto
, which grabs datapoints as they come (and skips fetching).
If you scroll you are now probably losing datapoints
It works - the bug was in specifying refresh interval - it must be just refresh_interval: 1
- not refresh_interval: 1s
:)
Ohhhh you are right!
If you:
then you fixed it 🎉
Well, maybe but I am not sure - I've just removed all fake data point handling. I want to check what data is fetched - whether we still need to fetch a little bit more or not (as it is commented in Cache.ts), then I will issue a PR.
Here's an idea to test it:
entities:
- entity: number.your_template_sensor
line:
shape: linear
mode: lines+markers
filters:
- fn: console.log # see https://github.com/dbuezas/lovelace-plotly-graph-card#debugging
refresh_interval: 0.1
hours_to_show: 30s
Then:
It does not work well so far:
More debugging:
api/history/period/2023-11-14T07:55:56.642Z?filter_entity_id=sensor.seconds_time_tracker&significant_changes_only=0&no_attributes&&minimal_response&&end_time=2023-11-14T07:56:01.643Z
[
[
{
"entity_id": "sensor.seconds_time_tracker",
"state": "1699948501.1",
"attributes": {},
"last_changed": "2023-11-14T07:55:56.642000+00:00",
"last_updated": "2023-11-14T07:55:56.642000+00:00"
}
]
]
api/history/period/2023-11-14T07:55:57.133Z?filter_entity_id=sensor.seconds_time_tracker&significant_changes_only=0&no_attributes&&minimal_response&&end_time=2023-11-14T07:56:02.134Z
[
[
{
"entity_id": "sensor.seconds_time_tracker",
"state": "1699948501.1",
"attributes": {},
"last_changed": "2023-11-14T07:55:57.133000+00:00",
"last_updated": "2023-11-14T07:55:57.133000+00:00"
}
]
]
Which shows last_changed
and last_updated
is changing.
For the first returned record only which is actually the oldest record for the two...:
api/history/period/2023-11-14T07:55:57.581Z?filter_entity_id=sensor.seconds_time_tracker&significant_changes_only=0&no_attributes&&minimal_response&&end_time=2023-11-14T07:56:02.582Z
[
[
{
"entity_id": "sensor.seconds_time_tracker",
"state": "1699948501.1",
"attributes": {},
"last_changed": "2023-11-14T07:55:57.581000+00:00",
"last_updated": "2023-11-14T07:55:57.581000+00:00"
},
{
"state": "1699948561.1",
"last_changed": "2023-11-14T07:56:01.141916+00:00"
}
]
]
api/history/period/2023-11-14T07:55:58.478Z?filter_entity_id=sensor.seconds_time_tracker&significant_changes_only=0&no_attributes&&minimal_response&&end_time=2023-11-14T07:56:03.479Z
[
[
{
"entity_id": "sensor.seconds_time_tracker",
"state": "1699948501.1",
"attributes": {},
"last_changed": "2023-11-14T07:55:58.478000+00:00",
"last_updated": "2023-11-14T07:55:58.478000+00:00"
},
{
"state": "1699948561.1",
"last_changed": "2023-11-14T07:56:01.141916+00:00"
}
]
]
It looks to me that the issue is only for statistic data so I've create PR #325 to fix it.
Hi @dbuezas, I see this issue is completed. Appears this fix is not in the latest release. Is there a way I can test it?
I'll make a release now. Give it a couple of minutes and update the card from hacs
Discussed in https://github.com/dbuezas/lovelace-plotly-graph-card/discussions/314
Using the following versions: lovelace-plotly-graph-card: 3.3.3 Home Assistant: 2023.9.3