hass-agent / HASS.Agent

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

Bug: Becomes unavailable when adding command (mqtt) #164

Open wiedikerli opened 2 months ago

wiedikerli commented 2 months ago

When i'm adding commands like sleep or shutdown. The MQTT entity becomes unavailable. When i have no commands it works flawlessly with sensors and all. It happens for the agent and satellite.

i tried different versions: 2.0.1 and 2.1.0-beta4

To Reproduce Steps to reproduce the behavior:

  1. Install and Configure MQTT
  2. Add Command like sleep or shutdown
  3. Save and activate
  4. Entity becomes unavailable

Misc info (please complete the following information): image

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

Logs

2024-09-23 23:04:20.864 +02:00 [INF] [MQTT] Connected
2024-09-23 23:04:28.256 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-23 23:04:28.261 +02:00 [FTL] [PROGRAM] FirstChanceException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
MQTTnet.Exceptions.MqttProtocolViolationException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
   at MQTTnet.Client.MqttClient.TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancellationToken)
2024-09-23 23:04:28.261 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-23 23:04:28.262 +02:00 [FTL] [PROGRAM] FirstChanceException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
MQTTnet.Exceptions.MqttProtocolViolationException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
   at MQTTnet.Client.MqttClient.TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.PacketDispatcher.MqttPacketAwaitable`1.WaitOneAsync(CancellationToken cancellationToken)
2024-09-23 23:04:28.266 +02:00 [FTL] [PROGRAM] FirstChanceException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
MQTTnet.Exceptions.MqttProtocolViolationException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
   at MQTTnet.Client.MqttClient.TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.PacketDispatcher.MqttPacketAwaitable`1.WaitOneAsync(CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.Request[TResponsePacket](MqttPacket requestPacket, CancellationToken cancellationToken)
2024-09-23 23:04:28.267 +02:00 [FTL] [PROGRAM] FirstChanceException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
MQTTnet.Exceptions.MqttProtocolViolationException: Received packet 'PubAck: [PacketIdentifier=2] [ReasonCode=Success]' at an unexpected time.
   at MQTTnet.Client.MqttClient.TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.PacketDispatcher.MqttPacketAwaitable`1.WaitOneAsync(CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.Request[TResponsePacket](MqttPacket requestPacket, CancellationToken cancellationToken)
2024-09-23 23:04:29.277 +02:00 [INF] [MQTT] Connected
2024-09-23 23:04:29.295 +02:00 [INF] [COMMANDS] Removed command: sleep
2024-09-23 23:04:29.297 +02:00 [INF] [SETTINGS_COMMANDS] Stored 0 entities
amadeo-alex commented 2 months ago

Hello, looks like the MQTT library is not having a good time with the MQTT broker - could you please tell me which one you're using? Did you use the original HASS.Agent version & it worked properly, or you've started with the fork?

wiedikerli commented 2 months ago

i tested the original 2.0.1 and the forked one, but neither could connect to mqtt properly. I'm using rabbitmq as broker.

amadeo-alex commented 1 month ago

Ok, I understand, would it be possible for you to test if the same behaviour is present with mosquitto? If I remember correctly there were a few users that had strange issues with RabbitMQ (although I can't remember details so I don't want to point any fingers)