That rate-limit per topic problem

Seems like I'm not alone, but has anyone a good solution?

I have a bunch of messages with different topics that I want to rate limit, per topic.

But besides sending the first message, I also want it to delay each msg per topic, not send them all at once wich seems to be what to choose from as of now.

Like this, treat each topic individually and send latest every 5 minutes

minute0 msg.topic = A ---> send

minute1 msg.topic = A --> drop
minute1 msg.topic = B--> send

minute2 msg.topic = A --> drop

minute3 msg.topic = A --> drop

minute4 msg.topic = A --> drop

minute5 msg.topic = A --> send
minute5 msg.topic = B--> drop

minute6 msg.topic = A --> drop
minute6 msg.topic = B--> send

minute7 msg.topic = A --> drop

To have one delay-node per topic, as I've seen one suggested doesn't realy seems lika a solution when there are som 50 different topics and also it changes every now and then...

I have looked into some other nodes, but none seems to do what I want.

So any suggestions?

1 Like

Will this do it?

image

One would think so :wink:

But it dosn't, and I'm not quite sure what scenario it is supposed to be good for...

from the doc:

The rate limiting can be applied to all messages, or group them according to their msg.topic value. When grouping, intermediate messages are automatically dropped. At each time interval, the node can either release the most recent message for all topics, or release the most recent message for the next topic.

Meaning that evrery " release time", one one topic is released...
here is an example from my flow:

Topic dropped :
1, 2, 3, 1, 2
topic released at time limit: --> 3
topic dropped: 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2
topic released at time : --> 1
topic dropped: 3, 1, 2, 3, 3, 1, 2
topic relesed at time: --> 2

What I want is each topic released every time limit, here it is just one topic ....

Set it to send All Topics then. If you need them spread out to once per minute then follow it with another Delay node set to rate limit everything at 1 minute intervals.

Well, that is an option, but not quite what I want.

Say a message is sent at min 1. The rate limit is 10 minutes and the it will release all topics. If I then delay again by say 1 min and there are maybe up to 50 topics in the que, that would mean it is quite possible the que will just increase...

the messages are sensor values and states from my home-assistant, so messages that has not changed are filtered out earlier. .

And also, I would prefer to always let the first message of each topic true, and rate limit the next, until the time set is reached.

of course it would be a lot easier if there was not so many topics, and some of them report more often than others and would be great not having to set the report rate on each individually...

Do you mean that you want the 50 topics (or however many there are) to be uniformly distributed across the time interval? So they would be far apart if there were only 5 topics, but 10 times more often if there were 50 topics? Can you explain what you are doing with them that needs that?

The rate limit per topic modes were designed for two scenarios... both aimed at situations where you have very little bandwidth (or time) to send data.

  1. each topic in turn - sends just one message per time interval - ensures each topic has a chance of being sent - and always sends the latest value of that topic.
  2. send all topics - if you only have a short transmit time before going back to sleep (for example) - then send all the topics you have available as quickly as possible - then go back to sleep.
    In both cases the time interval is set - and on each tick the required action is taken.

So yes I can see that the option you want isn't covered - as normally we would just suggest sticking one delay/ratelimit node into each topic wire al let them be treated individually... but I can see that may not be ideal over a randomly large set of topics. But then again - I'm not sure what you are doing downstream ? Can it not cope with a burst of messages arriving ?

:thinking:
Perhaps somebody will create a node to cover this situation...
:wink:

My JS skill is not up to the task nor do I have the time to "get there" in the foreseeable future or I'd take a stab at it.

I found a flow that actually does what I want, as it seems :slight_smile: including sending the first message. Especially when setting count to trigger to 1.

Time based Ratelimit / Throttle per topic

ps. searching the flows-page can be a hassle as well, you have to almost know the exact name of what you looking for...

It's not that it can't per se... I'm sending it to my phone and trying to get it a little bit less busy. Especially when it comes to data that I don't exactly need uppdated every minute or so...

The problem is that the update rate can vary a lot... and there are no easy way to set it in homeassistant.

There are defenetly more than one way to solve the problem, and rate-limit seemed like an easy and quick way to solve the problem :slight_smile:

What I want is basically each topic treated individually.

Like having one node for each topic, but one node to solve it.

And as it seems, the flow I found does just that, :slight_smile:

Looking quickly at the flow you linked, it appears that it only sends on a message when it receives one. That means that if you get a gap in messages coming in, or ifmessages stop coming in, then messages already in the queue will not get sent, or will be delayed longer than they should be. That may not matter in your system though.

I changed the countToTrigger to 1 and for now it seems to work, at least since it let the first message through. But haven't had time to check it properly yet and might not be today.