hass-agent / HASS.Agent

Unofficial development project for the HASS.Agent platform.
https://hass-agent.io
MIT License
347 stars 9 forks source link

Bug: Notification images from /media/local #178

Open iankaufmann opened 1 week ago

iankaufmann commented 1 week ago

I have a media source that contains annotated images at: /media/local/BlueIrisAIAnnotated

To be clear, images in notifications work just fine if instead I use: /api/camera_proxy/camera.blueiris_garage

So I am NOT having an issue with receiving notifications, or even receiving notifications containing images.

What doesn't work is using: /media/local/BlueIrisAIAnnotated/garage.20241005_190403565.jpg

Using this media source for notifications works with the companion app on my Android phone, so I know that it isn't an issue with the media source itself.

I can only assume it has something to do with authentication between HASS.Agent and Home Assistant.

Is it possible to get this to work?

2024-10-05 19-43-48

From Developer tools I am executing this:

action: notify.myhassagent
data:
  title: "Person Detected: Garage"
  message: "This is a test"
  data:
    image: "/media/local/BlueIrisAIAnnotated/garage.20241005_190403565.jpg"

I get the notification, but no image, with this log result:

2024-10-05 19:14:44.724 -05:00 [ERR] [STORAGE] Unable to download image: only HTTP & file:// uri's are allowed, got: /media/local/BlueIrisAIAnnotated/garage.20241005_190403565.jpg
2024-10-05 19:14:44.724 -05:00 [ERR] [NOTIFIER] Image download failed, dropping: /media/local/BlueIrisAIAnnotated/garage.20241005_190403565.jpg

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

amadeo-alex commented 1 week ago

Hm, interesting, HASS.Agent will use the token that is provided during setup to access the media, but, it tries to do it only when the URI/URL points towards the domain that you have HA configured. For example:

https://yourha.net/media/local/ozo63ta2atr71.png

Looks like the camera proxy works as intended because it's handled internally by the integration and a time-based token is appended to the URI provided in notification data. I'll need to see how the Android application handles this. One option would be to always try the "https://yourha.net/media/local/something.smth" is user provided URI starting with "/media".

I tried to use full URI "https://yourha.net/media/local/ozo63ta2atr71.png" and the media only one "/media/local/ozo63ta2atr71.png" and unfortunately first one works for HASS.Agent and not for HA and the second one only for HA...

I'll do a dive into Android app to figure things out and then work something out.

iankaufmann commented 1 week ago

Thanks for taking a look!

After digging into it a little bit, I noticed that the HASS.Agent-Integration looks to be trying to deal with these (line 84): https://github.com/hass-agent/HASS.Agent-Integration/blob/main/custom_components/hass_agent/notify.py

It looks like media_source.is_media_source_id(image) must be evaluating to false in my case because the logs just say "/media..." when it seems like if the media source was being found, the integration would be sending over a URL that starts with "https://".

amadeo-alex commented 4 days ago

Did a little bit of digging and it looks like the HA Companion App is the place where the relative URLs/URIs are handled. Basically the app checks if the URL/URI is absolute and if not then additional logic is in place to request the relative resource from HA instance. Guess we'll do the same then.