Home Assistant container setup with MariaDB and InfluxDB 2.x
Introduction
Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.
Requirements
This Home Assistant installation uses a MariaDB database to store recorder
data and an InfluxDB 2.x bucket to store history
data.
- Make sure you have MariaDB running, for example by installing the Docker container. A database must be created for Home Assistant.
- Make sure you have InfluxDB 2.x running, for example by installing the Docker container. A bucket must be created for Home Assistant.
Setup
-
Create the folders needed by the container
Run the following commands inside your home folder:
-
Create the script needed to run the container
Save the following script as
homeassistant_run.sh
:Instructions:
- Optional Replace
docker
withpodman
if needed - Optional Replace
--net=host
with ports to pass through if you want to expose ports. Here is described how to check if ports are available - Optional Replace
$PWD/config
with the location of your config if needed. This can be a fileserver mount - Required Replace
<linux-username>
with your own username if you want to monitor the size of the database with a sensor. This will only work if InfluxDB is running on the same machine as your Home Assistant instance. So you can remove the whole line if you do not use this sensor - Required Replace
<mariadb-username>
with your MariaDB username - Required Replace
<mariadb-password>
with your MariaDB password - Required Replace
<database>
with your MariaDB database. For examplehomeassistant
- Required Replace
<mariadb-host-IP-address>
with the IP address of your MariaDB host - Required Replace
Europe/Amsterdam
with your own timezone
- Optional Replace
-
Run the script to create the container
Run the following command:
The image
home-assistant
is automatically pulled and the container is created. -
Recorder and History setup
Now we are going to tell the recorder to use the MariaDB database and for the history we will use InfluxDB. Create
secrets.yaml
and add the MariaDB url and InfluxDB token:Instructions:
- Required Replace
<mariadb-username>
with your MariaDB username - Required Replace
<mariadb-password>
with your MariaDB password - Required Replace
<database>
with your MariaDB database. For examplehomeassistant
- Required Replace
<mariadb-host-IP-address>
with the IP address of your MariaDB host - Required Replace
<influxdb-token>
with the InfluxDB token. The token can be easily obtained through InfluxDB’s web interface
Edit
configuration.yaml
and add therecorder
andhistory
:Instructions:
- Optional Replace
<30>
with the number of history days to keep in the recorder database after a purge - Required Replace
myname
(twice) with your Home Assistant user or remove the exclude part. This is an example of an entity that does not need to be saved to the recorder or history - Required Replace
<influxdb-host-IP-address>
with the IP address of your InfluxDB host - Required Replace
<3004>
with the port of your MariaDB host - Required Replace
<organization>
with your own organization name. I used the name of my virtual machine for example - Required Replace
<bucket>
with your own bucket name. I usedhomeassistant
for example
- Required Replace
-
Check the results
Restart the
homeassistant
container. Run the following command:If needed you can check if the container is running properly. Home Assistant will now use MariaDB for the recorder and InfluxDB for the history.
Now you can use Home Assistant by opening a web browser and going to:
http://localhost:8123
. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.