# Fire a message only once unless it changes

**URL:** <https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 May 2023 19:21 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329 "2023-05-10T19:21:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Popolackie](https://avatars.discourse-cdn.com/v4/letter/p/5e9695/32.png) [@Popolackie](https://discourse.nodered.org/u/Popolackie)\
**Post date:** [10 May 2023 19:21 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/1 "2023-05-10T19:21:23Z")

</div>

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?

 ![Screenshot 2023-05-10 211909](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee65e955683f911da4747b55ef1a331d0110da38.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 May 2023 19:40 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/2 "2023-05-10T19:40:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Popolackie](https://avatars.discourse-cdn.com/v4/letter/p/5e9695/32.png) [@Popolackie](https://discourse.nodered.org/u/Popolackie)\
**Post date:** [10 May 2023 19:57 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/3 "2023-05-10T19:57:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cameo69](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameo69/32/66593_2.png) [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Post date:** [11 May 2023 06:26 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/4 "2023-05-11T06:26:56Z")

</div>

> [@Popolackie](#):
>
> 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

This is exactly what the filter node does.

![output_filter_01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70bb4889b2e0ee588c247b289d3164f64b650d13.gif)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Popolackie](https://avatars.discourse-cdn.com/v4/letter/p/5e9695/32.png) [@Popolackie](https://discourse.nodered.org/u/Popolackie)\
**Post date:** [11 May 2023 07:13 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/5 "2023-05-11T07:13:47Z")

</div>

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 🤣

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 July 2023 07:14 UTC](https://discourse.nodered.org/t/fire-a-message-only-once-unless-it-changes/78329/6 "2023-07-10T07:14:15Z")

</div>

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