# Strange MQTT Client behavior

**URL:** <https://community.homey.app/t/strange-mqtt-client-behavior/45105>\
**Category:** Apps\
**Tags:** flow, mqtt\
**Created:** [March 22, 2021, 7:03pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105 "2021-03-22T19:03:01Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![xAPPO](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/xappo/32/13726_2.png) [@xAPPO](https://community.homey.app/u/xAPPO)\
**Post date:** [April 17, 2021, 3:50am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/61 "2021-04-17T03:50:27Z")

</div>

That’s one heck of a lot of work Harrie. - well done.

If you haven’t the time to look at it Menno could we have it as a test version ???

---

<div class="post-metadata">

**Author:** ![scanno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/scanno/32/8358_2.png) [@scanno](https://community.homey.app/u/scanno)\
**Post date:** [April 17, 2021, 6:38pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/62 "2021-04-17T18:38:24Z")

</div>

Its in test now @HarriedeGroot

---

<div class="post-metadata">

**Author:** ![scanno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/scanno/32/8358_2.png) [@scanno](https://community.homey.app/u/scanno)\
**Post date:** [April 17, 2021, 7:18pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/63 "2021-04-17T19:18:35Z")

</div>

I will leave the MQTT client in test for a while. Please let me know if all works out. If there are no (major) issues, I will submit it for certification.

Sorry for the lack of time, but I really have to focus on my research and thesis.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 17, 2021, 7:23pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/64 "2021-04-17T19:23:22Z")

</div>

Thanks! Let’s monitor for a while indeed. No hurries. Study is much more important.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 18, 2021, 10:07am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/65 "2021-04-18T10:07:19Z")

</div>

For completeness, the updated [test version](https://homey.app/nl-nl/app/nl.scanno.mqtt/MQTT-Client/test/) can be found here:

> **[MQTT Client](https://homey.app/nl-nl/app/nl.scanno.mqtt/MQTT-Client/)**
>
> Abonneer op MQTT topics

Please report your findings 🙂

Details of the changes:

> <https://github.com/scanno/nl.scanno.mqtt/pull/28>
>
> 1. \*\*Made some improvements to the topic registrations (api vs trigger)\*\*
> 2. \*\*…Fixed handling of retained messages\*\*
> 3. \*\*Prevent losing api connections\*\*
> 4. \*\*Addressed the bug of randomly disabled flows\*\*
> 5. \*\*Added unsubscribe api\*\*
> 6. \*\*Introduced a TriggerQueue to handle the rate limiting of flow card triggers and prevent disabling of flows\*\*
> 7. \*\*Added broker online/offline flow card triggers\*\*
> 8. \*\*Added flow card action to send an empty message to be able to remove retained messages from the broker\*\*
> 9. \*\*Introduced TopicsRegistry to register topics by reference (e.g. app id), this reference can be used with the unsubscribe api\*\*
> 10. \*\*Performance improvements\*\*
> 11. \*\*General bug fixes\*\*
> 
> \*\*Commit 1\*\*
> Topic registration:
> \- always subscribe to the broker to return retained messages on subscription
> \- re-subscribe to all previously registered topics on connection of the broker/mqtt-client (keep topic registry alive)
> \- made some calls async and actually wait for the result before continuing + fixed some async handling of promises
> \- extended the TopicArray with seperate methods for api & trigger topics
> 
> \*\*Commit 2\*\*
> \- prevent topic unsubscription if its used by another registration (api vs trigger)
> 
> \*\*Commit 3\*\*
> Flow card triggers:
> \- prevent destruction of the full topics array, causing all api connections being lost
> \- subscribe to all flow card trigger topics on initialisation
> \- on trigger card change (flow card config): unsubscribe from removed topics & subscribe to newly added topics
> \- await the Homey trigger call
> \- check for api topic match before forwarding the message to the realtime api
> 
> \*\*Commit 4\*\*
> pre-check to prevent uneccesairy calls to the Homey trigger system
> prevents disabling of random flows not even listening to these topics (Homey BUG?)...
> this is also a performance boost, since the Homey trigger system won't be called for all api topics
> the small downside is the duplicate topic matching, if there is a match on a trigger topic
> 
> \*\*Commit 5\*\*
> (added missing file 'Trigger.js' for commit 3
> 
> \*\*Commit 6\*\*
> On change of app settings:
> \- prevent destruction of the full topicsArray resulting in lost api connections
> \- re-connect to the broker to trigger subscription of all registered topics (instead of the trigger topics only)
> \- await topic unsubscription before setting up the new client
> 
> \*\*Commit 7\*\*
> added unsubscribe api
> 
> \*\*Commit 8\*\*
> Introduced a TriggerQueue to handle the rate limiting of flow card triggers and prevent disabling of flows
> 
> \*\*Commit 9\*\*
> Added broker online/offline flow card triggers
> 
> \*\*Commit 10\*\*
> Added flow card action to send an empty message to be able to remove retained messages from the broker
> 
> \*\*Commit 11\*\*
> Introduced a TopicsRegistry to register topics by reference (e.g. app id). The unsubscribe api can only be called for topics with the reference provided during topic subscription. This prevents unsubscription of topics used by other apps/processes.
> Also optimized the topic matching by using a topic map (instead of array lookup).
> 
> \*\*Commit 12\*\*
> \- Remove messages from the trigger queue when a topic is unsubscribed
> \- Added failsafe for the TriggerQueue size. Allow homey to disable the flow (by rate limiting) if the number of messages in the trigger queue exceeds the max allowed number of messages.
> \- Correctly handle topic subscriptions after flow card triger changes.
> \- updated the README with examples of usage of the reference and unsubscribing of topics
> 
> \*\*Commit 13\*\*
> \- merged api changes from commit: https://github.com/scanno/nl.scanno.mqtt/commit/02c3f0f816dd70475ebe2d848cd5012fb5034f2b
> \- added response to unsubscribe api
> \- version bump to 3.x

---

<div class="post-metadata">

**Author:** ![Zimo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/zimo/32/16621_2.png) [@Zimo](https://community.homey.app/u/Zimo)\
**Post date:** [April 18, 2021, 6:17pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/66 "2021-04-18T18:17:23Z")

</div>

I’ve been testing it during weekend and so far this build looks really stable. So far no random disable of flows.

@HarriedeGroot, you did fantastic job.

Thanks!

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 18, 2021, 6:19pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/67 "2021-04-18T18:19:13Z")

</div>

YW, got some good looking result here too:

> [@MQTT Client Topic-Trigger?](https://community.homey.app/t/mqtt-client-topic-trigger/46284/15):
>
> I have 15 topic trigger active now. System load seems to keep stable. In the past, the 15 trigger got the system load up to 1500%. So many thanks for this improvement. The FlowTrigger for Broker connect/disconnect is very useful, too - to start broadcast of MQTT-Hub after a reconnect.

---

<div class="post-metadata">

**Author:** ![Robert\_Zwetsloot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robert_zwetsloot/32/12399_2.png) [@Robert\_Zwetsloot](https://community.homey.app/u/Robert_Zwetsloot)\
**Post date:** [April 18, 2021, 10:00pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/68 "2021-04-18T22:00:30Z")

</div>

works like a charm, updated without any problem and kept running since. No problems with broker and hub, all flows and nodered are still alive.

---

<div class="post-metadata">

**Author:** ![xAPPO](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/xappo/32/13726_2.png) [@xAPPO](https://community.homey.app/u/xAPPO)\
**Post date:** [April 19, 2021, 5:45am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/69 "2021-04-19T05:45:20Z")

</div>

I am seeing promising results too… will post if I find anything ‘strange’

(Ignoring some v6 beta issues)

---

<div class="post-metadata">

**Author:** ![Russell\_S](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/russell_s/32/45779_2.png) [@Russell\_S](https://community.homey.app/u/Russell_S)\
**Post date:** [April 19, 2021, 11:45am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/70 "2021-04-19T11:45:35Z")

</div>

Great work Harrie… So far so good.

The disabling of flows error (flows which used MQTT client) doesn’t occur anymore. These flows use # wildcards to listen for certain text.

For me the disabling flows error would previously occur when ever I tried scanning for new Tasmota devices in the Tasmota App.

Doesn’t happen anymore 🙂 … Thanks mate …😃

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 24, 2021, 8:38am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/71 "2021-04-24T08:38:40Z")

</div>

One week past. I’m curious if anyone had any issues with the beta/test version of the MQTT Client app?

@scanno did you get any reports? How many users installed the test version?

And the connection dropouts between apps? Are regular app restarts still needed?

And Homey responsiveness? Became worse due the retained messages coming in now or is improved by the additional checks for incoming messages?

CPU/Memory usage? Memory leaks introduced?

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [April 24, 2021, 9:13am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/72 "2021-04-24T09:13:54Z")

</div>

Perhaps I am not the most heavy user (though I am currently setting up a HA dashboard, so…), but have not had any issue at all.

Currently MQTT Client is using 17.8MB (and Hub 25.6MB) memory.  
Homey seems very responsive too.  
(Broker in Docker on local Synology DS218+)

---

<div class="post-metadata">

**Author:** ![scanno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/scanno/32/8358_2.png) [@scanno](https://community.homey.app/u/scanno)\
**Post date:** [April 24, 2021, 10:47am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/73 "2021-04-24T10:47:57Z")

</div>

@HarriedeGroot there are 52 users using the test version. I have not received any bug reports and the crash count is 0.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [April 24, 2021, 12:13pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/74 "2021-04-24T12:13:11Z")

</div>

For me all is fine with the test version.  
Topic subscription is working. Also after Homey restart (subscription, automatic Hub-broadcast).  
Homey systemload is stable and independent of number of topic subscriptions.  
Memory: Hub=21,6MB, Client=14,5MB

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 24, 2021, 12:29pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/75 "2021-04-24T12:29:07Z")

</div>

Thanks for the info. Looking all good to me; actually much better then expected.

@scanno Are you comfortable pushing this to live?

I’ve got some updates for the Hub on test already. These need the new unsubscribe API of the client. So waiting for the client before it can be released.

---

<div class="post-metadata">

**Author:** ![scanno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/scanno/32/8358_2.png) [@scanno](https://community.homey.app/u/scanno)\
**Post date:** [April 24, 2021, 6:04pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/76 "2021-04-24T18:04:41Z")

</div>

Your build #6 for app nl.scanno.mqtt is now waiting for certification.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [April 26, 2021, 10:43am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/77 "2021-04-26T10:43:19Z")

</div>

Version is live I see, thanks @scanno.

---

<div class="post-metadata">

**Author:** ![Russell\_S](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/russell_s/32/45779_2.png) [@Russell\_S](https://community.homey.app/u/Russell_S)\
**Post date:** [April 29, 2021, 12:03am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/78 "2021-04-29T00:03:03Z")

</div>

It’s still working well for me. My devices use it on a daily basis.

---

<div class="post-metadata">

**Author:** ![Russell\_S](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/russell_s/32/45779_2.png) [@Russell\_S](https://community.homey.app/u/Russell_S)\
**Post date:** [June 7, 2021, 11:10pm UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/79 "2021-06-07T23:10:13Z")

</div>

Just a quick update.

Unfortunately the “flow disabled because executed too many times” error is reoccurring again for me. ☹

Previously this would only happen for me whenever I was trying to discover new devices in the Tasmota APP… Now it just seems to happen at random every few days for no reason.

This only occurs with flows that have a MQTT wildcard in them.

The only thing that has changed with my setup just before these new bunch of errors started occurring is that I’ve recently added a few more flows that use MQTT wildcards…

The application I’m using these flows for is to monitor 6 x 433Mhz PIR motion sensors , 2 x FireAlarms , and a contact sensor on my fridge door. I have a SonOff RF-Bridge listening out for all of these. It’s been reflashed with Tasmota so it can communicate any events from these sensors to Homey via MQTT…

Each sensor pauses for a few seconds between every transmission that it does. The contact sensor on the fridge door can transmit more rapidly but the problem never happens with it. I’d also be very lucky to get two motion sensors trigger exactly at the same time so the amount of traffic and input coming from all of them is quite low.

I’m on Homey version 6.0 . The SonOff RF bridge is on the latest version of Tasmota… Can anyone think of an theories. ?

Here is a sample of one of the flows in case I’m doing something wrong … thanks

[https://homey.app/f/-BVIED](https://homey.app/f/-BVIED)

---

<div class="post-metadata">

**Author:** ![Zimo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/zimo/32/16621_2.png) [@Zimo](https://community.homey.app/u/Zimo)\
**Post date:** [June 8, 2021, 7:36am UTC](https://community.homey.app/t/strange-mqtt-client-behavior/45105/80 "2021-06-08T07:36:48Z")

</div>

For me in the past helped to create MQTT device for each external sensor. Then flows do not monitor MQTT topic, but property of device which doesn’t lead to flow disable.

Only disadvantage is that only property (capability) which can store text messages is Album, Artist or Track, so messages from my UPS are displayed as Tracks 😉

[Previous page](https://community.homey.app/t/strange-mqtt-client-behavior/45105.md?page=3)

[Next page](https://community.homey.app/t/strange-mqtt-client-behavior/45105.md?page=5)
