Docker - Home Assistant Container Setup with MariaDB and InfluxDB 2.x
Here I describe my setup of the Home Assistant container with MariaDB and InfluxDB 2.x.
Dependencies
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
Installation
I run this Docker container on a Ubuntu VM that runs via [[ Proxmox VE ]]. I perform the following on the CLI.
Docker pull command:
docker pull homeassistant/home-assistant
Within my home folder I have created a Docker folder where I create a subfolder for each container:
cd ~
mkdir -p docker/homeassistant
cd docker/homeassistant
Also create a folder where the Home Assistant configuration files can be stored:
mkdir config
I use the Nano text editor to create a shell script:
sudo nano homeassistant_run.sh
With this shell script we are going to create the container.
Copy the following into homeassistant_run.sh
:
docker run -d \
--name=homeassistant \
--hostname=homeassistant \
--privileged \
--network=host \
-v $PWD/config:/config \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/USER/docker/influxdb/data:/influxdb_data \
-e TZ=Europe/Amsterdam \
-e "MYSQL_USER=USR" \
-e "MYSQL_PASSWORD=PASS" \
-e "MYSQL_DATABASE=homeassistant" \
-e "MYSQL_HOST=192.168.x.xx" \
--restart unless-stopped \
homeassistant/home-assistant
If needed replace the following:
-v $PWD/config:/config
Choose the location for the Home Assistant configuration. In this example it is the config map we created
-v /var/run/docker.sock:/var/run/docker.sock
OPTIONAL: I have this volume set up because I’m using the Docker Monitor integration to monitor some Docker containers via HA. So it is not necessary to set up this volume if you do not use this integration.
-v /home/USER/docker/influxdb/data:/influxdb_data
OPTIONAL: Replace/home/USER/docker/influxdb/data
with the full path to the InfluxDB data directory so you can monitor the size of the database with a sensor. This will only work if InfluxDB is on the same machine as your Home Assistant instance. So it is not necessary to set up this volume if you do not use this sensor.
-e TZ=Europe/Amsterdam
Pick the right timezone
-e “MYSQL_USER=USR”
ReplaceUSR
with your MariaDB username
-e “MYSQL_PASSWORD=PASS”
ReplacePASS
with your MariaDB password
-e “MYSQL_DATABASE=homeassistant”
Replacehomeassistant
with the name of your Home Assistant MariaDB database
-e “MYSQL_HOST=192.168.x.xx”
Replace192.168.x.xx
with the IP address of your MariaDB host
Exit Nano (CTRL-X) and save the changes.
Now create the container:
sudo sh homeassistant_run.sh
Check if the container is running properly.
See also my notes about updating containers with Portainer or via the CLI. With Synology’s Docker Application, updating a container is also very easy.
Setup Recorder and History
Now we are going to tell the recorder to use the MariaDB database and for the history we will use InfluxDB. Go to the config directory:
cd config
Create secrets.yaml
:
sudo nano secrets.yaml
Add the MariaDB url and InfluxDB token:
db_url: mysql://USER:[email protected]:3306/homeassistant?charset=utf8mb4
influxdb_token: TOKEN
Replace the following:
db_url: mysql://USER:[email protected]:3306/DATABASE?charset=utf8mb4
Replace with your MariaDB configuration (USER
,PASS
,192.168.x.xx
andDATABASE
)
influxdb_token: TOKEN
Replace with your token. The token can be easily obtained through InfluxDB’s web interface
Exit Nano (CTRL-X) and save the changes.
Edit configuration.yaml
:
sudo nano configuration.yaml
Add the recorder
and history
configuration:
recorder:
purge_keep_days: 30
auto_purge: true
db_url: !secret db_url
exclude:
entities:
- person.myname
history:
influxdb:
api_version: 2
ssl: false
host: 192.168.x.xx
port: 3004
token: !secret influxdb_token
organization: ubuntuvm
bucket: homeassistant
tags:
source: HomeAssistant
tags_attributes:
- friendly_name
default_measurement: units
exclude:
entities:
- person.myname
If needed, replace the following:
purge_keep_days: 30
Replace30
with the number of history days to keep in the recorder database after a purge
person.myname (mentioned twice in the configuration!)
This is an example of an entity that does not need to be saved. Replacemyname
with the Home Assistant user or remove the exclude part
host: 192.168.x.xx
Replace192.168.x.xx
with your InfluxDB host IP address
port: 3004
Replace3004
with your InfluxDB host port
organization: ubuntuvm
Replaceubuntuvm
with your InfluxDB organization name
bucket: homeassistant
Replacehomeassistant
with your InfluxDB bucket name
Exit Nano (CTRL-X) and save the changes.
Optionally you can setup sensors to monitor the database size of MariaDB and InfluxDB2
Using Home Assistant
Now restart the Docker container:
docker restart homeassistant
If everything went well, Home Assistant will now use MariaDB for the recorder and InfluxDB for the history.
Home Assistant can now be accessed via the following URL:
http://<IP DOCKER HOST>:8123/
Optionally you can install Visual Studio Code Server to edit the yaml configuration files via the browser
Optionally you can install Node-RED to assist in setting up automation!
Now make the necessary settings and have fun using Home Assistant.
Read other notes
Tags
Notes mentioning this note
- Docker - MariaDB Container Setup
Here I describe my setup of the Docker MariaDB container.
- Docker - Visual Studio Code Server Setup
Here I describe my setup of the Visual Studio Code Server container.
- Docker - Node-RED Container Setup with Authentication and Home Assistant Nodes
Here I describe my setup of the Node-RED docker container.
- Home Assistant - Setup InfluxDB 2.x Database Size Sensor
Here I describe how to create a sensor for Home Assistant that will monitor the size of the InfluxDB 2.x...
- Home Assistant - Setup MariaDB Database Size Sensor
Here I describe how to create a sensor for Home Assistant that will monitor the size of the MariaDB database...
- Docker - Grafana Container Setup
Here I describe my setup of the Docker Grafana container. With Grafana you can create beautiful dashboards.
- Home Assistant - Monitor Performance of Docker Containers
Within my Home Assistant dashboard I wanted to see information about my Docker containers. For example CPU use, memory use...
- Docker - Budibase Low-code Platform Container Setup
When I heard that my employer was using the no-code platform Betty Blocks my interest was piqued. Although I like...
- Docker - InfluxDB 2.x Container Setup
InfluxDB is a time series database.
- Docker - Smartmeter2mqtt Container Setup with Webserver and Webrequest Output
Smartmeter2mqtt is an application that parses smartmeter data over the network or a P1 cable, I use it in combination...
- MariaDB - NixOS Container Setup
MariaDB is a fork of the MySQL database. I use this database, among other things, to store data from [[Docker...
Comments
No comments found for this note.
Join the discussion for this note on this ticket. Comments appear on this page instantly.