Allow executing long running commands from Home-Assistant and update a defined entity's attributes with:
state: running/success/failure
--
output: 'text'
running: false
exit_code: 0
started_at: '2022-04-29T08:24:51.757144+02:00'
updated_at: '0001-01-01T00:00:00Z'
ended_at: '2022-04-29T21:04:57.142761+02:00'
duration: 10000
output
aggregatesstdout
andstderr
exit_code
is0
if the command is still running- Dates are set to
0001-01-01T00:00:00Z
if not relevant (ended_at
when the command is still running for instance)
- Replace
__RELEASE_URL__
by a validtar.gz
release archive - Add it to your Dockerfile
RUN wget -O /tmp/hass-run-release.tar.gz __RELEASE_URL__.tar.gz && \
mkdir /tmp/hass-run-release && \
tar -xzf /tmp/hass-run-release.tar.gz -C /tmp/hass-run-release && \
cp /tmp/hass-run-release/hass-run /usr/bin && \
chmod +x /usr/bin/hass-run && \
rm /tmp/hass-run-release.tar.gz && \
rm -rf /tmp/hass-run-release
- Download a release
tar.gz
- Copy the
hass-run
binary in your$PATH
- Use
chmod +x
to make it executable
hass-run
starts your command as a daemon and exits immediatly.- A PID file is kept to optionnaly kill the command later on
Add a hass-run.yaml
in .
, $HOME
or /etc
with your host and token as follow:
host: "https://my_host_assistant_url.com"
bearer: "XXXXXX"
Add the flags --host
for your Home-Assistant host and --bearer
for your token.
Run a command with config file:
hass-run run shell.my_entity /tmp/my_command.pid -- my_command
Run a command without config file:
hass-run run --host https://my_hass_url.com --bearer XXXTOKENXXX shell.my_entity /tmp/my_command.pid -- my_command
Run multiple commands:
hass-run run --host https://my_hass_url.com --bearer XXXTOKENXXX shell.my_entity /tmp/my_command.pid -- bash -c "my_command_1 && my_command_2"
Set Home-Assistant configuration:
shell_command:
my_command: hass-run run shell.my_command ./my_command.pid -- bash -c "cd / && ls"
Kill a running command:
hass-run kill --host https://my_hass_url.com --bearer XXXTOKENXXX shell.my_entity /tmp/my_command.pid
hass-run kill shell.my_entity /tmp/my_command.pid
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D