Can't change audio output until restart of hagent

idk how to reproduce yet. I'm on the latest available beta. II have one audio sensor that I use to get e.g my headphones speakrs whatever else I have connected I use a dropdown select with data from that sensor. This works, I get the exact names, perfect so far! Now, I have an automation that on change of the dropdown changes the audio output via mqtt command on homeassistant/button/MainPC/setaudiooutput/action This also works! But sometimes it doesn't until a restart idk why yet though. It almost always happens when I turn off my monitors and go to sleep. I use smart switches to actually turn them off, not sure if related.
34 Replies
barrelltitor
barrelltitorOPโ€ข5mo ago
...how did I get to the logs again lol oh boi
024-06-28 14:06:40.891 +03:00 [DBG] [AUDIOMGR] Failed to retrieve devices: 0x88890004
System.Runtime.InteropServices.COMException (0x88890004): 0x88890004
at NAudio.CoreAudioApi.AudioSessionControl.get_GetSessionInstanceIdentifier()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at HASS.Agent.Shared.Managers.Audio.Internal.InternalAudioSessionManager.RemoveDisconnectedSessions() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\Internal\InternalAudioSessionManager.cs:line 41
at HASS.Agent.Shared.Managers.Audio.AudioManager.GetDeviceSessions(InternalAudioDevice internalAudioDevice) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 121
at HASS.Agent.Shared.Managers.Audio.AudioManager.GetDevices() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 228
024-06-28 14:06:40.891 +03:00 [DBG] [AUDIOMGR] Failed to retrieve devices: 0x88890004
System.Runtime.InteropServices.COMException (0x88890004): 0x88890004
at NAudio.CoreAudioApi.AudioSessionControl.get_GetSessionInstanceIdentifier()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at HASS.Agent.Shared.Managers.Audio.Internal.InternalAudioSessionManager.RemoveDisconnectedSessions() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\Internal\InternalAudioSessionManager.cs:line 41
at HASS.Agent.Shared.Managers.Audio.AudioManager.GetDeviceSessions(InternalAudioDevice internalAudioDevice) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 121
at HASS.Agent.Shared.Managers.Audio.AudioManager.GetDevices() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 228
barrelltitor
barrelltitorOPโ€ข5mo ago
uuuuuuuuuuuuuuuuuuuuuuuuuuuuh It's adding 2kb every second to the log
DrR0x
DrR0xโ€ข5mo ago
@ChrisRosenkreuz23 Going to add you in here instead of a new one
ChrisRosenkreuz23
ChrisRosenkreuz23โ€ข5mo ago
Ok
DrR0x
DrR0xโ€ข5mo ago
@Amadeo , @ChrisRosenkreuz23 is having a similar looking trace to me when changing volume That's not good ๐Ÿ˜ญ One thing I would try if you want @ChrisRosenkreuz23 is downgrading to beta1, that would fix this new issue afaik, but it shouldn't be that hard to fix if Ur happy to wait a couple of days
ChrisRosenkreuz23
ChrisRosenkreuz23โ€ข5mo ago
I'm good, I can wait
barrelltitor
barrelltitorOPโ€ข5mo ago
I've also passed the usb device to virtualbox at one epoint then passed it back usb device=audio device
Amadeo
Amadeoโ€ข5mo ago
Hm, so the trace only occurs while trying to change volume? And just to confirm, changing volume by command or by media player There was an issue with audio devices getting invalidated but I though we fixed it while investigating the audio memory leak
DrR0x
DrR0xโ€ข5mo ago
Command, however @barrelltitor appears to have the issue for changing audio output. Reading the stack trace it seems anything Todo with audio is failing sometimes, doesn't matter if it's volume or not. If it matter I reproduced with volumd
Amadeo
Amadeoโ€ข5mo ago
Now question what causes it to fail, the first suspect is sleep but...
DrR0x
DrR0xโ€ข5mo ago
Mine didn't do it immediately but i don't think it was sleep, my laptop is extremely messed up and it will turn back on 3s after sleeping. Meaning I have no easy way of knowing if it was sleep, sorry ๐Ÿ˜‚
barrelltitor
barrelltitorOPโ€ข5mo ago
My computer never sleeps ๐Ÿ˜Ž I have a rotary thingy from ikea I use to turn volume up down and pause, and a 2 button switch I use to change between audio devices I use the mute command too, I turn off my speakers via actual power off but I use an audio interface so it shouldn't matter at all as the interface is still on
barrelltitor
barrelltitorOPโ€ข5mo ago
No description
No description
barrelltitor
barrelltitorOPโ€ข5mo ago
that's all the sensors & commands I have, can givee config if needed I woke up about an hour or two ago, and I did the exact same things as the day before, but this time it's still working
ChrisRosenkreuz23
ChrisRosenkreuz23โ€ข5mo ago
any news on this? the faulty setvolume command, I mean
Amadeo
Amadeoโ€ข5mo ago
still trying to properly reproduce this audio stuff is starting to give me nightmares xd oh I think I know what it is damnnit so, issue is with COM threading compartments I hate it I have a POC of fix however it comes with a downside a small reduction in audio stuff performance I'll try to get is as "perfrormant" as possible, do some tests with monitors with speakers being turned on/off and then do a test build for you now to figure out if it doesn't leak memory I swear each time I dabble in audio stuff part of my soul dies
Amadeo
Amadeoโ€ข5mo ago
@barrelltitor @ChrisRosenkreuz23 (+@sreknob & @rafo as you were involved in the previous thread) https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.0-beta3-audio-comthread please try when you'll have some spare time - I tried to test various scenarios including just yanking the power cable to one of my monitors (quipped with speakers ofc) and it appears to be working
GitHub
Release 2.1.0-beta3-audio-comthread ยท amadeo-alex/HASS.Agent
Please do not download files from this "release" It's only purpose if to provide testing bed for the insiders/issue reporters. Unless explicitly instructed by the developers, please d...
Amadeo
Amadeoโ€ข5mo ago
of course, as always please backup your config
rafo
rafoโ€ข5mo ago
Will give it a shot tomorrow. Anything in particular we should test/keep an eye out for?
Amadeo
Amadeoโ€ข5mo ago
two main objectives with this one: - no errors in logs (excluding the "first time" ones) - no mem leak (still) and ofc all commands/sensors working ๐Ÿ˜„
sreknob
sreknobโ€ข5mo ago
Testing now. Only thing of note in the logs on startup so far is:
2024-07-08 20:55:39.346 -04:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-07-08 20:55:39.346 -04:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
at System.Threading.Mutex.OpenExistingWorker(String name, Mutex& result)
at System.Threading.Mutex.OpenExisting(String name)
at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-07-08 20:55:39.346 -04:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-07-08 20:55:39.346 -04:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\RazerReadWriteGuardMutex' is denied.
at System.Threading.Mutex.OpenExistingWorker(String name, Mutex& result)
at System.Threading.Mutex.OpenExisting(String name)
at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
Amadeo
Amadeoโ€ข5mo ago
those are fortunately first chance exceptions ๐Ÿ˜„
barrelltitor
barrelltitorOPโ€ข5mo ago
hi yes hello i am alive am testing i dont use the satellite service so i didnt install it hmmmm local api was disabled after the update
Amadeo
Amadeoโ€ข5mo ago
did you select the migrate option by any chance?
barrelltitor
barrelltitorOPโ€ข5mo ago
Not sure, everything else is ok though, oinly issue is I still can't change my audio a day later Will debug zigbee first
Message 0 received on homeassistant/button/MainPC/setaudiooutput/action at 3:12 PM:

Headphones (Logitech G733 Gaming Headset)
Message 0 received on homeassistant/button/MainPC/setaudiooutput/action at 3:12 PM:

Headphones (Logitech G733 Gaming Headset)
so it sent the correct name
barrelltitor
barrelltitorOPโ€ข5mo ago
No description
barrelltitor
barrelltitorOPโ€ข5mo ago
My logs show no errors, it only shows when I switch to the speakers When I restarted it I did get this
2024-07-11 15:13:08.956 +03:00 [DBG] [AUDIOMGR] device 'Main (Scarlett 2i2 USB)' activated
2024-07-11 15:13:44.725 +03:00 [INF] [SYSTEM] Application shutting down
2024-07-11 15:13:44.728 +03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at MQTTnet.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2024-07-11 15:13:44.728 +03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-07-11 15:13:44.731 +03: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)
at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishSubscriptionsAsync(TimeSpan timeout, CancellationToken cancellationToken)
at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.TryMaintainConnectionAsync(CancellationToken cancellationToken)
2024-07-11 15:13:08.956 +03:00 [DBG] [AUDIOMGR] device 'Main (Scarlett 2i2 USB)' activated
2024-07-11 15:13:44.725 +03:00 [INF] [SYSTEM] Application shutting down
2024-07-11 15:13:44.728 +03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at MQTTnet.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2024-07-11 15:13:44.728 +03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-07-11 15:13:44.731 +03: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)
at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishSubscriptionsAsync(TimeSpan timeout, CancellationToken cancellationToken)
at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.TryMaintainConnectionAsync(CancellationToken cancellationToken)
Not sure if its normal for restarts However, after a restart of the agent, it worked fine! So I'm thinking it could have been a stuck command not letting others pass thru properly or something? When I head to sleep I turn off power to the monitors from smart sockets, same for speakers, just headphones remain I also mute sound When I wake up, they all turn on The computer itself doesn't sleep, it just idles I haven't figured out exactly how to reproduce this yet
Amadeo
Amadeoโ€ข5mo ago
those first chance exceptions are related to mqtt connection not something that we need to be worrited atm hm unless you couldn't change the device because hass.agent didn't had connection to mqtt anymore?
barrelltitor
barrelltitorOPโ€ข5mo ago
It's from when I restarted, so I thought it might just be it closing the connection. But since it worked right after and had no error logs idk Had a vet emergency, will give full log when I'm back
Amadeo
Amadeoโ€ข5mo ago
hope it works out ok
barrelltitor
barrelltitorOPโ€ข5mo ago
Idiots ate 3d printing filament
Amadeo
Amadeoโ€ข5mo ago
XD
barrelltitor
barrelltitorOPโ€ข5mo ago
Or I think they did they were playing with it for 20mins and i found a piece onone of their tongues
Amadeo
Amadeoโ€ข5mo ago
cats?
Want results from more Discord servers?
Add your server