alias: "Purge noisy power sensors"
trigger:
- platform: time
at: "04:15:00"
action:
- service: recorder.purge_entities
data:
keep_days: 5
target:
entity_id: sensor.power_sensor_0
mode: single
Service disable
Call the service recorder.disable
to stop saving events and states to the database.
Service enable
Call the service recorder.enable
to start again saving events and states to the database. This is the opposite of recorder.disable
.
Custom database engines
SQLite is the most tested, and newer version of Home Assistant are highly optimized to perform well when using SQLite.
When choosing another option, you should be comfortable in the role of the database administrator, including making backups of the external database.
Here are examples to use with the db_url
configuration option.
Some installations of MariaDB/MySQL may require an ALTERNATE_PORT (3rd-party hosting providers or parallel installations) to be added to the SERVER_IP, e.g., mysql://user:
[email protected]_IP:ALTERNATE_PORT/DB_NAME?charset=utf8mb4
.
When using a MariaDB or MySQL server, adding +pymysql
to the URL will use the pure Python MySQL library, which is slower but may be required if the C MySQL library is not available.
When using the official Docker image, the C MySQL library will always be available. pymysql
is most commonly used with venv
where the C MySQL library is not installed.
Unix Socket connections always bring performance advantages over TCP, if the database is on the same host as the recorder
instance (i.e., localhost
).
If you want to use Unix Sockets for PostgreSQL you need to modify the pg_hba.conf
. See PostgreSQL
Database startup
If you are running a database server instance on the same server as Home Assistant then you must ensure that this service starts before Home Assistant. For a Linux instance running Systemd (Raspberry Pi, Debian, Ubuntu and others) you should edit the service file.
To help facilitate this, db_max_retry and db_retry_wait variables have been added to ensure the recorder retries the connection to your database enough times, for your database to start up.