core: Downloader not saving full image before returning control to event loop

The problem

When using the local file upload of an image, the image sometimes only partially uploads despite it being correct and fully formed locally.

Image appears on slack like this: image

However the exact same file (same timestamp) is fully formed and captured properly in the Local Media folder: image

My automation basically downloads a bunch of snapshots from various cameras, then sends them via the Slack notification before finally streaming video from one of them to the chromecast TV.

At first, I thought there needed to be a delay between the download and notification in case it started to send the slack notification file before it completed downloading the file in ‘Downloader’ so I added 2 seconds between each Slack Notify but that didn’t make a difference. I also don’t want to delay the streaming at the end by too much .

What version of Home Assistant Core has the issue?

Home Assistant 2022.11.4 Frontend 20221108.0 - latest

What was the last working version of Home Assistant Core?

Home Assistant 2022.11.4 Frontend 20221108.0 - latest

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Slack

Link to integration documentation on our website

https://www.home-assistant.io/integrations/slack

Diagnostics information

No response

Example YAML snippet

alias: Announce Someone Is At The Door
description: ""
trigger:
  - platform: device
    device_id: xxxxxxx
    domain: nest
    type: camera_person
condition: []
action:
  - service: media_player.volume_set
    target:
      entity_id: media_player.speakers_group
    data:
      volume_level: 0.5
  - service: shell_command.sonoff_tv_on
    data: {}
  - service: media_player.play_media
    data:
      media_content_id: http://xx.xx.xx.xx/someoneisatthedoor.mp3
      media_content_type: audio/mp3
    target:
      entity_id: media_player.speakers_group
  - service: downloader.download_file
    data_template:
      url: >-
        http://xx.xx.xx.xx:88/cgi-bin/CGIProxy.fcgi?usr=xxx&pwd=xxx&cmd=snapPicture2
      filename: frontdoor_snap.jpg
      overwrite: true
  - service: downloader.download_file
    data_template:
      url: >-
        http://xx.xx.xx.xx:88/cgi-bin/CGIProxy.fcgi?usr=xx&pwd=xxx&cmd=snapPicture2
      filename: driveway_snap.jpg
      overwrite: true
  - service: shell_command.snapshot_nest_frontdoor
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: notify.ha_slack_bot
    data:
      message: Front Door (Foscam) Snapshot
      data:
        file:
          path: /media/frontdoor_snap.jpg
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: notify.ha_slack_bot
    data:
      message: Driveway Snapshot
      data:
        file:
          path: /media/driveway_snap.jpg
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: notify.ha_slack_bot
    data:
      message: Front Door (Nest) Snapshot
      data:
        file:
          path: /media/frontdoor_nest_snap.jpg
  - service: camera.play_stream
    target:
      entity_id:
        - camera.front_door
    data:
      media_player: media_player.gallnuaimium
mode: parallel
max: 10

Anything in the logs that might be useful for us?

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (8 by maintainers)

Most upvoted comments

You will need to add those urls to allowlist_external_urls under homeassistant: in configuration.yaml,

https://www.home-assistant.io/docs/configuration/basic/#allowlist_external_urls

Something else just came to mind. Use url: instead of path: for the Slack service call. That way you can skip downloading it locally.

Looks to be something with the downloader integration. By flush, I mean the image will save completely to disk whenever it can. Extend the delay. What about wait for a template? Also have a look here: https://www.home-assistant.io/integrations/folder_watcher

Adding @frenck for his input.

I’m not a Slack user anymore, so, unfortunately, I don’t have the capacity to look at this. Perhaps @tkdrob can look when he gets the chance.