Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Notification images from /media/local #178

Open
2 of 4 tasks
iankaufmann opened this issue Oct 6, 2024 · 7 comments
Open
2 of 4 tasks

Bug: Notification images from /media/local #178

iankaufmann opened this issue Oct 6, 2024 · 7 comments
Labels
bug Something isn't working fixed in beta fix for this issue/request is already present in one of the beta versions
Milestone

Comments

@iankaufmann
Copy link

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):

  • Windows build (ideally screenshot/info of winver.exe output):
    2024-10-05 19-37-20

  • HASS.Agent version: 2.1.0

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

  • Installed via installer
  • Installed manually
  • Problem occurs in HASS.Agent
  • Problem occurs in Satellite Service
@iankaufmann iankaufmann added the bug Something isn't working label Oct 6, 2024
@amadeo-alex
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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.

@amadeo-alex
Copy link
Collaborator

@iankaufmann If you could, please test this debug release https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.1-beta2-notificationmedia and let me know if it works as expected :)?
I tried to match what the Companion Apps do but I also left what was working before for HASS.Agent which is the full URLs.
From my tests both now work.

@iankaufmann
Copy link
Author

Hmm, no luck.

2024-10-18 16:05:00.589 -05:00 [INF] [MAIN] HASS.Agent version: 2.1.0
2024-10-18 16:05:00.595 -05:00 [INF] [SETTINGS] Config storage path: C:\Users\Me\AppData\Local\HASS.Agent\Client\config
2024-10-18 16:05:00.705 -05:00 [INF] [SETTINGS] Configuration loaded
2024-10-18 16:05:00.710 -05:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2024-10-18 16:05:01.283 -05:00 [INF] [RADIOMGR] Radio management permission granted
2024-10-18 16:05:01.301 -05:00 [INF] [RADIOMGR] Ready
2024-10-18 16:05:03.341 -05:00 [INF] [INTERNALSENSORS] Ready
2024-10-18 16:05:05.941 -05:00 [INF] [VIRTDESKT] Virtual Desktop Manager initialized
2024-10-18 16:05:06.706 -05:00 [INF] [AUDIOMGR] initialized
2024-10-18 16:05:06.732 -05:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 1 entities
2024-10-18 16:05:06.755 -05:00 [INF] [SETTINGS_COMMANDS] Loaded 8 entities
2024-10-18 16:05:07.492 -05:00 [INF] [SETTINGS_SENSORS] Loaded 25 entities
2024-10-18 16:05:07.600 -05:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2024-10-18 16:05:07.643 -05:00 [INF] [LOCALAPI] Disabled
2024-10-18 16:05:07.749 -05:00 [INF] [MQTT] Identifying as device: PC
2024-10-18 16:05:07.760 -05:00 [INF] [MQTT] Connecting ..
2024-10-18 16:05:07.784 -05:00 [INF] [SERVICE] Local install path: C:\Program Files\HASS.Agent Satellite Service\Service\
2024-10-18 16:05:07.864 -05:00 [INF] [MQTT] Connected
2024-10-18 16:05:07.864 -05:00 [INF] [MEDIA] Ready
2024-10-18 16:05:07.893 -05:00 [INF] [NOTIFIER] Ready
2024-10-18 16:05:07.895 -05:00 [INF] [HASS_API] Home Assistant version: 2024.10.2
2024-10-18 16:05:09.108 -05:00 [INF] [HASS_API] System connected with https://mydomain
2024-10-18 16:05:09.775 -05:00 [INF] [MQTT] Initial registration completed
2024-10-18 16:05:34.485 -05:00 [ERR] [STORAGE] Unable to download image: only HTTP & file:// uri's are allowed, got: /media/local/BlueIrisAIAnnotated/backyard.20241015_142409544.jpg
2024-10-18 16:05:34.485 -05:00 [ERR] [NOTIFIER] Image download failed, dropping: /media/local/BlueIrisAIAnnotated/backyard.20241015_142409544.jpg

Getting the same error, like the HTTP link is still not being passed.

I tried running the installer first, and then I tried again with the .zip file and just replaced my config folder.

I was paranoid because the first line of the log file is "HASS.Agent version: 2.1.0" (not 2.1.1-beta2-notificationmedia), but not sure what I could be doing wrong at this point...

I ended up doing a complete uninstall, reboot, and fresh install and it still doesn't seem to be working.

Is there an update required on the Home Assistant integration side as well?

@amadeo-alex
Copy link
Collaborator

amadeo-alex commented Oct 19, 2024

Now that's embarrassing...
I did the changes locally but didn't push them to GitHub before building it via GitHub Actions...my apologies for that since you've wasted some time for the reinstalls etc.
Lesson learned, don't do commits when tired.

This is the correct one - https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.1-beta2-notificationmedia2 (the versions will still say 2.1.0)

@iankaufmann
Copy link
Author

Haha no worries! Glad it was that and not something deeper that was causing my specific case to not work. It's simple enough to reinstall since we can just back up the config folder, and that works well!

Ran the updated installer and can confirm that now the /media notifications work great!

I had developed a workaround by dumping the annotated images into a subdir of BlueIris UI3 so that there would be a webserver on the LAN that could serve them. I don't have that open to the WAN but it worked for my PC running HASS.Agent, I just needed to send two different notifications in my HA automation, one for non-HASS.Agent devices and one for mobile app devices.

It worked but this will let me streamline it back into one notification group.

Thanks for your work on this!

amadeo-alex added a commit that referenced this issue Oct 19, 2024
This PR adds logic required to properly show notification images passed with relative URL - "/media/pics/image.png".
Thanks to @iankaufmann for reporting! #178
@amadeo-alex amadeo-alex added the fixed in beta fix for this issue/request is already present in one of the beta versions label Oct 26, 2024
@amadeo-alex amadeo-alex added this to the 2.1.1 milestone Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in beta fix for this issue/request is already present in one of the beta versions
Projects
None yet
Development

No branches or pull requests

2 participants