Metadata-Version: 2.1
Name: homeassistant-historical-sensor
Version: 0.0.1
Summary: Historical sensors for HomeAssistant
Home-page: https://github.com/ldotlopez/ha-historical-sensor
Author: Luis López
Author-email: luis@cuarentaydos.com
Project-URL: Repository, https://github.com/ldotlopez/ha-historical-sensor/
Project-URL: Bug Tracker, https://github.com/ldotlopez/ha-historical-sensor/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown

#  Historical sensors for Home Assistant ![](icon-64.png)

--

Feed historical data into Home Assistant database. 

HomeAssistant architecture is built around polling (or pushing) data from devices or providers in "real-time".

Some data sources (energy, water or gas providers mainly) can't be polled in real-time or readings are not accurate. However reading historical data, like last month consumption, it's possible and accurate. This module adds support to this.


This module uses the `recoder` component and custom state creation store states "from the past".

Current projects using this module:

- [ideenergy energy monitor](https://github.com/ldotlopez/ha-ideenergy)

Historical sensors can't provide the current state, Home Assistant will show "undefined" state forever, it's OK and intentional. See technical details.

## Technical details

Q. How it's accomplished?.

A. It's a relatively easy answer but needs to be broken into some pieces:
  
  1. A new property for sensors: `historical_states`. This property holds a list of `DatedState`s which are, basically, a `state`+`datetime` tuple, so… the data we want.

  2. A new hook for sensor: `async_update_historical_states`. This method is responsible to update `historical_states` property.  
     **This is the only function that needs to be implemented**.

  3. A new method, implemented by HistoricalSensor class: `async_write_ha_historical_states`. This method handles the details of creating tweaked states in the past and write them into the database using the `recorder` component of Home Assistant core.


## Licenses

  - Logo by Danny Allen.
    [https://publicdomainvectors.org/es/vectoriales-gratuitas/Icono-de-configuraci%C3%B3n-del-reloj/88901.html](https://publicdomainvectors.org/es/vectoriales-gratuitas/Icono-de-configuraci%C3%B3n-del-reloj/88901.html)
