Sort of Token Bucket

Hi, I'm looking for help with a somewhat particular request that I can't find a solution to.
I have a nodered flow that manages me a relay (on/off) based on different conditions. List the conditions:

  • if the % of a battery is below 25%, the relay is switched on
  • If the % of the battery is between 25 and 30% and if a global variable is at 1, then the relay is set to on (the global variable is at 1 if solar production at that exact moment is greater than 2000 Wh )
  • if the battery % is above 30%, the relay is switched off

The problem I encounter is that the global variable is subject to solar production which can fluctuate over a given time around 2000 (perhaps just less, just more). This generates me a continuous on and off of the relay.
How could I handle this situation to avoid having a sudden switch between on and off?

You could either use a smooth node to smooth out the data or you could use an RBE node to prevent the continual "bounce". Probably other ways too but those are the two that spring to mind.

I am currently trying checking my var every 10 min to reduce "on/off effect".

The thing that you should debounce is the global variable. Change the logic setting that to apply some hysteresis. So only set it to one if it is greater than 2005 and set it to zero if it is less than 1995 (or whatever is appropriate). In between then leave the variable as it is.

Thanks @Colin for advise.
I will have some tests with hysteresis and understand if is a good solution.
The problem is that variabile is based on solar production and it shlould varies very often (fully sun, clouds, fog, etc..)

An alternative to hysteresis would be to use a Smooth node to smooth the solar production figure before setting the global variable. It all depends on what you want to achieve.

Mm i can't follow you. How do you mean with "smooth" node? Can you please give an example?
What I need to achieve is avoid to switch on and off many times in a short time.

I meant node-red-node-smooth. I forgot that it is not a core node. You will need to install it using Manage Palette. You could use it to slow down the rate of change of the solar figure, so that the global var would not change so quickly. Really you need to decide what you want to happen under various conditions. Suppose there is a cloud, then the sun comes out for 10 seconds (or 30 seconds or 2 minutes, or whatever) and then goes away again, what to you want to happen to the global variable?

You are right @Colin. Best solution should be understand wheter condition at that time, but is almost impossible.
What do u suggest? If your have experience on that, of course.

Can you explain in words what you are trying to achieve, for those who do not know about solar and battery charging?

Of course.
I have a solar system that supplies energy to the house and if the demand of the house is lower than the production, it charges the batteries.
My boiler (which heats the house) can run on both electricity and gas.
I created a system, managed by nodered, such that if the % of the battery is too low (below 25%) the boiler, via the ON relay, works on GAS. If the % is above 30%, it runs on current (therefore it is taken either from the panels directly, if the production is sufficient, or from the batteries). If the % of the battery charge is above 25% and the solar production (in that instant) is above 2100 W (this is the boiler's request, on average, to operate on current) I set the relay to OFF (so the boiler runs on electricity). If the solar production, at that given instant, is less than 2100 W, and the % of the batteries is between 25 and 30, then I put the relay to ON (so the boiler works on GAS.)

I hope it's clearer that way

There must be some more criteria that you want to satisfy, otherwise your initial solution is adequate.

Also perhaps it would be better to use the average solar over the last 15 minutes rather than the instantaneous figure. Ideally you might like to use the value that is going to be over the next 15 minutes, but it may not be practical to do that.

1 Like