-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add blog post about new sensor state classes #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fa29b0b
58a66db
7be1326
08e5fdf
b17c194
acfde8d
07468ee
ba155eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| author: Erik Montnémery | ||
| authorURL: https://github.com/emontnemery | ||
| title: "New sensor state classes: total and total_increasing" | ||
| --- | ||
|
|
||
| Two new state classes, `STATE_CLASS_TOTAL` and `STATE_CLASS_TOTAL_INCREASING` have been | ||
| added. In addition, it is no longer mandatory to set the `last_reset` attribute in order | ||
| for `sum` statistics to be generated. The driver for the changes is to make it easier to | ||
| integrate with utility meters etc. | ||
|
|
||
| ### State classes | ||
|
|
||
| There are now 3 defined state classes: | ||
| - `STATE_CLASS_MEASUREMENT`, the state represents a measurement in present time, for | ||
| example a temperature, electric power etc. | ||
|
emontnemery marked this conversation as resolved.
Outdated
|
||
| - `STATE_CLASS_TOTAL`, the state represents a total amount which can both increase and | ||
|
emontnemery marked this conversation as resolved.
Outdated
|
||
| decrease, e.g. the value of a stock portfolio | ||
| - `STATE_CLASS_TOTAL_INCREASING`, a monotonically increasing total, e.g. an amount of | ||
| consumed gas, water or energy | ||
|
|
||
| #### STATE_CLASS_TOTAL | ||
| If the sensor's state class is `STATE_CLASS_TOTAL`, the last_reset attribute can | ||
|
emontnemery marked this conversation as resolved.
Outdated
|
||
| optionally be set to gain manual control of meter cycles; each time last_reset changes | ||
| the corresponding value is used as the zero-point when calculating `sum` statistics. | ||
| If last_reset is not set, the sensor's value when it was first added is used as the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "first added" -> when looking at the examples it looks like it uses the last state as the zero-point, not the first state. |
||
| zero-point when calculating `sum` statistics. | ||
|
|
||
| Example of `STATE_CLASS_TOTAL` without last_reset: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are great examples and shouldn't be in a blog post but in the docs instead.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they can be both here and in the docs? |
||
|
|
||
| | t | state | sum | | ||
| | ---: | -----: | -----: | | ||
| | 0 | 1000 | 0 | | ||
| | 1 | 1010 | 10 | | ||
| | 2 | 0 | -1000 | | ||
|
Danielhiversen marked this conversation as resolved.
Outdated
|
||
| | 3 | 5 | -995 | | ||
|
|
||
| Example of `STATE_CLASS_TOTAL` with last_reset: | ||
|
|
||
| | t | state | last_reset | sum | | ||
| | ---: | -----: | ------------------- | -----: | | ||
| | 0 | 1000 | 2021-08-01T13:30:00 | 0 | | ||
| | 1 | 1010 | 2021-08-01T13:30:00 | 10 | | ||
| | 2 | 1005 | 2021-08-01T13:30:00 | 5 | | ||
| | 3 | 0 | 2021-09-01T13:30:00 | 5 | | ||
| | 4 | 5 | 2021-09-01T13:30:00 | 10 | | ||
|
frenck marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| #### STATE_CLASS_TOTAL_INCREASING | ||
|
emontnemery marked this conversation as resolved.
Outdated
|
||
| If the sensor's state class is `STATE_CLASS_TOTAL_INCREASING`, a decreasing value is | ||
| interpreted as the start of a new meter cycle or the replacement of the meter. It is | ||
|
emontnemery marked this conversation as resolved.
Outdated
|
||
| important that the integration ensures that the value cannot erroneously decrease in | ||
| the case of calculating a value from a sensor with measurement noise present. The | ||
| last_reset attribute will be ignored when compiling statistics. This state class is | ||
| useful for gas meters, electricity meters, water meters etc. The value when the sensor | ||
| reading decreases will be used as zero-point when calculating `sum` statistics. | ||
|
|
||
| Example of `STATE_CLASS_TOTAL_INCREASING`: | ||
|
|
||
| | t | state | sum | | ||
| | ---: | -----: | ---: | | ||
| | 0 | 1000 | 0 | | ||
| | 1 | 1010 | 10 | | ||
| | 2 | 0 | 10 | | ||
| | 3 | 5 | 15 | | ||
|
|
||
| Example of `STATE_CLASS_TOTAL_INCREASING` where the sensor does not reset to 0: | ||
|
|
||
| | t | state | sum | | ||
| | ---: | -----: | ---: | | ||
| | 0 | 1000 | 0 | | ||
| | 1 | 1010 | 10 | | ||
| | 2 | 5 | 10 | | ||
| | 3 | 10 | 15 | | ||
Uh oh!
There was an error while loading. Please reload this page.