Fire a message only once unless it changes

Hi there, I have a question concerning a Solarpanel project. I want to change the setpoint for an inverter via mqtt. The way I did it, the ouput message of a function node is fired everytime the input values come in. Even if this output message doesnt change, it is fired. To prevent that I used a contrib duplicate node, which prevents the message to get fired twice during the configured time. So far so good. If the output message of the function node changes the new message gets fired again. Good! If the first message is created again in the configured time period, after the second message passed, this message is blocked again. And thats the thing I would like to change. Is it possible to only block the actual message, and reset all old message, so if if they get fired again, they will pass?

Does the builtin Filter node do what you want, using Block Unless value Changes?

No, the filter block lets message A pass. It will block message A when it comes again. Then it will let message B pass, and blocks it if it comes again. If any of both messages comes again during the configured times the node blocks the messages. That seems to be the proper function!
I would like that message B passes after message A has passed, but blocking another message A and visa versa. I should reset the old filter after another message passed and only filter the new message. I hope this coherent. And want the mgtt message to be sent only when the setpoint changes, and that could also be the old setpoint.

This is what I would like to achieve + the script oft the function node before the filter block

Message A value: 600 output: 600
Message A value: 600 no output
Message B value: 800 output: 800
Message B Value: 800 no output
Message A value: 600 output: 600

var wert = msg.payload;
// Die einzelnen Variablen extrahieren
let Leistung
let Hyst = 10
// Wert größer als 600W dann Leistung auf 800 W erhöhen
if ( wert > (600+ Hyst))
Leistung = 800
if ( wert < (600-Hyst))
Leistung = 600
var msg = { payload: Leistung }
return msg

This is exactly what the filter node does.


1 Like

Ok, Thanks. I tried this out. Works as desired. Sorry should have found this by my myself. Was thinking to complicated or had trouble finding the right keyword because english is not my mothertongue. Thanks for your frienly contact. i'm getting further - until I get stuck again :rofl:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.