Correctly configure "Recorder", "History" and "LogBook" on Home Assistant

4 minutes of reading

Something that many do not know it's the huge impact that Home Assistant - as it is conceived - it risks having on its own performances as well as on the health of the storage on which it is installed "because of" its default configuration.

Many users of Home Assistant complain, after a long time after adoption, a drop in performance in the consultation of the historical data series collected; others, typically equipped with Raspberry Pi which server to run theHUB, they complain im breaksprovvise of the microSD (its "hard disk") on which the server is installed.

database

The point is how data is stored on the filesystem of the disk drive. Home Assistant, in basic configuration, simply save everything, always, forever. This means that any change of state of any entity is immediately written to the database of theHUB. This means that, for example, the simple activation of the component "Time & Date"Cause the generation of an entity"Sensor"Which in turn causes hundreds, thousands of completely useless records on the database. Imagine having a thermal sensor that sends a reading every minute: in a day the minutes are 1.440, in a month 43.000. And if I have 10 sensors? 430.000 scripts in a month, not bad. And if these sensors also send relative humidity? Then let's go up to 860.000 scripts in a month, and this only for thermal sensors, not considering all the other entities!

But what causes it the break, typically, of an SD? Excessive writing activity, especially in high quality models. What causes a slowdown in database querying? Excessive redundancy and quantity of data (farm, DBA users: it is just a very general statement to understand a concept, do not warm up, yesappLet's say that the theme is a little more complex than that).

Home Assistant it is however well done, which allows, through the appropriate configuration of the component "Recorder“, To significantly limit the bad effects of excessive data storage. The components "History" and "Logbook“, Instead, they are more than anything influenced by the configuration of the aforementioned component, but since they are used for data visualization, they too need to be configured correctly.

What are

"Recorder”Is the component responsible for recording historical data on Home Assistant. Typically save everything in a file called home-assistant_v2.db present in the folder where the configuration files of theHUB and is automatically populated. It is a non-excludable component (it is loaded by default) but which can be configured to indicate what and what not to save at the db - and which prohistorical foundation to preserve.

"History"Activates an entry at the user interface Lovelace UI which allows to visualize, in a graphic way, the progress of the states of the entity present onHUB. If not used, it can be excluded.

"Logbook“Finally, activates an entry at the Lovelace UI interface which allows you to view the sequence of actions performed at theHUB.

Recorder

As we have anticipated, "Recorder" is not an unbeatable component but it is, of course, configurable.
To do this you need to add in configuration the voice:

recorder:

followed by the specificities that you want to put in place.

"Recorder" allows to explain what to exclude and / or what to include, starting from the domains (components / platforms g. "Sensor","Switch"Etc.) to arrive, in a very precise manner, to the entities.

Let's look at an example:

recorder:
  purge_keep_days: 7
  db_url: sqlite:////home/user/.homeassistant/test
  exclude:
    domains:
      - sensor
      - automation
      - script
    entities:
      - light.ingresso
  include:
    entities:
      - sensor.temperatura_sala

The field "purge_keep_days"Serves to keep the database streamlined and performing. Indicate this field to help understand Home Assistant after how many days to get rid of the collected data; in this case, all data older than a week is wiped out.

The second field, "db_url“, Serves to indicate where to save, alternatively, the database, and in what format. In this case, we save the data on a SQLite installed locally. Usually, in the standard configuration of Home Assistant, no need to mention it.

The "exclude" block, it goes without saying, excludes domains and entities. The sensors prothey produce a great deal of data, so we exclude them; perhaps among the many integrated lights the light.ingresso it changes state too often and, not wanting to exclude the entire domain, we make it explicit among the excluded entities.

The block "include"Goes to compensate for the blockage"exclude": Having excluded all the sensors, I preclude myself the possibility of analyzing historical series, perhaps of important sensors: this is why, in the example, we explain the example sensor sensor.temperatura_sala in the entities included.

The strategy is therefore to use, more than anything else, the domains in the block “exclude"And the entities in the block"include": This allows me to immediately mitigate the proproblem of the many entries and the many database accesses, isolating entire domains, but allowing some targeted data censuses for some specific entities.

More information is available on component page.

History

"History"Instead it activates at Lovelace UI an interface for the consultation of the trends of the states of the entities (registered by the component"Recorder") On a time axis:

Home Assistant - Component_history_24h

Obviously there can be entities that, despite "Recorder"Is configured to record them, it doesn't make sense or you don't want to view its history at the rappresentation of "History"

Therefore, exactly in the logic described for "Recorder", It is possible to exclude / explicitly include entire domains and / or entities from rappresentation.

An example:

history:
  exclude:
    domains:
      - automation
      - weblink
      - updater
    entities:
      - sensor.last_boot
      - sensor.date
  include:
    domains:
      - sensor
      - switch
      - media_player

The component can be totally excluded, just remember to delete the item from the configuration "default_config:"(Attention, however: this item activates many other important things, which should be activated individually at this point) and, of course, the possible entry "recorder:"

More information is available on component page.

Logbook

Finally, "Logbook"Serves to define at Lovelace UI a history of actions and been carried out or changed at theHUB:

Home Assistant - Logbook

Also in this case, as for "History", there can be entities that, despite "Recorder"Is configured to record them, it doesn't make sense or you don't want to view its history at the log list.

Therefore, exactly in the logic described for "Recorder", It is possible to exclude / explicitly include entire domains and / or entities from rappresentation.

An example:

logbook:
  exclude:
    entities:
      - sensor.last_boot
      - sensor.date
    domains:
      - sun
      - weblink
  include:
    domains:
      - sensor
      - switch
      - media_player

The component can be totally excluded, just remember to delete the item from the configuration "default_config:"(Attention, however: this item activates many other important things, which should be activated individually at this point) and, of course, the possible entry "recorder:"

More information is available on component page.


Home Assistant Official LogoATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Home Assistant, for any doubt, question, information on the specific merit of these components.

inDomus telegram channel