LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.56k stars 68 forks source link

mqtt stopped working again #374

Open p6002 opened 10 months ago

p6002 commented 10 months ago

HASS Agent under windows 11 and 10 has problems with mqtt. After restarting the application it works for a day, then no contact again. Any plans to fix this bug? Without it, the app loses its point since it can't communicate with the server.

image
cwgannon commented 10 months ago

Working here without issue on Windows 11. Do other tools that connect via MQTT also get disconnected? Try MQTT Explorer, e.g.

dtaralla commented 10 months ago

I have the same issue. Discovered this awesome project, and did a fresh install of the app on my Win 11 PC. Set up the MQTT username and password (see screenshot below), but according to HASS MQTT addon log, the app is not sending the username and password and is trying to authenticate anonymously?

MQTT Addon log:

2023-11-25 12:05:30: New connection from 192.168.0.64:53666 on port 1883.
error: received null username or password for unpwd check
2023-11-25 12:05:30: Client 265470aa disconnected, not authorised.

Agent MQTT config: image

Agent logs:

2023-11-25 12:46:33.257 -05:00 [INF] [MAIN] HASS.Agent version: 2022.14.0
2023-11-25 12:46:33.259 -05:00 [INF] [MAIN] Extended logging enabled
2023-11-25 12:46:33.262 -05:00 [INF] [SETTINGS] Config storage path: C:\Users\david\AppData\Roaming\LAB02 Research\HASS.Agent\config
2023-11-25 12:46:33.348 -05:00 [INF] [SETTINGS] Configuration loaded
2023-11-25 12:46:33.351 -05:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2023-11-25 12:46:33.521 -05:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded
2023-11-25 12:46:33.522 -05:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded
2023-11-25 12:46:33.524 -05:00 [INF] [SETTINGS_SENSORS] Config not found, no entities loaded
2023-11-25 12:46:33.529 -05:00 [INF] [LOCALAPI] Disabled
2023-11-25 12:46:33.529 -05:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2023-11-25 12:46:33.529 -05:00 [INF] [MQTT] Identifying as device: XXXX
2023-11-25 12:46:33.535 -05:00 [INF] [MQTT] Connecting ..
2023-11-25 12:46:33.535 -05:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2023-11-25 12:46:33.599 -05:00 [INF] [NOTIFIER] Ready
2023-11-25 12:46:33.613 -05: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)
2023-11-25 12:46:33.613 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
2023-11-25 12:46:33.613 -05: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.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2023-11-25 12:46:33.613 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
2023-11-25 12:46:33.614 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
2023-11-25 12:46:33.621 -05:00 [INF] [MEDIA] Ready
2023-11-25 12:46:33.632 -05:00 [WRN] [MEDIA] No MediaSession active
2023-11-25 12:46:33.646 -05:00 [WRN] [MQTT] Not connected, message dropped (won't report again for 5 minutes)
2023-11-25 12:46:33.655 -05:00 [INF] [HASS_API] Home Assistant version: 2023.11.3
2023-11-25 12:46:33.998 -05:00 [INF] [HASS_API] System connected with https://XXXXXXXXX:XXXXX
2023-11-25 12:46:38.627 -05: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 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2023-11-25 12:46:38.627 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2023-11-25 12:46:38.627 -05: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.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2023-11-25 12:46:38.627 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
2023-11-25 12:46:38.627 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2023-11-25 12:46:38.628 -05:00 [FTL] [NET] FirstChancemqttCommunicationException: Connecting with MQTT server failed (NotAuthorized).
MQTTnet.Adapter.MqttConnectingFailedException: Connecting with MQTT server failed (NotAuthorized).
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
dtaralla commented 10 months ago

Update: my issue was somehow in my credentials.

At first, I was trying to use my username & password from my HASS user credentials (the ones I use to connect through HASS itself to my account). Was not working.

Then I tried not using a hostname (my.hostname.ca for example) in the agent MQTT config, and use the LAN IP address of my home assistant instance. Still not working, but at least I got the stacktraces shown above.

Tried creating a new mqtt user through the MQTT addon config. And that's where I was mistaken - somehow I put a wrong input in the Logins option, and the addon just silently failed to add my new MQTT user and didn't save it. Hence why the "unautorized" messages when I was trying to use it! I tried again by editing my MQTT addon config YAML directly rather than using the fancy config interface, and now it works!

My mqtt addon config:

logins:
  - username: THENAME
    password: THEPASSWORD
require_certificate: false
certfile: fullchain.pem
keyfile: privkey.pem
customize:
  active: false
  folder: mosquitto
debug: false