I recently migrated from Hassbian to Hassio because I coudn’t upgrade any more for some reason.
Now everything works accept a bash script that converts images. It uses Imagemagick.
Is there any way to install Imagemagick on HASSIO?
First you have to install SSH server on Hass.IO ADD-ON STORE, and log on with to it with a SSH client like PuTTY. Then execute the command to install Imagemagick: apk add --update imagemagick
With imagemagick installed, then you call in the scripts, commands to create an animated gif with the images from your cameras…
For example:
Create a file on \config\www\camera\cam-gif.sh with the content:
Command to turn the file executable: chmod +x cam-gif.sh
Create in shell_commands: snapshot_cam_gif: '/config/www/camera/cam-gif.sh'
Create in scripts:
Thank you for this info! I was able to SSH into my Hass.io instance and install Imagemaick. I also created the .sh script and ran it from the SSH terminal without issue. A .gif was created and was able to be sent via e-mail (and Google Hangouts!) without issue.
I am struggling however, with the shell_commands part. I have several other shell_commands that are working fine. However when I try to run the ‘convert’ script it fails with a return code of 127. I enabled additional debugging:
I simplified the script to just run ‘convert --help’ and it still fails the same way:
With #!/bin/bash in the script:
2019-05-24 18:41:35 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `/config/cache/test.sh`, return code: 127:
b'/bin/sh: /config/cache/test.sh: not found\n'
Without #!/bin/bash in the script:
2019-05-24 18:27:59 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `/config/cache/test.sh`, return code: 127:
b'/config/cache/test.sh: line 1: convert: not found\n'
Try this, make a wrapper python program, to call the cam-gif.sh script.
Based on the previous example, create a python file: cam-gif.py like this:
import subprocess
import sys
import os
path="/config/www/camera"
os.chdir(path)
print (os.getcwd())
cmd = "/config/scripts/cam-gif.sh"
x = subprocess.check_output(cmd, shell=True)
print(x.decode("utf-8"))
Then the shell_command: snapshot_cam_gif: "python3 /config/scripts/cam-gif.py"
Also, you can change the script to reinstall imagemagick, if it gets uninstalled by a home assistant update, as it happens on HassOS.
#!/bin/bash
file="/usr/bin/convert"
if [ -f "$file" ]
then
echo "Imagemagik $FILE found."
else
echo "Re-Installing Imagemagik:"
apk add --update imagemagick
fi
cd /config/www/camera
rm -rf image-cam.gif
/usr/bin/convert -loop 0 -delay 50 /config/www/camera/image-cam-1.png /config/www/camera/image-cam-2.png /config/www/camera/image-cam-3.png /config/www/camera/image-cam.gif
There is another issue if you are editing this file in windows, and I guess it is your case based on your error: You need to remove the char(13) “Enter key” because Linux only uses char(10) for a new line.
Try this command to clean the file: sed -i 's/\r//' cam-gif.sh