Home Assistant CLI

Hi everybody,
I’m running ha on a Pi4 with no monitor and keyboard attached to, but using a win10-pc to control it. Recently I learned the ha cli command “ha core stop”. Indeed ha stoppt, but I was not able to restart it again, because there was no opportunity to say “ha core start”. Finally I disconnected the Pi4 from the power supply and switched it on again. Fortunately nothing happend - thanks to the “stopped ha” I think.
This is my question: Are these cli commands only useful in case you have a monitor/keyboard attached to your host directly?

The ha commands have many useful functions like testing you network, DNS or core installation, but there are some that might require some extras like physical access to restart after a shutdown.
I have never used that many of the ha commands myself, but my guess is that ha core stop is the shutdown of the ha core from the inside.
Once that is run then you have to start it from the outside with the command in Alpine Linux or however your HA is installed.
A hard reboot should get things back up and running though, since it’s a stop command and not a disable.

Yes, that’s what I guessed. Thank you for clarification and confirmation.

I’m confused, how are you accessing the HA CLI that you lose access after ha core stop? ha core stop shuts down only one thing: the docker container that core is running in. That container does not run the ssh service, you cannot ssh into it. You can get into that container via the Docker CLI but if you do you’ll find the HA CLI isn’t available. It’s just an alpine linux container with busybox.

In an HAOS install the only places you can access the HA CLI by default are:

  1. In an addon (like the ssh addon for example)
  2. On the host. Either by setting up host ssh access or connecting a keyboard and monitor

Neither of those stops running when you do ha core stop. Addons each run in their own container and they don’t care what’s going on in the core container. And the host obviously keeps running regardless of what the core container is doing.

When I do ha core stop it’s usually to muck with something in .storage. When I’m done I do ha core start. SSH never disconnected the whole time, everything works fine. If you are seeing something different then please clarify how you are accessing the HA CLI because that doesn’t make sense.

1 Like

I’m accessing it by the addon Terminal & SSH. Or alternatively I use “Developing Tools - Services - Home Assistant Core Integration: Stop”.

I’m not a programmer and still a beginner in home assistant. And I’m not experienced in linux. To be honest, I do not know what a docker is.
Therefore: First of all I would like to apologize for my question. I’m aware that it may reveal my lack of knowledge. And secondly: Thank you very much for your kind answer.

To the background of my question: I experienced that a full backup does not include a backup of the ha database (sqlite). In case my sd-card would crash I would loose all data of my energy dashboard. Meanwhile I installed a new ha on a ssd. I copied the “old” database to the new system. It works fine, I did not loose any data during the process.
I did assume that “to stop” ha would prevent my database to become corrupted. That’s the reason I did some research for “stopping ha”. And I found this command in HA CLI - and experienced the problem which led to my question.

But your answer makes me uncertain whether my thoughts are going in the right direction. Maybe I am totally wrong!?

Ah, so problem is accessing the SSH web interface via HA. When you stop HA docker instance, you also stop the interface.

If you access via SSH using programs like PuTTY or straight up ssh command in Mac/Linux, you will be able to stop/start like Mike posted earlier.

Ah so if you do this then you’re right, there is no good way to start it again. Taking down core takes down the UI. So when you stop HA via the UI you can’t start it again via the UI. You’ll have to use something else to start it again.

This addon does not go down with HA. So if you have installed this addon and enabled ssh then you should not have any issues with ha core stop. While ssh’ed you should be able to do ha core stop and then ha core start after you have finished whatever it is you are trying to do. You should not find yourself disconnected in between as the ssh addon shouldn’t stop running.

That shouldn’t be the case. Where did you hear/read that? The sqlite DB with all your history is a file in /config called. home-assistant_v2.db. In fact to my knowledge there is no way to take a backup of HA without including your DB. That’s actually the main reason I personally use the MariaDB addon since I don’t want my history data in my backups. I’d rather just start fresh then have massive backups personally but I’m sure others feel differently.

So if you are seeing this behavior then perhaps its a bug?

You shouldn’t have to worry about this. I’ve never stopped anything to take backups, even when I was including the DB in my backups. I’ve never found a corruption issue. There’s no harm in what you’re doing other then HA being down for a bit so feel free to stop and start HA during backups. But you shouldn’t have to.

Putty indeed is on my to-do-list.

Concerning the full backup: I faced this problem after having installed ha on a SSD and restoring a full backup of my SD card I used before. In this first try I missed the old data from the energy dashboard. In a second try I copied the old database to the new system and all data were there.

But - perhaps I made another failure during the workflow (in my first try) which I’m not aware of. I will pay attention to this issue again.
The database included in the full backup makes life much more easier for me in the future. I’m very much interested in the historic data of my energy dashboard.
Thank you for your help!