HASS.Agent: Windows client to receive notifications, use commands, sensors, quick actions and more!

Anotehr question that appeared when I installed the beta. I had originally installed it in my sons computers with my admin account. but then I decided to erasse the installation and reinstall with my sons non-admin accounts. I did provide the admin pass to open up the ports, but now neither notifications or the media player work. I assume it is something with the admin rights over the port to receive notifications or media commands, but even if I have used the netsh command posted in the thread I still get no notifications or can play media from HA in the windows computers. Is there any log where I can check why it is not displaying notifs or playing? I assume those things do not go over MQTT but rather directly to the TCP port, right?

thanks!

Could you please open an elevated command prompt, and enter these commands:

netsh http delete urlacl http://+:5115/
netsh http add urlacl url=http://+:5115/ user=Everyone

Then restart HASS.Agent, and see if that fixes it :slight_smile:

You’re right about TCP. You can see the logs by going to configurationloggingopen logs folder, then open the latest log. If you’re not getting enough info, check enable extended logging and restart HASS.Agent for it to take effect. Remember to turn that off when you’re done!

1 Like

Hi again!

I run the commands in an administrator shell but no success. Then I removed completely HAS agent and rebooted and then installed it again (as a non-admin user account providing my admin password for the installation) and reissued the netsh commands, but still no luck. I’m copying the extended log but I imagine that it can be something related to the daemon listening in the port being executed with admin rights for some reason and then not being able to display on a non-admin account? Al the rest works fine, sensors get created and button commands from HA work (shutdown, mute)… but no notifications and no media control.

This is the content of the log:
“2022-05-27 19:32:12.915 +02:00 [INF] [MAIN] Extended logging enabled
2022-05-27 19:32:12.920 +02:00 [INF] [SETTINGS] Config storage path: C:\Users\liamm\AppData\Local\HassAgent\config
2022-05-27 19:32:13.045 +02:00 [INF] [SETTINGS] Configuration loaded
2022-05-27 19:32:13.048 +02:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-05-27 19:32:13.305 +02:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded
2022-05-27 19:32:13.341 +02:00 [INF] [SETTINGS_COMMANDS] Loaded 2 entities
2022-05-27 19:32:13.710 +02:00 [FTL] [PROGRAM] FirstChanceException: Element not found. (0x80070490)
System.Runtime.InteropServices.COMException (0x80070490): Element not found. (0x80070490)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at CoreAudio.AudioSessionManager2.UnregisterNotifications()
2022-05-27 19:32:13.810 +02:00 [INF] [SETTINGS_SENSORS] Loaded 14 entities
2022-05-27 19:32:13.814 +02:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service
2022-05-27 19:32:13.814 +02:00 [INF] [LOCALAPI] Initializing …
2022-05-27 19:32:13.815 +02:00 [INF] [NOTIFIER] Ready
2022-05-27 19:32:13.815 +02:00 [INF] [MQTT] Identifying as device: LIAMBOX
2022-05-27 19:32:13.815 +02:00 [INF] [MEDIA] Ready
2022-05-27 19:32:13.820 +02:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-05-27 19:32:13.825 +02:00 [INF] [MQTT] Connecting …
2022-05-27 19:32:13.871 +02:00 [INF] [MQTT] Connected
2022-05-27 19:32:14.120 +02:00 [INF] [LOCALAPI] listening on port 5115
2022-05-27 19:32:15.829 +02:00 [INF] [MQTT] Initial registration completed
2022-05-27 19:32:35.821 +02:00 [INF] [SYSTEM] Application shutting down
2022-05-27 19:32:35.825 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at MQTTnet.Client.MqttClient.TrySendKeepAliveMessagesAsync(CancellationToken cancellationToken)
2022-05-27 19:32:35.826 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)
2022-05-27 19:32:35.832 +02:00 [INF] [MQTT] Disconnected
2022-05-27 19:32:35.844 +02:00 [FTL] [PROGRAM] FirstChanceException: Safe handle has been closed.
Object name: ‘SafeHandle’.
System.ObjectDisposedException: Safe handle has been closed.
Object name: ‘SafeHandle’.
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at Interop.Kernel32.CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped)
at System.Net.HttpListenerSession.CloseRequestQueueHandle()
2022-05-27 19:32:35.845 +02:00 [FTL] [PROGRAM] FirstChanceException: The I/O operation has been aborted because of either a thread exit or an application request.
System.Net.HttpListenerException (995): The I/O operation has been aborted because of either a thread exit or an application request.
at System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
2022-05-27 19:32:35.845 +02:00 [FTL] [PROGRAM] FirstChanceException: The I/O operation has been aborted because of either a thread exit or an application request.
System.Net.HttpListenerException (995): The I/O operation has been aborted because of either a thread exit or an application request.
at System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
2022-05-27 19:32:35.848 +02:00 [INF] [SYSTEM] Application shutdown complete”

The addons in HA work because I have tried to send both audio and notifications to another windows machine where HAS agent is installed in the admin account and there it works fine.

I might remove and install the whole Agent as admin and then simply copy the zip file in the non-admin account as you suggest in the thread, but I’d like to have one single copy of the agent for all accounts…

Thanks!

Just installed the beta to try out the media player entity. Update works very smoothly, and I am now able to see the entity in HA. I can pause and play existing music, but I’m not seeing the state change. In this case, I’m using the Windows version of Spotify to play music.

Could you please try this from another PC in the same network:

Open a browser and go to http://{hass_agent_ip}:5115, where you change {hass_agent_ip} to the IP address of the faulting PC.

If it shows HASS.Agent Active, we’ll know the API itself works.

There are also some docs that might be useful: HASS.Agent Docs - check the ‘Notifications’ topics on the left, specifically ‘Client Side’.

I’d like to have one single copy of the agent for all accounts

That currently only works if you use one account at a time (so no using of ‘switch user’ in Windows), and the folder needs to be accessible to all users. Better multiuser-support is in the works.

Strange, what version of Windows do you have?

Hi!
I’ve checked the API and it works and both command buttons I have created (shutdown and mute) work. All sensors work fine, but still not notifications or media player functionality. There is something weird here. I have completely removed HAS agent and installed it from scratch again in the non-admin account (my son’s) and then I have given port access to all users and restarted the agent, but still nothing. I have as well tested the notification from the configuration itself and then it works, so it is definitely something around the network ports.

On second thoughts… I might have an idea! I use Home assistant in a docker container in a linux machine. Which port does the Home assistant agent uses? It could be that docker is not allowing the inbound connection of the agent on the Windows machines? But why then does it work in another windows machine where Hass agent is installed in the admin account?

I would like to help, but I’m a linux guy and the intricacies of programing in .NET is not so palatable right now… :wink:

I guess I will wait until you fix the multi-user support. In any case, thanks for devoting your free time on this… as owner as several open source projects myself I do know the time it takes!

Regards,
/Nacho

Hm don’t think the multiuser support will fix this. It might be something in the Home Assistant configuration, especially since HASS.Agent’s API can be reached from another machine. Did you check the HA debugging docs? We might get some more info there. Optionally post your HA yaml configuration for the notifications/mediaplayer here.

In any case, thanks for devoting your free time on this… as owner as several open source projects myself I do know the time it takes!

Thank you! That’s nice to hear, because yea it takes a ton of time :grin:

Now I’ve wasted both your and my time. Really sorry for that! It turns out that I had a typo in the configuration in home assistant of the notifier where the admin one was rightly configured (/notify at the end) while the two non-admin installations I had written /notif which clearly explains why they did not work. I have now tested with one of the two non-admin computers and both notifications and TTS to the media player work.

Well hopefully this is good for other people to learn how to debug problems!
Thanks again!

Definitely not wasted time if it lead to the solution :smiley:

The config is a bit error-prone, I want auto entity discovery in a future version of the integrations, but for now I’m glad it’s working!

1 Like

I tried rebooting once more just in case, but no change. I’m using Windows 10 with latest updates. The entity is able to control play/pause, volume up, and volume down but state just says idle and no other music info or controls. Using desktop version of Spotify, latest version.

Scratch that. Think I fixed it. Turned on a media overlay feature within Spotify that was blocking it from publishing back to the OS for the agent to see. I think it’s working now.

Awesome, nice find! Was it this setting:

If so, I’ll add it to the manual :slight_smile:

Indeed. Hopefully that helps save someone 3 minutes. :stuck_out_tongue:

Hah yea, that’s the dream :grin:

@SamKr hey man I have a question or feature request please :slight_smile: how would I go about making a sensor to tell whether the specified window (or just the active window) is running fullscreen? (not maximised)

Use case is for Plex Media Player, I have a command to send the fullscreen key, but I’d love to have a sensor for it so I can automate fullscreen if it’s not.

(my AV receiver causes the window to resize when turning on/off)

Yep that’s a feature request :stuck_out_tongue: Added it to the list (hassagent-92), thanks :slight_smile:

1 Like

I’m gonna try this as soon as my backup loads onto my new SD card. This is what I’ve been looking for! Thanks!

1 Like

I love the new beta feature of showing the browser next to the Windows system tray. Matches perfectly using the Metrology theme.

I have two questions / request:

  1. Can we make the tray icon monochrome? As you can see, all other official tray icons are in white (for dark theme) or black (for light theme). I’m happy to offer help if you need help making these icons.

  2. Can we left-click the tray icon to open the browser, and right-click to open the menu? Right now left-clicking the icon doesn’t seem to do anything, and the default OS behavior for left-clicking usually opens the systray panel.

Thanks for the awesome work!

Hi @madelena,

For starters - LOVE the theme! Looks so slick, definitely installing that myself.

About your requests:

  1. Sure thing! I’m (obviously heh) no graphics designer, so if you could help with the icons, that’d be great :grin:

  2. Interesting, alright, I’ll make it configurable

You’re very welcome, and thank you as well :slight_smile:

1 Like