# Activate the trigger only once

**URL:** https://discourse.nodered.org/t/activate-the-trigger-only-once/74131
**Category:** General
**Created:** [24 January 2023 17:19 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131 "2023-01-24T17:19:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Bomber75](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bomber75/32/64882_2.png) [@Bomber75](https://discourse.nodered.org/u/Bomber75)
#### Post date: [24 January 2023 17:19 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/1 "2023-01-24T17:19:15Z")

</div>

Hello everybody,

with home assistant I control a temperature sensor,  
the object checks if the temperature is lower than 20, then turn on a relay.  
The problem is this: when the temperature drops below 20  
the object activates the relay and this is correct, but the problem is that the object continues to trigger even when a value changes below the set threshold, I would like that when it reaches the threshold, the object only activates once.  
I thank

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8db5b962a7e59b85fcf3d87583784fb9e31000ec.png)  
 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/03bd9d2bcf71edc1f12797a7fa697bc035202b99.png)

---

<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: [24 January 2023 21:01 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/2 "2023-01-24T21:01:05Z")

</div>

Add a Filter node on the output, set to pass only when the value changes. Then you will get only one `on` message and only one `off` message.

---

<div class="post-metadata">

### Author: ![Bomber75](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bomber75/32/64882_2.png) [@Bomber75](https://discourse.nodered.org/u/Bomber75)
#### Post date: [26 January 2023 09:26 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/3 "2023-01-26T09:26:16Z")

</div>

thanks, I inserted the filter, and I set it that if greater than 19 it does not consider the data, however how can I do if it is less than 19?  
The filter options indicate only if greater than you do....

I also tried to use the first option of the filter, but when the value changes as it is not equal, the data is read.

thank you very much.

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/9276ea9959dcf4fd636ec864ae014fb2710f64e2.png)  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/827a6ae0a3c39bfa12f8a4d68c9b6d336d8e17d4.png)  
 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c1d2f8d99fd09cd3bc845e017b98b6495bb2fc3.png)

---

<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: [26 January 2023 09:38 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/4 "2023-01-26T09:38:48Z")

</div>

I didn't say replace the existing nodes with that node, I said to add a filter node (I meant at the end of the flow), set to only pass if data changes. That will suppress the repeated `on` and `off` messages.

---

<div class="post-metadata">

### Author: ![Bomber75](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bomber75/32/64882_2.png) [@Bomber75](https://discourse.nodered.org/u/Bomber75)
#### Post date: [26 January 2023 09:53 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/5 "2023-01-26T09:53:38Z")

</div>

hi,  
the nodes have been added, I have not removed anything, if I use the first option of the filter node, the data passes because the read value is different, if instead the data is equal it is not considered.  
The value unfortunately changes is not always the same, so I used another option of the filter node, but I don't know how to set the node if the value is less than .....

thank you

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b105b7efafd842dda5f178babeda12991fc18544.png)  
 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c1d2f8d99fd09cd3bc845e017b98b6495bb2fc3.png)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [26 January 2023 10:12 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/6 "2023-01-26T10:12:37Z")

</div>

The difficulty using the filter node seems to be because your data is split between the two wires, for "Switch turn on" and "Switch turn off".

Is it possible to combine these into one, rbe then split again? Something like this (no HA nodes in the example)

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e7ccd5c87fcde0a5619ef3775bb9355a954c025.jpeg)

```auto
[{"id":"06e1b33b692056bc","type":"inject","z":"18302aaec057c898","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"19","payloadType":"num","x":90,"y":80,"wires":[["0f19e212ce258b8b"]]},{"id":"60ddbdf3832ab530","type":"inject","z":"18302aaec057c898","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":90,"y":120,"wires":[["0f19e212ce258b8b"]]},{"id":"ceefcd7272a139c9","type":"inject","z":"18302aaec057c898","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":90,"y":160,"wires":[["0f19e212ce258b8b"]]},{"id":"0f19e212ce258b8b","type":"switch","z":"18302aaec057c898","name":"<20?","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"20","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":100,"wires":[["b7d5980bb6049dbe"],["44def34c21007195"]]},{"id":"44def34c21007195","type":"change","z":"18302aaec057c898","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["41ef36c36f8ac7a7"]]},{"id":"b7d5980bb6049dbe","type":"change","z":"18302aaec057c898","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":80,"wires":[["41ef36c36f8ac7a7"]]},{"id":"41ef36c36f8ac7a7","type":"rbe","z":"18302aaec057c898","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":470,"y":100,"wires":[["020ac02ac024ddbb"]]},{"id":"020ac02ac024ddbb","type":"switch","z":"18302aaec057c898","name":"ON or OFF ?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":100,"wires":[["e54564bb5d8098e3","f5dbeaa5575a8496"],["250c2727b643a907","cd83acadd225604c"]]},{"id":"e54564bb5d8098e3","type":"link out","z":"18302aaec057c898","name":"Turn something ON","mode":"link","links":[],"x":810,"y":80,"wires":[],"l":true},{"id":"250c2727b643a907","type":"link out","z":"18302aaec057c898","name":"Turn something OFF","mode":"link","links":[],"x":820,"y":120,"wires":[],"l":true},{"id":"4f575cbb1e44d2dd","type":"inject","z":"18302aaec057c898","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"18","payloadType":"num","x":90,"y":40,"wires":[["0f19e212ce258b8b"]]},{"id":"f5dbeaa5575a8496","type":"debug","z":"18302aaec057c898","name":"ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":40,"wires":[]},{"id":"cd83acadd225604c","type":"debug","z":"18302aaec057c898","name":"OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":160,"wires":[]}]

```

---

<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: [26 January 2023 13:46 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/7 "2023-01-26T13:46:18Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d7d7b7e6f98f552ff791071ee968eea287eb33d.png)

Instead of using separate nodes to turn it on and off, use one node that is passed a message to tell it whether to go on or off. Then put the filter in front of that.

---

<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: [9 February 2023 13:46 UTC](https://discourse.nodered.org/t/activate-the-trigger-only-once/74131/8 "2023-02-09T13:46:54Z")

</div>

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