Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.sensor.recorder Namespace Reference

Functions

list[tuple[float, State]] _entity_history_to_float_and_state (Iterable[State] entity_history)
 
bool _equivalent_units (set[str|None] units)
 
list[State_get_sensor_states (HomeAssistant hass)
 
set[str|None] _get_units (list[tuple[float, State]] fstates)
 
bool _is_numeric (State state)
 
str|None _last_reset_as_utc_isoformat (Any last_reset_s, str entity_id)
 
tuple[str|None, list[tuple[float, State]]] _normalize_states (HomeAssistant hass, dict[str, tuple[int, StatisticMetaData]] old_metadatas, list[tuple[float, State]] fstates, str entity_id)
 
str _suggest_report_issue (HomeAssistant hass, str entity_id)
 
float _time_weighted_average (list[tuple[float, State]] fstates, datetime.datetime start, datetime.datetime end)
 
str|None _timestamp_to_isoformat_or_none (float|None timestamp)
 
None _update_issues (Callable[[str, str, dict[str, Any]], None] report_issue, list[State] sensor_states, dict[str, tuple[int, StatisticMetaData]] metadatas)
 
dict[str, set[str]] _wanted_statistics (list[State] sensor_states)
 
statistics.PlatformCompiledStatistics compile_statistics (HomeAssistant hass, Session session, datetime.datetime start, datetime.datetime end)
 
dict list_statistic_ids (HomeAssistant hass, list[str]|tuple[str]|None statistic_ids=None, str|None statistic_type=None)
 
bool reset_detected (HomeAssistant hass, str entity_id, float fstate, float|None previous_fstate, State state)
 
None update_statistics_issues (HomeAssistant hass, Session session)
 
dict[str, list[statistics.ValidationIssue]] validate_statistics (HomeAssistant hass)
 
None warn_dip (HomeAssistant hass, str entity_id, State state, float previous_fstate)
 
None warn_negative (HomeAssistant hass, str entity_id, State state)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
dictionary DEFAULT_STATISTICS
 
dictionary EQUIVALENT_UNITS
 
string LINK_DEV_STATISTICS = "https://my.home-assistant.io/redirect/developer_statistics"
 

Detailed Description

Statistics helper for sensor.

Function Documentation

◆ _entity_history_to_float_and_state()

list[tuple[float, State]] homeassistant.components.sensor.recorder._entity_history_to_float_and_state ( Iterable[State entity_history)
private
Return a list of (float, state) tuples for the given entity.

Definition at line 165 of file recorder.py.

◆ _equivalent_units()

bool homeassistant.components.sensor.recorder._equivalent_units ( set[str | None]  units)
private
Return True if the units are equivalent.

Definition at line 154 of file recorder.py.

◆ _get_sensor_states()

list[State] homeassistant.components.sensor.recorder._get_sensor_states ( HomeAssistant  hass)
private
Get the current state of all sensors for which to compile statistics.

Definition at line 83 of file recorder.py.

◆ _get_units()

set[str | None] homeassistant.components.sensor.recorder._get_units ( list[tuple[float, State]]  fstates)
private
Return a set of all units.

Definition at line 149 of file recorder.py.

◆ _is_numeric()

bool homeassistant.components.sensor.recorder._is_numeric ( State  state)
private
Return if the state is numeric.

Definition at line 183 of file recorder.py.

◆ _last_reset_as_utc_isoformat()

str | None homeassistant.components.sensor.recorder._last_reset_as_utc_isoformat ( Any  last_reset_s,
str  entity_id 
)
private
Parse last_reset and convert it to UTC.

Definition at line 382 of file recorder.py.

◆ _normalize_states()

tuple[str | None, list[tuple[float, State]]] homeassistant.components.sensor.recorder._normalize_states ( HomeAssistant  hass,
dict[str, tuple[int, StatisticMetaData]]  old_metadatas,
list[tuple[float, State]]  fstates,
str  entity_id 
)
private
Normalize units.

Definition at line 191 of file recorder.py.

◆ _suggest_report_issue()

str homeassistant.components.sensor.recorder._suggest_report_issue ( HomeAssistant  hass,
str  entity_id 
)
private
Suggest to report an issue.

Definition at line 286 of file recorder.py.

◆ _time_weighted_average()

float homeassistant.components.sensor.recorder._time_weighted_average ( list[tuple[float, State]]  fstates,
datetime.datetime  start,
datetime.datetime   end 
)
private
Calculate a time weighted average.

The average is calculated by weighting the states by duration in seconds between
state changes.
Note: there's no interpolation of values between state changes.

Definition at line 102 of file recorder.py.

◆ _timestamp_to_isoformat_or_none()

str | None homeassistant.components.sensor.recorder._timestamp_to_isoformat_or_none ( float | None  timestamp)
private
Convert a timestamp to ISO format or return None.

Definition at line 398 of file recorder.py.

◆ _update_issues()

None homeassistant.components.sensor.recorder._update_issues ( Callable[[str, str, dict[str, Any]], None]  report_issue,
list[State sensor_states,
dict[str, tuple[int, StatisticMetaData]]  metadatas 
)
private
Update repair issues.

Definition at line 687 of file recorder.py.

◆ _wanted_statistics()

dict[str, set[str]] homeassistant.components.sensor.recorder._wanted_statistics ( list[State sensor_states)
private
Prepare a dict with wanted statistics for entities.

Definition at line 374 of file recorder.py.

◆ compile_statistics()

statistics.PlatformCompiledStatistics homeassistant.components.sensor.recorder.compile_statistics ( HomeAssistant  hass,
Session  session,
datetime.datetime  start,
datetime.datetime  end 
)
Compile statistics for all entities during start-end.

Definition at line 405 of file recorder.py.

◆ list_statistic_ids()

dict homeassistant.components.sensor.recorder.list_statistic_ids ( HomeAssistant  hass,
list[str] | tuple[str] | None   statistic_ids = None,
str | None   statistic_type = None 
)
Return all or filtered statistic_ids and meta data.

Definition at line 646 of file recorder.py.

◆ reset_detected()

bool homeassistant.components.sensor.recorder.reset_detected ( HomeAssistant  hass,
str  entity_id,
float  fstate,
float | None  previous_fstate,
State  state 
)
Test if a total_increasing sensor has been reset.

Definition at line 353 of file recorder.py.

◆ update_statistics_issues()

None homeassistant.components.sensor.recorder.update_statistics_issues ( HomeAssistant  hass,
Session  session 
)
Validate statistics.

Definition at line 741 of file recorder.py.

◆ validate_statistics()

dict[str, list[statistics.ValidationIssue]] homeassistant.components.sensor.recorder.validate_statistics ( HomeAssistant  hass)
Validate statistics.

Definition at line 798 of file recorder.py.

◆ warn_dip()

None homeassistant.components.sensor.recorder.warn_dip ( HomeAssistant  hass,
str  entity_id,
State  state,
float   previous_fstate 
)
Log a warning once if a sensor with state_class_total has a decreasing value.

The log will be suppressed until two dips have been seen to prevent warning due to
rounding issues with databases storing the state as a single precision float, which
was fixed in recorder DB version 20.

Definition at line 295 of file recorder.py.

◆ warn_negative()

None homeassistant.components.sensor.recorder.warn_negative ( HomeAssistant  hass,
str  entity_id,
State  state 
)
Log a warning once if a sensor with state_class_total has a negative value.

Definition at line 332 of file recorder.py.

Variable Documentation

◆ _LOGGER

homeassistant.components.sensor.recorder._LOGGER = logging.getLogger(__name__)
private

Definition at line 53 of file recorder.py.

◆ DEFAULT_STATISTICS

dictionary homeassistant.components.sensor.recorder.DEFAULT_STATISTICS
Initial value:
1 = {
2  SensorStateClass.MEASUREMENT: {"mean", "min", "max"},
3  SensorStateClass.TOTAL: {"sum"},
4  SensorStateClass.TOTAL_INCREASING: {"sum"},
5 }

Definition at line 55 of file recorder.py.

◆ EQUIVALENT_UNITS

dictionary homeassistant.components.sensor.recorder.EQUIVALENT_UNITS
Initial value:
1 = {
2  "BTU/(h×ft²)": UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT,
3  "dBa": UnitOfSoundPressure.WEIGHTED_DECIBEL_A,
4  "RPM": REVOLUTIONS_PER_MINUTE,
5  "ft3": UnitOfVolume.CUBIC_FEET,
6  "m3": UnitOfVolume.CUBIC_METERS,
7  "ft³/m": UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE,
8 }

Definition at line 61 of file recorder.py.

◆ LINK_DEV_STATISTICS

string homeassistant.components.sensor.recorder.LINK_DEV_STATISTICS = "https://my.home-assistant.io/redirect/developer_statistics"

Definition at line 80 of file recorder.py.