# Controlling an output from Temperature with Notification

**URL:** <https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857>\
**Category:** General\
**Created:** [16 November 2021 21:54 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857 "2021-11-16T21:54:21Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [16 November 2021 21:54 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/1 "2021-11-16T21:54:21Z")

</div>

Hi All,

I'm a bit stuck with my first flow ever, I'm trying to switch an output based on temperature being above a setpoint and this all works as expected.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e003f3186eba3ce24fa1f951934357780378d60f.png)

With the following debug output.

```auto
11/17/2021, 8:46:34 AM[node: 0dcd1af1fd2a15cf](http://10.1.1.50:8123/api/hassio_ingress/5XMITp0dfOkegIxKxmG2FaTmqN9H3-pfZdwxue67hUw/#)sensor.ewelink_th01_8858b423_temperature : msg.payload : string[4]

"26.1"

11/17/2021, 8:46:35 AM[node: 2394e5e1d13041d2](http://10.1.1.50:8123/api/hassio_ingress/5XMITp0dfOkegIxKxmG2FaTmqN9H3-pfZdwxue67hUw/#)sensor.ewelink_th01_8858b423_temperature : msg.payload : string[3]

"OFF"

```

As I now want to integrate some SMS alerting, which I also have sorted, I need to filter (perhaps using the filter component) to ensure that only one message for a particular state is sent rather than an ON or an OFF every 30 seconds. I only want to receive the one SMS.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 November 2021 23:34 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/2 "2021-11-16T23:34:30Z")

</div>

Indeed the filter node is probably what you want

---

<div class="post-metadata">

**Author:** ![RootShell-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rootshell-coder/32/47167_2.png) [@RootShell-coder](https://discourse.nodered.org/u/RootShell-coder)\
**Post date:** [16 November 2021 23:57 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/3 "2021-11-16T23:57:00Z")

</div>

Maybe using a function block will help you

```auto
[{"id":"10d237f5abaeef12","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":1074,"y":486,"wires":[["e086b16f5f5b1e3d"]]},{"id":"b36a7b4a0c534feb","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"22","payloadType":"num","x":1076,"y":522,"wires":[["e086b16f5f5b1e3d"]]},{"id":"ed5785eff42dfac5","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"23","payloadType":"num","x":1076,"y":558,"wires":[["e086b16f5f5b1e3d"]]},{"id":"bc69c06df7e46843","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"24","payloadType":"num","x":1076,"y":594,"wires":[["e086b16f5f5b1e3d"]]},{"id":"da0e065ba252cac4","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"25","payloadType":"num","x":1076,"y":666,"wires":[["e086b16f5f5b1e3d"]]},{"id":"eafc1f7be0fe2ba2","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"26","payloadType":"num","x":1076,"y":702,"wires":[["e086b16f5f5b1e3d"]]},{"id":"7052d3e1ded26a82","type":"inject","z":"c991dbcde03824f2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"27","payloadType":"num","x":1076,"y":738,"wires":[["e086b16f5f5b1e3d"]]},{"id":"e086b16f5f5b1e3d","type":"function","z":"c991dbcde03824f2","name":"","func":"const t = flow.get('temperature') ?? {\n 'alarm': 25, //set temperature alarm here\n 'sms': false\n}\n\nlet alarm = {}\n\nif (msg.payload >= t.alarm && !t.sms){\n alarm.payload = `send sms alarm ${msg.payload}`\n t.sms = true\n flow.set('temperature', t)\n return [msg, alarm]\n}\n\nif (msg.payload < t.alarm && t.sms){\n alarm.payload = `send sms no alarm, t stable ${msg.payload}`\n t.sms = false\n flow.set('temperature', t)\n return [msg, alarm]\n}\n\nreturn [msg, null]","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1260,"y":594,"wires":[["1ac7d78807bcc019"],["3686b9dbf1eff01b"]]},{"id":"1ac7d78807bcc019","type":"debug","z":"c991dbcde03824f2","name":"t","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1412,"y":576,"wires":[]},{"id":"3686b9dbf1eff01b","type":"debug","z":"c991dbcde03824f2","name":"alarm","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1412,"y":612,"wires":[]}]

```

to remove the set value

 ![bg](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fad460282048137d7236ea9d0b5b7af87db9af4.png)

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [17 November 2021 01:37 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/4 "2021-11-17T01:37:51Z")

</div>

OK, I'll have a look at that one, thanks. Just need to work out how to import that function code, I'm sure there's a way just haven't had to do it yet 🙂

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [17 November 2021 01:39 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/5 "2021-11-17T01:39:26Z")

</div>

> Blockquote  
> Indeed the filter node is probably what you want

Yep, but I've looked at doing that and couldn't get it to work, likely because there are two streams coming in from the input, a true condition value and a false.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 November 2021 08:38 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/6 "2021-11-17T08:38:27Z")

</div>

Where in your flow are you adding the node(s) to send the SMS?  
How long does the requirement:

> [@pspeirs](#):
>
> I only want to receive the one SMS.

last? Forever?

What should happen if the state changed before the time limit ends?

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [18 November 2021 10:00 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/7 "2021-11-18T10:00:08Z")

</div>

Hi,

I'm looking at putting the SMS notification after I detect that the temperature has gone above the setpoint. Ideally, the temp would be above the setpoint for maybe 10 minutes before firing off an SMS message. There would be no further SMS while the temp remains over the setpoint. Once the temp drops below the setpoint, all would be reset and and over temp would result in another SMS being sent.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 November 2021 13:59 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/8 "2021-11-18T13:59:27Z")

</div>

So let's say the set point is 50 and the temps come in as 30, 40, 50, 55 at this point you want an SMS messsage sent and nothing else for ten minutes, right?

But what happens if after 5 minutes, the temp drops to 30 (there are extreme changes I know) or rises to 100? As I read your description, no SMS message would be sent.

The best thing to do is draw up a flow chart laying out your requirements. Then you can get into the How to do it part.

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [18 November 2021 23:26 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/9 "2021-11-18T23:26:12Z")

</div>

Hi, extreme change in a short period of time wasn't a consideration because it simply won't happen that quickly.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 November 2021 00:34 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/10 "2021-11-19T00:34:01Z")

</div>

So can it go over the set point and within 10 minutes drop bellow it?  
What happens if it then goes back over the set point?

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [21 November 2021 03:32 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/11 "2021-11-21T03:32:33Z")

</div>

> [@zenofmud](#):
>
> it go over the set point and within 10 minutes drop bellow it?  
> What happens if it then goes back over the set point?

If it drops below the setpoint, things will reset and start over. Much like the post with the function block above shows.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 November 2021 09:50 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/12 "2021-11-21T09:50:26Z")

</div>

So if the temp hovered around the set point you could get a message more than once in 10 minutes…right?

---

<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:** [21 November 2021 11:07 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/13 "2021-11-21T11:07:34Z")

</div>

Can this not be handled simply with a Trigger node set to Send Nothing then after 10 minutes send the SMS, but use the below threshold detection to reset the trigger so nothing will be sent if it drops below the threshold?

---

<div class="post-metadata">

**Author:** ![pspeirs](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pspeirs](https://discourse.nodered.org/u/pspeirs)\
**Post date:** [26 November 2021 04:20 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/14 "2021-11-26T04:20:42Z")

</div>

This case I may as well continue to use the function. I'm not worrying too much ab out the after 10 minutes requirement, it currently seems to work fine as is.

---

<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 January 2022 04:21 UTC](https://discourse.nodered.org/t/controlling-an-output-from-temperature-with-notification/53857/15 "2022-01-25T04:21:14Z")

</div>

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