Code Monkey home page Code Monkey logo

Comments (5)

home-assistant avatar home-assistant commented on September 27, 2024

Hey there @ThomDietrich, mind taking a look at this issue as it has been labeled with an integration (statistics) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of statistics can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign statistics Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


statistics documentation
statistics source
(message by IssueLinks)

from core.

ThomDietrich avatar ThomDietrich commented on September 27, 2024

Hello @bakerkj,
thanks for the feedback!
The statistics component calculates change_second like this:

return (self.states[-1] - self.states[0]) / age_range_seconds

The calculation doesn't care about the values and the nature of the source sensor.

Did I understand you correctly: You would like a new characteristic which take sum_differences_nonnegative and divides it by the seconds between the oldest and newest sample?

from core.

bakerkj avatar bakerkj commented on September 27, 2024

Hi @ThomDietrich,

I am trying to use change_second to compute the rate of increase of a counter that is always increasing, except when the device is reset (which is when the counter starts again from zero).

I think instead of the existing code

    def _stat_change_second(self) -> StateType:
        if len(self.states) > 1:
            age_range_seconds = (self.ages[-1] - self.ages[0]).total_seconds()
            if age_range_seconds > 0:
                return (self.states[-1] - self.states[0]) / age_range_seconds
        return None

I think I want something like this

    def _stat_change_second_something(self) -> StateType:
        if len(self.states) > 1:
            age_range_seconds = (self.ages[-1] - self.ages[0]).total_seconds()
            change = self.states[-1] - self.states[0]
            if age_range_seconds > 0 and change >= 0:
                return change / age_range_seconds
        return None

So for example

time in seconds | counter | statistic
0               | 0       | None
10              | 10      | 1
20              | 30      | 2
30              | 40      | 1
40              | 0       | None <- counter reset
50              | 20      | 2
60              | 30      | 1

I think in this way, the statistic will not be computed in the case where the counter resets (the change is negative)?

Does that make sense?

Thanks,
Ken

from core.

ThomDietrich avatar ThomDietrich commented on September 27, 2024

I think it does make sense. Did you check this integration? I wonder if it already does what you want (not that I am saying this is strictly out of scope for the statistics integration)

https://www.home-assistant.io/integrations/derivative/

from core.

bakerkj avatar bakerkj commented on September 27, 2024

I think it does make sense. Did you check this integration? I wonder if it already does what you want (not that I am saying this is strictly out of scope for the statistics integration)

https://www.home-assistant.io/integrations/derivative/

If I understand correctly, the derivative sensor has the same challenge with counters that reset to zero:

For sensors that reset to zero after a power interruption and need a “non-negative derivative”, such as bandwidth counters in routers, or rain gauges, consider using the Utility Meter integration instead. Otherwise, each reset will register a significant change in the derivative sensor.

I don't think the Utility Meter integration does what I am looking to do.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.