If you have used Home Assistant it is very likely that you also glanced at the "History"-function of the GUI. I really like this view, because it shows you relevant data in a simple way and it is very easy to find basic connections between elements. So I would like to use this feature also in the future. So you might ask yourself "Where is the problem?". If we have a look at the documentation of Home Assistant you will notice that the default database is a sqlite3-database.
In my eyes this implementation does not fit the real needs because:
So do not get me wrong! I really love sqlite3, but I think it is not the right way to store data for an infinite time.
The solution is very simple: You just have to activate the "Recorder"-Component. The one and only line you need to add to your configuration is the connectionstring. This string has to be added for the key "db_url". You can choose between different databases like MySQL and PostgreSQL, but there is also the option to use another sqlite3 file! To be able to use one of the first two options you need to install their client-implementations. But watch out to activate the virtualenv (if you used it during the installation process of Home Assistant) before you start installing the dependencies.
You can work with includes or excludes if you want to limit the data which will be stored in the database. It is very important that you use this options within the recorder. If you type it under the history or the logbook entry, everything will be recorded as it has been. The only effect is that limited data will be displayed.
Another possibility is to purge the data. This means that the datasets get a lifetime. If they are older than a specified time range they will be deleted. You can also use this function with the default database. You only need to modify the recoder-section your configuration file like here: (Data will be stored for only one week.)
recorder:
purge_days: 7