Thanks for the feedback from all!
@nickrout - docker cp
is good to know and I wasn’t aware of that command, but in this instance I want to trigger something from the container. So I wouldn’t be able to execute a docker command within the container.
@febalci - When you say “deal with using docker run commands” - would that mean I wouldn’t be using hassio and I’d deploy the home assistant container myself?
My python script is working under hassio. I’m executing it from an automation by doing: service: shell_command.notify
. My shell_command
in the configuration is this:
notify: python3 /config/scripts/hangout_home_assistant_bot.py --msg "{{ message }}" --token "{{ token }}" --space "{{ space }}"
@flamingm0e - I’ve set up what you suggested (adding a folder in my /config path and mapping that on my webserver. This isn’t ideal in my mind, but it’s likely the best approach. I thought of building a webservice to call from the container to move the image, but that would have some lag I assume. The time from gate opening to text should be short, and I was worried this would slow it down. The symlink very well may have worked, but I figured if the file is actually living in the /config directory, I wanted to be able to define certain access rules within apache.
In case anyone comes across this out of curiosity, here is my python script (with some redaction). It’s not finished yet because I basically took over the script to test sending images and removed the ability to send a text, so I need to add that back. But it works to send an image, which was my goal in this post:
from httplib2 import Http
from json import dumps
import argparse
import urllib.request
import uuid
parser = argparse.ArgumentParser(description='This scrtipt is used tp push messages to a Hangouts Chat room. It is used by Home Assistant to send notifications.')
parser.add_argument("--msg", default="default message content", help="This is used to send the message text. It's ignored when using as an image.")
parser.add_argument("--space", default="<redacted>", help="This is part of the bot URL that specifies which group to use.")
parser.add_argument("--token", default="<redacted>", help="This is part of the bot URL to provide some type of auth.")
args = parser.parse_args()
def main():
file_name = str(uuid.uuid4()) + '.jpeg'
img_url = 'https://<external webserver FQDN>/ha_www_images/' + file_name
print(file_name)
urllib.request.urlretrieve("http://<internal camera IP>/snap.jpeg", "/config/ha_www_images/" + file_name)
url = 'https://chat.googleapis.com/v1/spaces/' + args.space + '/messages?key=<redacted>&token=' + args.token
bot_message = {
'cards' : [
{'sections':[
{'widgets':[
{'image':
{'imageUrl': img_url
,'onClick':
{'openLink':
{'url': img_url
}
}
}
}
]}
]}
]}
message_headers = { 'Content-Type': 'application/json; charset=UTF-8'}
http_obj = Http()
response = http_obj.request(
uri=url,
method='POST',
headers=message_headers,
body=dumps(bot_message),
)
print(response)
if __name__ == '__main__':
main()