Can't open image from notification on Android

I’ll start by saying I’m fairly sure I’m affected by the issue described in this feature request and the bugs linked to it (I am on Android) so really I want to check if that’s right and then get advice on what the best workaround is.

Config.yaml, my automation and the script the automation calls are all below.

Problem
Attempting to open an image from a notification generates a 401 Unauthorized response. This applies whether using the recommended media source integration or linking directly to the image.

What have I tried?

  • Reading the docs, reading posts here, and on GitHub, and on Reddit
  • Using the media source integration to link to the image
  • Adding the image location to allowlist_external_dirs and linking to it directly

I’m particularly confused about the allowlist_external_dirs option not working, I thought that would be the workaround so any guidance on what I’ve got wrong there would be great.

Config.yaml (to show my various attempts to make the image folder externally accessible)


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include templates.yaml


zha:
  enable_quirks: True
  custom_quirks_path: custom_zha_quirks
  
homeassistant:
  whitelist_external_dirs:
    - '/media/security/driveway/'
    - '/media/security/driveway'
    - /media/security/driveway/
    - /media/security/driveway
    
  allowlist_external_dirs:
    - '/media/security/driveway/'
    - '/media/security/driveway'
    - /media/security/driveway/
    - /media/security/driveway

The automation which triggers when my camera detects a person. It was using path.value for all the link locations but I hardcoded some of them while trying to debug it.

I’ve got continue_on_error: true set because the camera can be a little slow so the 10 second timeout is occasionally hit.

alias: Person notification
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.driveway_person_detection
    from: "off"
    to: "on"
condition: []
action:
  - alias: Get an image
    continue_on_error: true
    action: script.driveway_snapshot
    metadata: {}
    data: {}
    response_variable: path
  - action: notify.mobile_app_matt_s_s22
    metadata: {}
    data:
      message: "{{path.value}}"
      data:
        image: /media/local/security/driveway/snapshot.jpeg
        clickAction: http://homeassistant:8123/media/local/security/driveway/snapshot.jpeg
        actions:
          - action: URI
            title: Open
            uri: /media/local/security/driveway/snapshot.jpeg
mode: single

And finally the snapshot script.

alias: Driveway snapshot
variables:
  path: |
    {{ { 'value': "/media/security/driveway/snapshot.jpeg" } }}
sequence:
  - alias: Get image
    continue_on_error: true
    action: camera.snapshot
    metadata: {}
    data:
      filename: "{{path.value}}"
    target:
      device_id: [redacted]
  - stop: Returning file path
    response_variable: path
description: Take a picture from the driveway camera
icon: mdi:cctv

Any suggestions appreciated!

This is annoying and isn’t just a problem for the companion app. This is the work around that I have. Create a dashboard view for each camera. Single card page, you can select sub view so that it is only visible by direct address.

Setting it as a subview also hides the side menu and the only place you can navigate to is back. Create a camera entity with local file and use that with a picture glance card. Set clickAction to the path of the sub view.

this needs to be a relative URL like the others or authentication wont not be added

Thanks @Mikefila - that’s a pretty big compromise but I’ll give it a go.

@dshokouhi thanks for the response but I think you misunderstood my point: none of those methods work, they all produce 401 as a response.

I just tried it again to see if something changed, I still get 401 as well. The image comes through in the text body but I can’t open it.

action: notify.mobile_app_pixel_7
data:
  message: The garage door has been open for 10 minutes.
  title: Your Garage Door Friend
  data:
    image: /media/local/test.jpg
    clickAction: http://192.168.0.101:8123/media/local/test.jpg

ok then you are impacted by https://github.com/home-assistant/android/issues/1672 and the best workaround is to use the www folder

Thanks again both, I’m marking the www folder workaround as the solution as it’s good enough for me. Yes it’s open to the local network but the only external access to my HA instance is via a VPN so I’m happy that the security risk is minimal so long as I trust the devices on the same subnet.

For future reference…

I’m writing the file to:

./www/security/driveway/snapshot.jpeg

And the relevant parts of the notification call are:

image: /local/security/driveway/snapshot.jpeg
clickAction: http://homeassistant:8123/local/security/driveway/snapshot.jpeg
      

I also had to allow access for the file to be written, in config.yaml:

homeassistant:
  allowlist_external_dirs:
   - "./www/security/driveway/"