Skip to main content

Historical sensors for HomeAssistant

Project description

Historical sensors for Home Assistant

GitHub Release (latest SemVer including pre-releases) CodeQL Code style: black

Buy Me A Coffee

Feed historical data into Home Assistant database.

HomeAssistant architecture is built around polling (or pushing) data from devices, or data providers, in "real-time". Some data sources (e.g, energy, water or gas providers) 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 to store states "from the past".

Current projects using this module:

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 HistoricalStates which are, basically, a state+datetime (with tzinfo), 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.

Q. Something else?

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

External vs. internal statistics

Importing CSV files

Licenses

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

homeassistant-historical-sensor-1.0.0a0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file homeassistant-historical-sensor-1.0.0a0.tar.gz.

File metadata

File hashes

Hashes for homeassistant-historical-sensor-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 6ca55dab74e7a805095d50046731eadb17cc4532de06d96967ef3297c47cf8aa
MD5 3c3e08999d47e0ae24f63b9fb9d8aad5
BLAKE2b-256 b721f991a4d04b5fb115095b79cd17267e4fc3ccd9cfe291ad379f96e4e19e82

See more details on using hashes here.

File details

Details for the file homeassistant_historical_sensor-1.0.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for homeassistant_historical_sensor-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 c503da362f4f4f5f0364c3c71fd20d476e0dbd357bcb6cffaac7d31da8984f88
MD5 fb4ddcffcf3418ee4ad3dc922b2d3ff1
BLAKE2b-256 266dfb66ff1aac924a5f0eca1b7872e2995d47f0a68b1c7848d72924fb3c922b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page