# Call service after 10 seconds with a range

**URL:** <https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540>\
**Category:** General\
**Created:** [10 November 2021 23:52 UTC](https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540 "2021-11-10T23:52:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nightmare1](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nightmare1](https://discourse.nodered.org/u/nightmare1)\
**Post date:** [10 November 2021 23:52 UTC](https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540/1 "2021-11-10T23:52:38Z")

</div>

thanks in advance  
i have struggled with this basic task for a while and i can do it so easily in the home assistant automations but i want it in node red as part of a larger flow.  
i have a temperature sensor continually fluctuating, and i want to switch on a fan only if the temperature is within a range for more that a minute  
(Not when it is under or over a number)

i have simplified my example  
"when temperature is between 30 and 40"- "for more that 1 minute"- "switch on fan"

i have tried timers and loops restricted messages and i keep getting lost

i couldn't use a delay because i need it different automation when the temperature goes out side the range, the delay node was just triggering the node late even if the temperature had moved outside the range  
i wasnt able to use the trigger node because the temperature was always changing and resetting the trigger timer

---

<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:** [11 November 2021 00:32 UTC](https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540/2 "2021-11-11T00:32:12Z")

</div>

You can cancel the second, delayed message from a trigger node by sending msg.reset.  
Sending another temperature within the range doesn't retart the countdown.

 ![Untitled 6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c00a7ca17b69a2885ead52844958db10daf8ce6.jpeg)

```auto
[{"id":"f4eca1737fc074f0","type":"inject","z":"f7d3b9792b4e31ae","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"19","payloadType":"num","x":110,"y":100,"wires":[["91965a69aa2ab915"]]},{"id":"71022b6689a6bc0b","type":"trigger","z":"f7d3b9792b4e31ae","name":"","op1":"","op2":"ON","op1type":"nul","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":140,"wires":[["34a67c24a55a01cc"]]},{"id":"91965a69aa2ab915","type":"switch","z":"f7d3b9792b4e31ae","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"20","vt":"num","v2":"30","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":140,"wires":[["71022b6689a6bc0b"],["b2a61973ed87d686"]]},{"id":"b2a61973ed87d686","type":"change","z":"f7d3b9792b4e31ae","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":160,"wires":[["71022b6689a6bc0b"]]},{"id":"d31414fad885e286","type":"inject","z":"f7d3b9792b4e31ae","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":110,"y":140,"wires":[["91965a69aa2ab915"]]},{"id":"60a57b056134928c","type":"inject","z":"f7d3b9792b4e31ae","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"29","payloadType":"num","x":110,"y":180,"wires":[["91965a69aa2ab915"]]},{"id":"5809522291822f4f","type":"inject","z":"f7d3b9792b4e31ae","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"31","payloadType":"num","x":110,"y":220,"wires":[["91965a69aa2ab915"]]},{"id":"34a67c24a55a01cc","type":"debug","z":"f7d3b9792b4e31ae","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2021 07:17 UTC](https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540/3 "2021-11-11T07:17:04Z")

</div>

Perhaps [the hysteresis node](https://flows.nodered.org/node/node-red-contrib-hysteresis) will help here, it allows you to set lower/upper thresholds and compares it to the previous value.

---

<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:** [25 November 2021 07:17 UTC](https://discourse.nodered.org/t/call-service-after-10-seconds-with-a-range/53540/4 "2021-11-25T07:17:23Z")

</div>

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