-
-
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
Merged
emontnemery
merged 8 commits into
home-assistant:master
from
emontnemery:state_class_total_blog
Aug 16, 2021
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa29b0b
Add blog post about new sensor state classes
emontnemery 58a66db
Update blog/2021-08-12-state_class_total.md
emontnemery 7be1326
Attempt to fix tables
emontnemery 08e5fdf
Apply suggestions from code review
emontnemery b17c194
Apply suggestions from code review
emontnemery acfde8d
Tweak
emontnemery 07468ee
Update 2021-08-12-state_class_total.md
emontnemery ba155eb
Bump date of the blogpost
emontnemery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| 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 for | ||
| `sum` statistics to be generated. The driver for the changes is to make it easier to | ||
| integrate with devices, like utility meters. | ||
|
|
||
| ### 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. For supported sensors, statistics of | ||
| hourly min, max and average sensor readings are compiled. | ||
| - `STATE_CLASS_TOTAL`, the state represents a total amount that can both increase and | ||
| decrease, e.g. the value of a stock portfolio. When supported, the accumulated growth | ||
| or decline of the sensor's value since it was first added is updated hourly. | ||
| - `STATE_CLASS_TOTAL_INCREASING`, a monotonically increasing total, e.g. an amount of | ||
| consumed gas, water or energy. When supported, the accumulated growth of the sensor's | ||
| value since it was first added is updated hourly. | ||
|
|
||
| #### `STATE_CLASS_MEASUREMENT` | ||
|
|
||
| For sensors with state_class `STATE_CLASS_MEASUREMENT`, it is deprecated to set the | ||
| `last_reset` attribute, and it will be ignored in Home Assistant 2021.10. | ||
|
|
||
| #### `STATE_CLASS_TOTAL` | ||
|
|
||
| For sensors with state_class `STATE_CLASS_TOTAL`, the `last_reset` attribute can | ||
| 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 | ||
| 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` | ||
|
|
||
| For sensors with state_class `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 | ||
| 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 | | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.