I’ve added a link to my docker compose directory as volume “/compose” as the docker-compose command needs to run in the same directory as the compose.yaml. (I started with the script in my home assistant config directory with a cd line in the script to change to the compose directory, but that didn’t work).
relevant line from my configuration.yaml:
shell_command:
restart_zwave: sh /compose/restart_zwave.sh
I have also tried “./compose/restart_zwave.sh”, both with and without single quotes in configuration.yaml
The error I’m getting in home assistant log when I try and call shell_command.restart_zwave either from a button or developer tools > services:
I think it may be a permissions issue but the script has full a+x permissions so not sure about that? Docker doesn’t install as a user in linux so I can’t add the docker user to a specific group to get this working.
You can’t execute a shell command on the host machine like that. What you are currently doing is executing the shell command inside the docker container.
Just a question, in you docker-compose, home assistant depends on zwave2mqtt, doesn’t this mean that home assistant will be restarted as well, when you restart zwave2mqtt.
I’m trying to do it the other way around, so that zwave2mqtt can be restarted from HA, as sometimes this needs to be done to refresh data.
Also when updating HA to a new version, if I forget to restart zwave2mqtt none of the sensors pass information until zwave2mqtt is also restarted. I want to be able to do this via a button away from home.
depends_on doesn’t restart zwave2mqtt when HA is updated which is what I’m wanting.
There are multiple ways to restart a docker container from Home Assistant.
SSH into host
You could generate SSH keys in the docker container, copy them to your host, and mount them to the docker stack to persist across reboots. Then execute the command on the host through SSH.
HA Dockermon
A docker container that gives you status of the docker containers and you can start/stop/restart containers.
Monitor Docker
A custom component that gives you statistics about docker containers such as CPU, RAM etc. and also let’s you start/stop/restart containers.
Yes, HA can see the files, but still the script will be executed inside the home assistant docker container, which doesn’t have docker compose and can’t restart docker containers outside of the container like this.
I already use Portainer so I don’t think HA Dockermon will add anything to my setup. I expose HA via nginx but I don’t want to expose Portainer / HA Dockermon, I want to restart zwave2mqtt via HA so I’ll look at that custom component, thanks for that
HA Dockermon allows you to restart docker containers from HA through REST calls, you shouldn’t need to expose it to NGINX. But anyway the custom component is my preferred solution