# Threshold with duration

**URL:** https://forums.losant.com/t/threshold-with-duration/1738
**Category:** Help
**Tags:** workflow
**Created:** [April 23, 2019, 11:26am UTC](https://forums.losant.com/t/threshold-with-duration/1738 "2019-04-23T11:26:53Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Roi\_Aranyi](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Roi\_Aranyi](https://forums.losant.com/u/Roi_Aranyi)
#### Post date: [April 23, 2019, 11:26am UTC](https://forums.losant.com/t/threshold-with-duration/1738/1 "2019-04-23T11:26:53Z")

</div>

Hi,  
How can I create a workflow which will trigger an action when the device readings have crossed a threshold for X min.  
For example the freezer temperature is above -20 c for more than 10 min?

---

<div class="post-metadata">

### Author: ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)
#### Post date: [April 23, 2019, 1:51pm UTC](https://forums.losant.com/t/threshold-with-duration/1738/2 "2019-04-23T13:51:53Z")

</div>

Hi @Roi_Aranyi,

You will want to make use of a [Timer Node](https://docs.losant.com/workflows/triggers/timer/) and a [Conditional Node](https://docs.losant.com/workflows/logic/conditional/). The Timer Node will trigger after a set amount of time, and the Conditional Node will give you a boolean that sends you right or left for true and false. So you will go right (true) if the freezer has been above -20 degrees, and perform some actions afterwards for handling the lower temperature (email notification, text notification, alert). The [On Change Node](https://docs.losant.com/workflows/logic/on-change/) may also provide some of what you are looking for, or you could do a timestamp comparison of the last recorded value to check for those 10 minutes (details found [here](https://forums.losant.com/t/count-the-number-of-active-device-sessions-unique-serial-numbers/1732/2)).

There is also a feature request [here](https://forums.losant.com/t/addition-of-a-timer-capability/1692) that could benefit, so be sure to vote!

Let me know how else I can help,  
Julia

---

<div class="post-metadata">

### Author: ![Roi\_Aranyi](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Roi\_Aranyi](https://forums.losant.com/u/Roi_Aranyi)
#### Post date: [April 23, 2019, 2:33pm UTC](https://forums.losant.com/t/threshold-with-duration/1738/3 "2019-04-23T14:33:35Z")

</div>

Thanks Julia,  
Will this solution ensure the temp was above -20 the all time or is just sampled in two different time points?

---

<div class="post-metadata">

### Author: ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)
#### Post date: [April 23, 2019, 3:05pm UTC](https://forums.losant.com/t/threshold-with-duration/1738/4 "2019-04-23T15:05:58Z")

</div>

Hi @Roi_Aranyi,

The solution I provided above is ideal for two time points in some use cases, but another engineer pointed out to me a better solution for your use case. It was recommended that you use the [Storage: Set Value Node](https://docs.losant.com/workflows/data/store-value/) to store the current time if the temperature of the freezer goes above -20 degrees. Then, when your Device State workflow is triggered, you can compare the time of current workflow to the time you have just stored in workflow storage by subtracting one from the other in a Conditional Node. Then, if the time is over 10 minutes, you will be able to send a notification or perform an action from the workflow.

Let me know if an example would make this clearer!  
Thanks,  
Julia

---

<div class="post-metadata">

### Author: ![Roi\_Aranyi](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Roi\_Aranyi](https://forums.losant.com/u/Roi_Aranyi)
#### Post date: [April 24, 2019, 6:59am UTC](https://forums.losant.com/t/threshold-with-duration/1738/5 "2019-04-24T06:59:52Z")

</div>

Thanks again Julia,  
I think I understand the general idea, just one question:  
In the solution you’ve mentioned would each reading above the threshold will get the Set Value Node to keep current time?  
How do I keep the Set Value Node from overriding the time of the first time the temp crossed the threshold?

---

<div class="post-metadata">

### Author: ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)
#### Post date: [April 24, 2019, 3:42pm UTC](https://forums.losant.com/t/threshold-with-duration/1738/6 "2019-04-24T15:42:46Z")

</div>

Hi @Roi_Aranyi,

You do not have to override the time for every cross of the threshold, but you are able to if your use case calls for it. I have built out an example workflow we can walk through:

The workflow below will store the time if the temperature is above -20, and will send a text alert if the temperature stays above -20 for longer than 10 minutes.

This workflow receives mock temperature values from my Virtual Button:  
 ![40%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/b/b86ba72482bd9a680d01083e0268bdd44361f8d1.png)

Then I get my stored value which I have named `tempTime` and put that value on the payload at `data.lastTemp`. If it is null, I will know that the temperature has been at the correct levels, but if it is not null, it will hold the time at which the temperature was too high.

 ![22%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/b/b932a49d51f2db14c8f5c771804fa4d0c3fcdf09.png)

Then I check my current temperature reading:

 ![31%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/f/fed10af88decd65cfd5f8662b1de7091fd8fe420.png)

If it is below -20, it goes left, and my stored `tempTime` value is reset to null.

 ![51%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/182229e5555e593df07698feeb8cf2dc3375b7f2.png)

If it is too hot (above -20), the path goes right to a conditional that will check if `tempTime` has a stored value.  
 ![55%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/731f53ad89270bfdf0b90e6dadca0aeca2858304.png)

If it does have a stored value, we go left to another conditional that compares the current time and the stored time, and if more than 10 minutes have passed since the temperature was above -20, I will receive a text notification:

 ![48%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/e885b01466690728a38b2b518637703d73452530.png)

If my stored `tempTime` value is null, the workflow goes right and sets my storage value to the current time:

 ![05%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1446c774e9f21d5f63342245da41becf31e060f5.png)

If it does have a stored value, we go left to another conditional that compares the current time and the stored time:

 ![48%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/e885b01466690728a38b2b518637703d73452530.png)

Then, when 10 minutes have gone by and my temperature is still too high, I receive a text notifying me that I should check it out!

 ![00%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/14032c63d653bd1ea582fa96fd1cb26ff2680861.png)

Let me know how else I can help,  
Julia

---

<div class="post-metadata">

### Author: ![Roi\_Aranyi](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Roi\_Aranyi](https://forums.losant.com/u/Roi_Aranyi)
#### Post date: [April 28, 2019, 5:28am UTC](https://forums.losant.com/t/threshold-with-duration/1738/7 "2019-04-28T05:28:37Z")

</div>

Perfect.  
Thank you 🙂

---

<div class="post-metadata">

### Author: ![Jose\_Cruz](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/jose_cruz/32/1580_2.png) [@Jose\_Cruz](https://forums.losant.com/u/Jose_Cruz)
#### Post date: [August 18, 2019, 1:17am UTC](https://forums.losant.com/t/threshold-with-duration/1738/8 "2019-08-18T01:17:41Z")

</div>

Hi @JuliaKempf, I’m running into a similar situation but in my case what I’m trying to accomplish is:

1. Bring values from a dashboard ‘slide/set’ input to a Virtual Button into the workflow - for example, Temperature Max threshold
2. Once I get a sensor temp report, I want to compare the last dashboard threshold value (temp\_max, for example) with the current sensor temp reading
3. if current \> temp\_max then send SMS, for example

I was successful in setting the temp\_max threshold from the dashboard input control into the correct device payload. But the problem I’m having the way I’m working the workflow is that all temp sensor reports are compared to the same temp\_max threshold from my one device:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6241486834d1c72e72a6758ba37e172c879e751a.png)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1ce2ae83d003884047ea58eafa4c4ef43e584796.png)  
The Data Explorer also confirms we have successful hexID (6DD2 in this case) tag payload transfer (no other device has this data):  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/b/bddfd172c0a26a0c463592585c50d41e23933c8f.png)

What is the best way, in your view, to then compare the correct device (in this case 6DD2) from the dashboard input with the correct device temp reading from the workflow to make a decision based on :

1. the correct Device
2. with the correct reported temp vs temp\>max?

Here’s the workflow detail currently :

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/d/d30e4dcd9555b16f47eacea9001abaefd980ab51.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/19852ead6407a6645870d099c7a69a0f69eb141d.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/c/cdefd1bf033ce60ee9361a4e6f45b8abc73eb502.png)

Let me know if this makes sense and/or if you need any add’nl info 🙂  
Right now, I am getting an SMS msg everytime ANY sensor reports a TEHU state and the TEMP has gone \> the LAST SET dashboard threshold setting, regardless of device (I have two Input Controls for two separate devices, including ‘6DD2’, yet the values used to ‘compare’ on the workflow are the last set on the dashboard, 6DD2 or the other).

Thank you in advance to you or whoever’s helping!!! j

---

<div class="post-metadata">

### Author: ![Jose\_Cruz](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/jose_cruz/32/1580_2.png) [@Jose\_Cruz](https://forums.losant.com/u/Jose_Cruz)
#### Post date: [August 18, 2019, 8:39pm UTC](https://forums.losant.com/t/threshold-with-duration/1738/9 "2019-08-18T20:39:38Z")

</div>

@JuliaKempf never mind! I got it. Following @yoursunny 's post [Sending temperature data values with SMS](https://forums.losant.com/t/sending-temperature-data-values-with-sms/116/7) and his use of the **Gauge Query Node** PLUS identifying that I was using the wrong device\_ID payload path, I can now successfully compare the right sensor temp read to the last known dashboard ‘set’ threshold:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/47e461168d0ddbe6107e7b4a10760b174f1b0087.png)

Thanks @yoursunny ☀ for your post/idea! 🕶 🔴
