How to use MariaDB on Home Assistant OS

Set MariaDB on Home Assistant to improve speed

Home Assistant OS domotic system can register all the events that occur through the integrated configurations we develop. The default database is SQlite, a low resource consumption option for basic uses. It doesn’t include too many sensors or different actuators. However, if you want a more complex, fast and capable database you can install MariaDB.

Even though the Home Assistant OS database is SQlite, installing MariaDB is not that hard. The default database gets slower when you introduce more sensors. The installation of MariaDB lets you check older registers and improve the general speed of the system. The best method is to install MariaDB after installing Home Assistant OS. That way you won’t lose any data from your integrations or automatizations.

The SQlite records versus the MariaDB

Is MariDB on Home Assistant worthy?

Installing the Home Assistant OS in a SSD unit is very useful. You will get a better reading and writing speed in comparison with hard drive disks. When we set several sensors, it’s very important to keep a good speed for our domotic devices. A faster Home Assistant OS means a better user experience.

On the long term, using MariaDB is a good call. If you use Home Assistant with a few sensors and basic stuff, you won’t have any issues. But little by little you add new integrations and sensors and the registers on the default database are not that good. MariaDB is a great alternative to set your different configurations according to your needs. If you installa MariaDB from the beginning you won’t have to risk any data lose.

Download and install MariaDB

In the Home Assistant OS installation there is a section called Add-ons. There you can install different official, community and third party add-ons. From the Settings menu you can access the section where you can install MariaDB for Home Assistant.

First you need to install an add-on called File Editor. It allows you to navigate through the configuration files of the system in a faster and simpler way. Then you can edit directly from the web the main settings of Home Assistant OS. On the add-ons store you will find MariaDB as an official add-on, click on it.

Install it by pressing the install button and follow the steps on the Documents file. Inside the file you will find the mandatory options and the optional configurations available. Finally, you see which parameters you need to manage on the configuration.yaml file.

Once you install the MariaDB database you have to enable the startup and vigilance options. Before pressing Initiate you have to open the Settings tab. In the menu you need to introduce the database name and the user password from Logins. The rest of the setting options you can let as they are.

Now you can click on Initiate the database and wait for it to start working. The system will show you how many CPU and RAM is the add-on consuming. On the Register section you can check if everything is working properly. Finally you have to configure the main settings file to use the new MariaDB database.

Activate MariaDB on Home Assistant

Open the File Editor add-on and the Configuration-yaml file. There you will introduce the information for all the registers to be saved on the database. Just write the following code:

recorder:

db_url: mysql://homeassistant:RedesZoneClaveBuena@core-mariadb/homeassistant?charset=utf8mb4

purge_keep_days: 30

Once you have done this, visit the Developers Tools section and click on Verify settings. The Home Assistant OS will revise the syntax of the coding. You can click on Restart and your Home Assistant OS will use MariaDB as the default database. In the code there’s an option called purge_keep_days: 30. It indicates that all 30 days registers will be erased. Normally the 10 days registers are erased but with this code they can be kept a few more days. In the Recorder section of the official Home Assistant Web you can see the rest of additional settings you can implement.


Do you have any questions or problems related to the topic of the article? We want to help you.

Leave a comment with your problem or question. We read and respond to all comments, although sometimes it may take a while due to the volume we receive. Additionally, if your question inspires the writing of an article, we will notify you by email when we publish it.
*We moderate comments to avoid spam.

Thank you for enrich our community with your participation!

Leave a Comment