Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Spread data spikes over missing days in counter graphs#6472

Open
dwmw2 wants to merge 2 commits intodomoticz:developmentfrom
dwmw2:meter-spread
Open

Spread data spikes over missing days in counter graphs#6472
dwmw2 wants to merge 2 commits intodomoticz:developmentfrom
dwmw2:meter-spread

Conversation

@dwmw2
Copy link
Contributor

@dwmw2 dwmw2 commented Dec 1, 2025

When there are gaps in the data (e.g., device offline for multiple days), the accumulated usage appears as a large spike on the day data resumes. This preprocessing function detects gaps and spreads the accumulated value evenly across the missing days, preventing spikes from affecting graph scale.

It used to look like this:
Screenshot from 2025-12-01 11-32-14

... now it looks like this:

Screenshot from 2025-12-01 11-53-24

@dwmw2 dwmw2 changed the title Spread data spikes over missing days in counter graphs [WIP] Spread data spikes over missing days in counter graphs Dec 1, 2025
@dwmw2
Copy link
Contributor Author

dwmw2 commented Dec 1, 2025

For some reason this isn't working on my production box even though it was working in testing on the same type of meter device.

@dwmw2
Copy link
Contributor Author

dwmw2 commented Dec 1, 2025

Ah, I figured it out. My test server had gaps where Domoticz itself hadn't been running. My production server had been running but the meter data hadn't been coming in, so there were actual zeroes in the data and not just gaps:

    {
      "d": "2025-03-02",
      "v": "97.703"
    },
    {
      "d": "2025-03-03",
      "v": "87.305"
    },
    {
      "d": "2025-03-04",
      "v": "0.000"
    },
    {
      "d": "2025-03-05",
      "v": "0.000"
    },

I'm confused by the presence of zeroes; surely we shouldn't be writing to Meter_Calendar for that day if the device hasn't actually updated at all?

We can tweak the graph code to treat those like empty data, but I'm less sure that we should. What do you think?

dwmw2 added 2 commits December 1, 2025 18:27
When a device hasn't updated within the timeout period, UpdateMeter()
already prevents entries from being added to the Meter table. The
AddCalendarUpdateMeter() function should leave gaps in Meter_Calendar
rather than explicitly inserting zeros, allowing the graph smoothing
code to handle the missing data appropriately.
When there are gaps in the data (e.g., device offline for multiple days),
the accumulated usage appears as a large spike on the day data resumes.
Detect gaps and spread the accumulated value evenly across the missing
days to prevent spikes from affecting graph scale.

The fillMissingDays function is implemented in the shared
counterLogSeriesSupplier module and used by all counter/meter device
types (energy-used, energy-generated, gas, water, counter, P1 energy).
@dwmw2 dwmw2 changed the title [WIP] Spread data spikes over missing days in counter graphs Spread data spikes over missing days in counter graphs Dec 1, 2025
@dwmw2
Copy link
Contributor Author

dwmw2 commented Dec 1, 2025

Fixed the code which introduced the zeroes. We deliberately don't introduce explicit zeroes in the Meter table, and we shouldn't in Meter_Calendar either. Then the JS code which smooths over empty days will be fine.

@gizmocuz gizmocuz force-pushed the development branch 2 times, most recently from a0a55cd to e57a1b6 Compare December 2, 2025 11:09
@0crap
Copy link

0crap commented Feb 11, 2026

Fixed the code which introduced the zeroes. We deliberately don't introduce explicit zeroes in the Meter table, and we shouldn't in Meter_Calendar either. Then the JS code which smooths over empty days will be fine.

Just to be sure, this does not alter my solar power "Meter_Calendar" table?
When the solar panels are fully covered with snow there are days with zeroes in that table.
Which is totally legit.

Sorry if unrelated, just asking...

@dwmw2
Copy link
Contributor Author

dwmw2 commented Feb 11, 2026

Good question. No, it should not affect those days because they should have an explicit zero rather than just an absence of data.

@0crap
Copy link

0crap commented Feb 11, 2026

Thx, good to know.

I do understand your use case, but e.g. Meter and Meter_Calendar should reflect the truth as close as possible.
Let code automagically alter it feels a bit uncomfortable.
Maybe I'm just overly concerned.

I do appreciate your time!

@0crap
Copy link

0crap commented Feb 12, 2026

If I may suggest, another way of looking at your use case might be to change the autoscaler behavior?
Let the autoscaler ignore one or two stupid high readings...

@gizmocuz
Copy link
Contributor

As you know, there is still an issue with Enphase/Envoy and the latest beta/counterhelper.
This needs to be addressed and solved.
If this was masked, we have no idea of a spike at all.. not sure if that is desired?

@0crap
Copy link

0crap commented Feb 12, 2026

I don't think @dwmw2 is specifically having an issue with his Enphase/Envoy. That is not stated in his opening post.
I personally did have an issue in that regard and got confronted with a spike in my Generated graph.

I do agree that I would not like to have that spike get masked. That also would have masked the underlying problem.
Which in my case, i guess, is somehow related to new Envoy firmware.

My personal opinion is that Domoticz should not alter Meter or Meter_Calendar data on it's own.
Having code in place that can do that, makes me feel a bit uncomfortable.
I am not a coder, so I can't comment on the OP's code, I'm just trying to give some feedback by reading his comments.

(It is fair to say that I manually needed to edit the database to fix my issue.
Not by changing the column Value but by making the column Counter consistent again.)

@dwmw2
Copy link
Contributor Author

dwmw2 commented Feb 12, 2026

My personal opinion is that Domoticz should not alter Meter or Meter_Calendar data on its own.

It's Domoticz which creates those tables. But yes, again: the 'smoothing' here is only in the display, and the tables aren't modified to contain the averaged-out data.

That does need a bug fix to avoid writing false explicit zeroes to the Meter_Calendar when there are no new data during that day, which is the only change to the Meter_Calendar handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants