ivanmihov / homeassistant-ntfy.sh

Home Assistant integration for ntfy.sh
GNU General Public License v3.0
55 stars 11 forks source link

local image doesn't appear to work #1

Open zombiehoffa opened 1 year ago

zombiehoffa commented 1 year ago

Can you provide an example of how to use this with local images? I'm trying to replace telegram for notification but I have a subset of notifications that include pictures from my security cameras and I kind of need those to function to consider getting rid of telegram. I have had no luck getting it to work on my own.

ivanmihov commented 1 year ago

I usually do it this way:

Take snapshot from the camera:

service: camera.snapshot
data:
  filename: "/config/www/tmp/snapshots/FILE_NAME.jpg"
target:
  entity_id: camera.CAMERA_ENTITY

Send the notification:

service: notify.ivan
data:
  title: Notification Title
  message: Notification Message
  data:
    image: "https://HOMEASSISTANT_URL/local/tmp/snapshots/FILE_NAME.jpg"

Note that you might want to have something random for the FILE_NAME if your Home Assistant is publicly exposed and delete the image at some point.

zombiehoffa commented 1 year ago

I ended up using the shell command tp do this with curl so i could direct atta h the image (my homeassistant is not web exposed so url will break on any ntfy endpoint not on my home network or overlay vpn network sadly.) I can poat an example tomorrow if wanted.

dimatx commented 1 year ago

I'm also trying to accomplish the same... Trying it with the payload below, but have the same issue as my Frigate is not exposed to the internet. Furthermore, it seems like ntfy PWA app will only render an image that's directly attached. (While the push notification seems to show it as it should... ) Have you found a working solution to get the image to show in the web app / PWA, @zombiehoffa? @ivanmihov - do you think it would make sense for your integration to fetch the image, and directly include it in the message?

service: notify.ntfy
data:
  title: " Garage bay 1"
  data:
    priority: 2
    topic: security
    image: https://frigate.internalhost.com/api/garage/latest.jpg
    tags:
      - information_source
  message: is closed 

image image

zombiehoffa commented 1 year ago

@dimatx This is what I ended up doing: shell_command: ntfy_put: > curl --header 'Priority: {{ priority }}' --header 'Filename: {{ filename }}' --header 'Authorization: Bearer tk_secretkeyhere' --upload-file '{{ file }}' --url 'https://ntfy.sh/{{ topic }}'

You call the above in your automations with something like this (choose edit in yaml): service: shell_command.ntfy_put alias: Sendit data: priority: 3 topic: homeassistant filename: yourpicture.jpg file: /path/to/yourpicture.jpg

dimatx commented 1 year ago

Thanks @zombiehoffa. Unfortunately my image that I need to attach isn't local to HA, so I'm hoping this PR will address things for me: https://github.com/binwiederhier/ntfy/pull/820

titof2375 commented 1 year ago

hello, I have the same problem listed above, my images are in the media folder now, /media/local/camera/snapshot_CamDevant.jpg image1 and when I type the address in my search bar

dinki commented 1 year ago

Here to join in the chorus of requests to allow for including images stored local. My use case is the same: take snapshot from doorbell camera when doorbell button is pressed and then send that snapshot file

vampywiz17 commented 5 days ago

@dimatx This is what I ended up doing: shell_command: ntfy_put: > curl --header 'Priority: {{ priority }}' --header 'Filename: {{ filename }}' --header 'Authorization: Bearer tk_secretkeyhere' --upload-file '{{ file }}' --url 'https://ntfy.sh/{{ topic }}'

You call the above in your automations with something like this (choose edit in yaml): service: shell_command.ntfy_put alias: Sendit data: priority: 3 topic: homeassistant filename: yourpicture.jpg file: /path/to/yourpicture.jpg

It really useful, and basicily replace these integration!

Now i use these:

Create a shell script:

#!/bin/bash

file_url="$1"
priority="$2"
filename="$3"
topic="$4"

curl -s "$file_url" | curl -s \
  --header "Priority: $priority" \
  --header "Filename: $filename" \
  --header "Authorization: Bearer tk_xxxxxxxxxxxxxxxxxxxxx" \
  --upload-file - \
  --url "https://servername.duckdns.org/$topic"

and after add it to configuration.yml

shell_command:
  ntfy_put: bash /config/shell_scripts/notify_ntfy.sh '{{ file_url }}' '{{ priority }}' '{{ filename }}' '{{ topic }}'

Finally, i invite it:

action: shell_command.ntfy_put
data:
  priority: 3
  topic: topicname
  filename: Csengettek!
  file_url: http://username:password@192.168.31.130/Streaming/channels/1/picture

Edit:

Optimalize the code a bit, to handle secret data correctly:

#!/bin/bash

ntfy_key=$(grep 'ntfy_key:' /config/secrets.yaml | awk '{print $2}')
file_url="$1"
message_title="$2"
priority="$3"
filename="$4"
topic="$5"

curl -s "$file_url" | curl -s \
  --header "Title: $message_title" \
  --header "Priority: $priority" \
  --header "Filename: $filename" \
  --header "Authorization: Bearer $ntfy_key" \
  --upload-file - \
  --url "https://servername.duckdns.org/$topic"