HA restarts very slow

When I restart HA to try a configuration change it seems to take forever (like 10 or more minutes) for it to start back up. is this normal and is there any way to speed it up? I’m on a Raspberry PI, I have appdaemon and bind running on it, but nothing else but HA.

I observed that me too since I have enabled bluetooth_tracker. I will try to disable to see if that its the cause.

I have disabled bluetooth_tracker and I can’t see any difference. On my HA I have to wait for one or two minutes when I hit restart service

Just for good measure. Delete your home-assistant.db, home-assistant.db2 and home-assistant,log before you do another reboot. Then any reboot after your initial one done after deleting these files should be quicker.

The new db, db2 and log files will be freshly created and populated.

Ok, that time it only took about 2 minutes or so, which is great. Before this, I literally went out in the garage with my son, cut 4 4x4 blocks, routed the edges, drilled a 1" wide quarter inch deep hole in each board to display his baseballs, came back in and it was still loading. Two minutes is wonderful. Is there any type of cleanup script that I can run to clean out the database and rotate the logs on a regular basis? And how often would that need to be?

You could create a script that deletes these 3 files. You loose and historic sensor data when deleting these databases though. So use only if you don’t mind doing that.

To purge the database:

  purge_days: 2

Also, you may want to switch to mysql. It took like 10 minutes for me to set it up and restarts and page loads are a good bit faster. Before it would take graphs about 30 seconds to load and now it is almost instant.


Do you have any instructions for doing that?

Install MySQL DB

$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install mysql-server && sudo apt-get install mysql-client
$ sudo apt-get install libmysqlclient-dev
$ sudo apt-get install python-dev python3-dev
$ mysql -uroot -p
$ CREATE USER ‘dbuser’@‘localhost’ IDENTIFIED BY ‘password’;
$ GRANT ALL PRIVILEGES ON dbname.* TO ‘dbuser’@‘localhost’;

Test if user works:
$ mysql -udbuser dbname -p

Switch to HASS env
$ ssh pi@your_raspberry_pi_ip
$ sudo su -s /bin/bash hass
$ source /srv/hass/hass_venv/bin/activate
$ pip3 install --upgrade mysqlclient

Add to configuration.yaml

db_url: mysql://dbuser:password@localhost/dbname


Is the netdisco.service part of HA, or just used by HA. When I try to restart HA from inside the web page, the log keeps showing that netdisco.service is continually scanning every few minutes. does it need to shut down as part of the restart?

@kenshin Could you add this to the documentation: https://home-assistant.io/components/recorder/#mysql ?

Thanks for the post. on mysql. My restarts were good and I had skipped 34 but updated today, wanted to play with speak. My restarts went from 20 seconds to 5 - 10 minutes.

I am running on the HASSbian image. Installed the database and restarts improved

How would I use secrets to obscure the database credentials?

I tried to use
db_url: mysql://!secret dbser:!secret dbpassword @!secret dblhost/!secret dbname

with the entries in the secrets.yaml
dbuser: ha_user
dbpassword: ChangeM3
dbname: ha

but I get

16-12-19 13:28:36 homeassistant.components.recorder: Error during connection setup: (_mysql_exceptions.OperationalError) (2005, “Unknown MySQL server host ‘!secret dbhost’ (110)”)

this works
db_url: mysql://ha_user:ChangeM3@localhost/ha

has anyone used secrets with the db connect string

Put all of the url in one secret: https://github.com/Danielhiversen/home-assistant_config/blob/master/configuration.yaml#L29

cool, thanks!

It’s still not working right. If I call the homeassistant restart service, HA never restarts (or at least it takes a REALLY long time). But if I go out and do a systemctl restart home-assistant@hass, it takes less than a minute to restart.

I can confirm that switching to MySQL using the instructions given by kenshin works. My restarts were really slow (used 0.34.4) and switching to MySQL made it a whole lot faster. After updating to 0.35.2 still as fast as before updating.

Also put purge_days on 2 (so I can keep it clean).

This was after switching to MySql. As I said, it’s nice and fast if restarted from the command prompt. But if restarting from the HA web page, it’s very slow. What information can I provide to help in resolving this?

I too have this problem, i believe it started with an upgrade to 34.5 for me, I’m currently on 35.2 and as of yesterday i was still having the issue. I haven’t tried MySQL yet and unfortunately I’m currently at work but I just wanted to add myself to the list.

Same issue, but perhaps not as patient to wait 10 mins so I don’t know if it will eventually boot, … I’ve been restarting via SSH. Occurs with both default recorder option and postgresql.

Not sure if related but in tracing this failure to boot problem I found if I include - platform: cast in my media players Hass won’t boot at all. Taking it out seems to fix it but half my chromecast players are not showing up any more.