Pushing Images with Pushover 3.0

Hmm, that’s strange - last I saw, it was rejected due to the desire to continue using the third-party library instead of the APIs directly. I actually had a PR for the documentation too, but then had to roll that back.

Here’s an example in case it is actually live though:

- alias: Garage motion detected
  trigger:
    platform: state
    entity_id: sensor.garage_motion
    from: '0'
    to: '1'
  condition:
    - condition: state
      entity_id: input_boolean.security_armed
      state: 'on'
  action:
    - service: notify.pushover
      data_template:
        message: "Security system: Motion in Garage!"
      data:
        title: "Home Assistant"
        data:
          priority: 1
          sound: siren
          file:
            url: !secret cam_garage_latest_url
            auth: basic
            username: !secret cam_garage_username
            password: !secret cam_garage_password
1 Like

did your code every get rolled in home assistant to support images?

looks like the 3rd party library supports it, I’m no developer though
https://pushover.net/faq#library-python

Alternatively, the 3rd party pushnotify Python package written by Jeffrey Goettsch, the pushover Python 3 package written by Wyatt Johnson, and the Chump Python package written by Karan Lyons are available.

To send an image attachment, the 3rd party Requests library can be used. For example, to send the file “your_image.jpg”:

import requests
r = requests.post(“https://api.pushover.net/1/messages.json”, data = {
“token”: “APP_TOKEN”,
“user”: “USER_KEY”,
“message”: “hello world”
},
files = {
“attachment”: (“image.jpg”, open(“your_image.jpg”, “rb”), “image/jpeg”)
})
print(r.text)

I just updated my code here: 6f354e6. I’ll be testing it and creating a new PR soon, but in the meantime, feel free to grab this code for now.

2 Likes

How can I modify original pushover.py?

It’s best not to edit the original files. I used the custom_components method described here; https://community.home-assistant.io/t/editing-component-files-in-hassio/24273
So I took the new pushover.py from @brkr19 and placed it in config/custom_components/notify
Works like a charm (reboot ofcourse) really happy, thanks a lot @brkr19

2 Likes

Using this a custom component worked really well. Thanks for the tip

I’m trying to have my camera image sent to Pushover but still, with the custom component, have issues.
Could you share you automation lines so I can compare?
thanks

nobody can help?

mine looks like this:
- id: Bezoeker
alias: Bezoeker
initial_state: True
trigger:
platform: state
entity_id: binary_sensor.voordeur_line_crossing_2
to: ‘on’
action:
- service: notify.pushover_ha
data_template:
message: ‘(voordeur) Bezoeker om {{now().strftime("%H:%M %d-%m-%Y")}}’
data:
title: “Home Assistant”
data:
priority: 0
sound: intermission
file:
url: http://ipaddress:port/ISAPI/Streaming/channels/1/picture?
authentication: digest
username: !secret hikvision_user
password: !secret hikvision_password

Thank you so much, it works now.
Although, it shows the live feed which, in my opinion, isn’t really what I need since ideally, I would need to image from when the even occurred…
Any way to push only the image of the event from when it occurred?

Actually, it worked the first time then without changing anything, got this error for the URL image:
Received status=401 while trying to download http://192.168.1.149:65006/ISAPI/Streaming/channels/1/picture?

That’s a issue I am running into also (since 5 days or so). I found that when I use basic authentication on my camera it works again (Hikvision).

I am also building a setup at the office and we use Axis camera’s there. The problem is accessing the URL works when using basic authentication (set via the axis manager) but then HA can’t find the camera’s. I still did not solve that (spent almost the whole day yesterday on his)

I tried using basic (changed ion NVR and in automation); same issue…

I worked around it, this code works for me (just the action piece)

action:
- service: camera.snapshot
  data:
    entity_id: camera.voordeur
    filename: 'tmp/voordeur.jpg'
- service: notify.pushover_ha
  data_template:
    message: 'Bezoeker om {{now().strftime("%H:%M %d-%m-%Y")}}'
  data:
    title: "Whatever"
    data:
      priority: 0
      sound: intermission
      file:
        path: 'tmp/voordeur.jpg'

this seems perfect, although, I’m getting
Can't write tmp/ext_cote_maison.jpg, no access to path!

after some reading, I finally got it to work :slightly_smiling_face:

I had to whitelist tmp:

  whitelist_external_dirs:
    - /tmp  

and reboot the NUC completely

my automation:

- id: '1522174458955'
  alias: Notification "line crossing" entrée
  trigger:
  - entity_id: binary_sensor.sfnetwork_nvr_line_crossing_4
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: camera.ext_entree_maison
      filename: /tmp/snapshot_ext_entree_maison.jpg
    service: camera.snapshot
  - data:
      data:
        file:
          path: /tmp/snapshot_ext_entree_maison.jpg
        priority: 0
        sound: incoming
      message: Intrusion à l'entrée de la maison!!!
      title: Home Assistant - Cam entrée maison
    service: notify.pushover

FINALLY!!!
thanks so much for your help!!! hope it help other users.

I wonder if you guys could help, I can’t get past the folder whitelist issue. I’m using Homeassitant on Windows and it downloads a JPG image from my netatmo camera to c:\homeassistant\downloads\last.jpg this works fine but when it comes to sending the JPG via Pushover I get the error ‘downloads\last.jpg is not secure to load data from!’ even though the folder is whitelisted. I’m sure it’s probably related to the path syntax but I’ve tried forward and backward slashes and even tried with the JPG being located in the config folder but still no luck

Automations.yaml:

  • id: ‘1535480687632’
    alias: Monitor for animals in back garden
    trigger:
    • entity_id: binary_sensor.back_outdoor_animal
      from: ‘off’
      platform: state
      to: ‘on’
      action:
    • data:
      filename: last.jpg
      overwrite: true
      url: http://XXXX/live/snapshot_720.jpg
      service: downloader.download_file
    • data:
      data:
      file:
      path: downloads\last.jpg
      priority: -1
      sound: alien
      message: Animals in back garden
      title: Back garden monitoring
      service: notify.notify
      hide_entity: false
      initial_state: ‘off’

Configuration.yaml:

  whitelist_external_dirs:
    - downloads

Eventually managed to fix myself by using the full path rather than a relative one:

Automation:

  • id: ‘1535480687632’
    alias: Monitor for animals in back garden
    trigger:
    • entity_id: binary_sensor.back_outdoor_animal
      from: ‘off’
      platform: state
      to: ‘on’
      action:
    • data:
      filename: last.jpg
      overwrite: true
      url: http://XXXX/live/snapshot_720.jpg
      service: downloader.download_file
    • data:
      data:
      file:
      path: c:/Homeassistant/downloads/last.jpg
      priority: -1
      sound: alien
      message: Animals in back garden
      title: Back garden monitoring
      service: notify.notify
      hide_entity: false
      initial_state: ‘off’

Config:

  whitelist_external_dirs:
    - c:\Homeassistant\downloads

Hi folks,
still doesn’t work for me. Beginner here, so there might something basic be missing. What I have done:

  • set up pushover -> works!
  • loaded pushover.py from @brkr19 (getting You are using a custom component for notify.pushover which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant. )
  • loading camera images into hass.io via still_image_url generally works

I just can’t get the code to run. Here it is:

- alias: alarm_trigger
  trigger:
  - platform: state
    entity_id: 'binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor'
    to: 'on'
  action:
  - service: notify.pushover_notifier
    data:
      message: "motion detected"
      title: "Alarm!"
      data:
        file:
          url: http://USER:PASSWORD@IP:80/image/jpeg.cgi

Leaving out the last three lines works like charm. Adding these lines however gives me the following error message:
attachment: invalid message parameter
using attachment instead of file brings:
Could not send notification: send_message() got multiple values for keyword argument 'attachment'

Since working with the url directly, I am not facing this “whitelist issue”, right? If the jpg is downloaded in the python script, I can’t see where and therefore can’t add anything to the whitelist.
Can anyone please point me in the right direction? Thanks!

EDIT: I just found out that deleting the last three lines doesn’t work with @brkr19 's script, getting the same attachment: invalid message parameter error as before …

It looks like your spacing is off try

- alias: alarm_trigger
  trigger:
    - platform: state
      entity_id: 'binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor'
      to: 'on'
  action:
    - service: notify.pushover_notifier
      data:
        message: "motion detected"
        title: "Alarm!"
        data:
          file:
            url: http://USER:PASSWORD@IP:80/image/jpeg.cgi

Thanks for the hint. Spacing already drives me nuts in yaml files.
It doesn’t change anything though and all my automations use the spacing as I posted above and work well.