Add sensor example - weight of pellets for sensor with total amount (#2073)

This commit is contained in:
Jan Bouwhuis 2024-02-05 18:13:23 +01:00 committed by GitHub
parent 08b247f5dd
commit 8e8bf36017
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -106,8 +106,7 @@ Sensors can be configured by the user, this is done by storing `sensor` entity o
## Restoring sensor states ## Restoring sensor states
Sensors which restore the state after restart or reload should not extend `RestoreEntity` because that does not store the `native_value`, but instead the `state` which may have been modifed by the sensor base entity. Sensors which restore the state should extend `RestoreSensor` and call `await self.async_get_last_sensor_data` from `async_added_to_hass` to get access to the stored `native_value` and `native_unit_of_measurement`. Sensors which restore the state after restart or reload should not extend `RestoreEntity` because that does not store the `native_value`, but instead the `state` which may have been modified by the sensor base entity. Sensors which restore the state should extend `RestoreSensor` and call `await self.async_get_last_sensor_data` from `async_added_to_hass` to get access to the stored `native_value` and `native_unit_of_measurement`.
## Long-term Statistics ## Long-term Statistics
@ -127,20 +126,22 @@ either of `energy`, `gas`, or `monetary`
### Entities representing a total amount ### Entities representing a total amount
Entities tracking a total amount have a value that may optionally reset periodically, Entities tracking a total amount have a value that may optionally reset periodically,
like this month's energy consumption, today's energy production or the yearly growth of like this month's energy consumption, today's energy production, the weight of pellets used to heat the house over the last week or the yearly growth of
a stock portfolio. The sensor's value when the first statistics is compiled is used as a stock portfolio. The sensor's value when the first statistics is compiled is used as the initial zero-point.
the initial zero-point.
#### How to choose `state_class` and `last_reset` #### How to choose `state_class` and `last_reset`
It's recommended to use state class `total` without `last_reset` whenever possible, state class `total_increasing` or `total` with `last_reset` should only be used when state class `total` without `last_reset` does not work for the sensor. It's recommended to use state class `total` without `last_reset` whenever possible, state class `total_increasing` or `total` with `last_reset` should only be used when state class `total` without `last_reset` does not work for the sensor.
Examples Examples:
- The sensor's value never resets, e.g. a lifetime total energy consumption or production: state_class `total`, `last_reset` not set or set to `None` - The sensor's value never resets, e.g. a lifetime total energy consumption or production: state_class `total`, `last_reset` not set or set to `None`
- The sensor's value may reset to 0, and its value can only increase: state class `total_increasing`. Examples: energy consumption aligned with a billing cycle, e.g. monthly, an energy meter resetting to 0 every time it's disconnected - The sensor's value may reset to 0, and its value can only increase: state class `total_increasing`. Examples: energy consumption aligned with a billing cycle, e.g. monthly, an energy meter resetting to 0 every time it's disconnected
- The sensor's value may reset to 0, and its value can both increase and decrease: state class `total`, `last_reset` updated when the value resets. Examples: net energy consumption aligned with a billing cycle, e.g. monthly. - The sensor's value may reset to 0, and its value can both increase and decrease: state class `total`, `last_reset` updated when the value resets. Examples: net energy consumption aligned with a billing cycle, e.g. monthly.
- The sensor's state is reset with every state update, for example a sensor updating every minute with the energy consumption during the past minute: state class `total`, `last_reset` updated every state change. - The sensor's state is reset with every state update, for example a sensor updating every minute with the energy consumption during the past minute: state class `total`, `last_reset` updated every state change.
#### State class `total` #### State class `total`
For sensors with state class `total`, the `last_reset` attribute can For sensors with state class `total`, the `last_reset` attribute can
optionally be set to gain manual control of meter cycles. optionally be set to gain manual control of meter cycles.
The sensor's state when it's first added to Home Assistant is used as an initial The sensor's state when it's first added to Home Assistant is used as an initial
@ -182,7 +183,6 @@ of the new meter cycle is not 0, but 0 is used as zero-point:
| 2021-08-01T16:00:00 | 5 | 2021-09-01T16:00:00 | 10 | 15 | 5 | | 2021-08-01T16:00:00 | 5 | 2021-09-01T16:00:00 | 10 | 15 | 5 |
| 2021-08-01T17:00:00 | 10 | 2021-09-01T16:00:00 | 15 | 20 | 5 | | 2021-08-01T17:00:00 | 10 | 2021-09-01T16:00:00 | 15 | 20 | 5 |
#### State class `total_increasing` #### State class `total_increasing`
For sensors with state_class `total_increasing`, a decreasing value is For sensors with state_class `total_increasing`, a decreasing value is