Trying to use it, but get the following error in the home assistant log:
Timed out running command: echo apc_sua1000xli_unmute > /config/pipes/host_executor_queue, after: 60s
Traceback (most recent call last):
File “/usr/local/lib/python3.10/asyncio/streams.py”, line 501, in _wait_for_data
await self._waiter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/shell_command/init.py”, line 87, in async_service_handler
stdout_data, stderr_data = await process.communicate()
File “/usr/local/lib/python3.10/asyncio/subprocess.py”, line 195, in communicate
stdin, stdout, stderr = await tasks.gather(stdin, stdout, stderr)
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/shell_command/init.py”, line 86, in async_service_handler
async with async_timeout.timeout(COMMAND_TIMEOUT):
File “/usr/local/lib/python3.10/site-packages/async_timeout/init.py”, line 129, in aexit
self._do_exit(exc_type)
File “/usr/local/lib/python3.10/site-packages/async_timeout/init.py”, line 212, in _do_exit
raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
Looks like you don’t have the monitor script running. If there is nothing reading from the queue, anything trying to write to it will block. FYI you can test the monitor script by running it in the foreground:
It works!!! Were errors in the “monitor_ha_queue.sh”. I had forgotten the closing parentheses at the end of a line in new cases and it prevented the script from running. Thank you!
Thanks for that great suggenstion. I messed around with ugly SSH from container to the host and found this thread. Am I correct to create the named pipe inside the path of the volume mounted in the container?
My usecase is a bit different, but I think this will work with some of your help.
I have a shell_command with an argument.
Script is for updating docker containers including homeassistant itself. It cannot run inside the container, as it would stop itself by stopping the container. I think running this on the host would work. But no idea how to give and process the argument from homeassistant to the monitor-script on the host.
Maybe I would change my shell_command like this and pass the “container_name” to the service call as data.
But how can the monitoring script evaluate the argument and pass it to the script?
A simple idea would be, to define cases like update_container <container_name> for each container in the monitoring script and hardcode the arguments. But this seems not well maintainable.
Maybe you have an better idea how to modify the monitoring script.
I only tweaked your script a bit in my env in order to get it generic and allow any script to be launched without being required to update and relaunch the monitoring pipe script for each new script you’d need and also getting default logging. I just expect any command send to the pipe is matching with a script existing in the HA folder. :
#!/bin/bash
ha_home=/home/user/homeassistant
pipe=$ha_home/pipes/host_executor_queue
while true; do
if read line < $pipe; then
$ha_home/$line.sh >> $ha_home/$line.log 2>&1
fi
done
will trigger the create_zip.sh script within home assistant home folder
btw, the nohup was not immediately recognized on my ubuntu host, just running it with ./$HOME/bin/monitor_ha_queue.sh >&/dev/null & and added @reboot $HOME/bin/monitor_ha_queue.sh into crontab -e
First: on the host, there is no /usr/share/hassio/homeassistant folder
So I assumed I needed to create it.
Then the pipe at /config/pipes/host_executor_queue doesn’t exist, because I put it in the newly created folder.
I’m new to docker, but then I went into my container with this command: docker exec -it homeassistant /bin/bash
and when I try the echo some_script > /config/pipes/host_executor_queue command, it can’t find the pipe. So I decided to make the pipe in my home assistant config folder under a new folder pipes. and direct to it instead
echo some_script > pipes/host_executor_queue
I’ve had no luck thus far. Here is the example of my machine
echo echo_world > pipes/host_executor_queue
which is this in the script.
#!/bin/bash
pipe=/home/user_name/.homeassistant/pipes/host_executor_queue
while true; do
if read line < $pipe; then
case $line in
echo_world)
echo 'hello world' > output.txt
;;
esac
fi
done
I solved it, I was a permission issue with the output.txt location. I installed with Docker, config folder is in /home/username/.homeassistant. I was actually coming back to this message to delete my question. but For anyone else struggling with pipes
I followed these steps:
my configuration.yaml file is in ~/.homeassistant
It seems that for it to work, the folder that the temp.txt was written to must be owned by the admin user, not root
Then I made the .sh file same as above with the addition of the output.txt
#!/bin/bash
pipe=/home/username/.homeassistant/pipes/host_executor_queue
while true; do
if read line < $pipe; then
case $line in
process_check)
ps -e | grep -oc 'process_name' > /home/username/.homeassistant/pipe_output/output.txt
;;
esac
fi
done
For anyone interested, this SSHCommand might be intersting, as it won’t require to open any SSH ports on your router. The SSH command towards your host server (running the HA Docker) will be launched within your local network.
Hi Lee, thanks for sharing this interesting trick.
Does the fact that you are running this infinite “while” loop on your host have any performance problems? Could it be better to add a few seconds pause for example?
(Depending how time cricital your script is ofcourse).