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:
- TimescaleDB
- PostGIS
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:
Installation
Precondition
- 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.
Manual installation:
- Put the
ltss
folder fromcustom_components
folder in this repo to a folder namedcustom_components
in your HA config folder
Automatic installation:
- Just install ltss as an integration via HACS
configuration.yaml
- Add a section to your HA configuration.yaml:
ltss:
db_url: postgresql://USER:PASSWORD@HOST_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?
Configuration
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.
Details
The states are stored in a single hypertable with the following layout:
Column name: | id | time | entity_id | state | attributes | location |
---|---|---|---|---|---|---|
Type: | bigint | timestamp with timezone | string | string | JSONB | POINT(4326) |
Primary key: | x | x | ||||
Index: | x | x | x | x | x |
Chunk size of the hypertable is set to 1 month.
The location column is only populated for those states where latitude
and longitude
is part of the state attributes.
Credits
Big thanks to the authors of the recorder component for Home Assistant for a great starting point code-wise!