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.

output_filter_01

[{"id":"ffca59e0d79ef560","type":"comment","z":"c77baade4cd2f70c","name":"https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329","info":"https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329","x":1070,"y":100,"wires":[]},{"id":"fe40c2513c71dfa0","type":"debug","z":"c77baade4cd2f70c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":220,"wires":[]},{"id":"5ff2047c80a8f212","type":"inject","z":"c77baade4cd2f70c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":830,"y":200,"wires":[["aa993b7d59e2c1b1"]]},{"id":"5f3c5020a01a306a","type":"inject","z":"c77baade4cd2f70c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"800","payloadType":"num","x":830,"y":260,"wires":[["aa993b7d59e2c1b1"]]},{"id":"aa993b7d59e2c1b1","type":"rbe","z":"c77baade4cd2f70c","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":1050,"y":220,"wires":[["fe40c2513c71dfa0"]]}]
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.