Long time state storage (LTSS) custom component for Home Assistant
NOTE: Starting 2020-09-13 attributes are stored with type JSONB instead of as a plain string, in addition a GIN index is created on this column by default. At first startup after updating of LTSS, migration of your DB happens automatically. Note that this can take a couple of minutes and HASS will not finish starting (i.e. frontend will not be available) until migration is done.
WARNING: I take no responsibility for any data loss that may happen as a result of this. Please make sure to backup your data before upgrading!
Enabling simple long time state storage (LTSS) for your sensor states. Requires a PostgreSQL instance with the following extensions:
This component is not to be considered as a replacement to the recorder component in Home Assistant but rather as an alternative to the InfluxDB component for more space-efficient long time storage of specific sensor states.
Nice to know:
- Fully SQL compatible -> works with the SQL sensor in Home Assistant
- Compatible with Grafana for visualization of time series:
- Make sure that you PostgreSQL instance is up and running and that you have created a database,
DB_NAME. I recommend the following docker image: https://docs.timescale.com/v1.0/getting-started/installation/docker/installation-docker#postgis-docker to get started quickly and easy.
- Put the
custom_componentsfolder in this repo to a folder named
custom_componentsin your HA config folder
- Just install ltss as an integration via HACS
- Add a section to your HA configuration.yaml:
ltss: db_url: postgresql://USER:[email protected]_ADRESS/DB_NAME include: domains: - sensor entities: - person.john_doe
NOTE : During the initial startup of the component, the extensions will be created on the specified database. This requires superuser priviligies on the PostgreSQL instance. Once the extensions are created, a user without superuser rights can be used! Ref: Can I use Timescale DB as an alternative to Influx DB in Homeassistant for Grafana?
ltss (map)(Required) Enables the recorder integration. Only allowed once. db_url (string)(Required) The URL that points to your database. exclude (map)(Optional) Configure which integrations should be excluded from recordings. domains (list)(Optional) The list of domains to be excluded from recordings. entities (list)(Optional) The list of entity ids to be excluded from recordings. include (map)(Optional) Configure which integrations should be included in recordings. If set, all other entities will not be recorded. domains (list)(Optional) The list of domains to be included in the recordings. entities (list)(Optional) The list of entity ids to be included in the recordings.
The states are stored in a single hypertable with the following layout:
|Type:||bigint||timestamp with timezone||string||string||JSONB||POINT(4326)|
Chunk size of the hypertable is set to 1 month.
The location column is only populated for those states where
longitude is part of the state attributes.
Big thanks to the authors of the recorder component for Home Assistant for a great starting point code-wise!