# Start above and send message if below

**URL:** https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170
**Category:** General
**Created:** [16 March 2020 11:19 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170 "2020-03-16T11:19:40Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [16 March 2020 11:19 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/1 "2020-03-16T11:19:40Z")

</div>

Hi Guys,

I want to have a flow which tells via Alexa-Routine that the room humidty in bathroom drops below 50% (to remember me to close the window after daily showering) but only if it was higher before.

To be honest I've no clue how to manage that at the moment. Do you have some hints for me which leads me in the right direction?

Thx in advance for any input!

Cheers  
Florian

---

<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: [16 March 2020 13:33 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/2 "2020-03-16T13:33:58Z")

</div>

Welcome to the forum Florian.  
One way to achieve that is to use a function node and in there save the previous value of humidity and then you can compare the current value with the previous value to determine whether to send on a message to trigger Alexa. Have a look in the docs at that section on Writing Functions and in there it will tell you how to use the node context to save the previous value.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 March 2020 13:35 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/3 "2020-03-16T13:35:08Z")

</div>

This would be a simple task if you had a smart home controller. and a window temp and humidity sensors

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [16 March 2020 14:24 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/4 "2020-03-16T14:24:03Z")

</div>

Hey Guys,

first - thx for your help. Unfortunately I do not "speak" java-script so I'm not really able to program this via a function node.

Of course I'm using a smart-home-controller (namely: HomeAssistant) - unfortunately I do not have Window-Sensors (of course would be simple with this)

Cheers

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 March 2020 14:36 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/5 "2020-03-16T14:36:10Z")

</div>

Why not buy a cheap sensor, i'm sure the aqara zigbee devices work with home assistant. You can pick these sensors up for £10. Or fit a humidity fan and not have to open widow, as fan will start when humidity rises, uk cost £30 plus fitting

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [16 March 2020 14:39 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/6 "2020-03-16T14:39:57Z")

</div>

Hey, yes I know - I'm already using Aquara Devices (for humidity ;)) ... It's because I wanted to know if it's possible to do it that way I try to manage currently.

Cheers

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 March 2020 14:41 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/7 "2020-03-16T14:41:53Z")

</div>

Yes it's possible.

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [16 March 2020 14:43 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/8 "2020-03-16T14:43:22Z")

</div>

Do you know how? 😉

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 March 2020 14:49 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/9 "2020-03-16T14:49:21Z")

</div>

As Colin said you will need to store the last value and use a function node or possibly switch node to compare values.

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [16 March 2020 15:54 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/10 "2020-03-16T15:54:35Z")

</div>

As I said before - I do not "speak" java-script so I'm not really able to program this via a function node. Maybe some can give me a "template".

thx!

---

<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: [16 March 2020 16:18 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/11 "2020-03-16T16:18:03Z")

</div>

you could use some change nodes, switch nodes and [flow variables](https://nodered.org/docs/user-guide/context)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 March 2020 18:44 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/12 "2020-03-16T18:44:03Z")

</div>

show us what you have tried and i am sure this forum will push you in the right direction.

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [17 March 2020 08:49 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/13 "2020-03-17T08:49:52Z")

</div>

Hey, this was my first try - but of course it always triggers if value changes

```auto
[{"id":"7bf9c73d.cc7968","type":"server-state-changed","z":"b701708f.d6fa2","name":"Badezimmer Luftfeuchtigkeit <50%","server":"cdcde6c6.b307a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"50","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"x":180,"y":60,"wires":[["eee2552d.1736b8"],[]]},{"id":"3f04b7b9.f48ae8","type":"delay","z":"b701708f.d6fa2","name":"","pauseType":"delay","timeout":"7","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":60,"wires":[["9d0117db.751c38"]]},{"id":"eee2552d.1736b8","type":"rbe","z":"b701708f.d6fa2","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":60,"wires":[["3f04b7b9.f48ae8"]]},{"id":"9d0117db.751c38","type":"alexa-remote-routine","z":"b701708f.d6fa2","name":"","account":"67422e97.c87f7","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"str","value":"Die Luftfeuchtigkeit im Badezimmer ist wieder unter 50%. Das Fenster kann wieder geschlossen werden."},"volume":{"type":"num","value":"100"},"mode":"set","devices":["G090XG079414118F"]}},"x":750,"y":60,"wires":[[]]},{"id":"cdcde6c6.b307a8","type":"server","z":"","name":"HA (MULATZ)","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"67422e97.c87f7","type":"alexa-remote-account","z":"","name":"Alexa-Account","authMethod":"proxy","proxyOwnIp":"192.168.100.208","proxyPort":"3456","cookieFile":"/root/.node-red/alexa-remote/auth.txt","refreshInterval":"3","alexaServiceHost":"layla.amazon.de","amazonPage":"amazon.de","acceptLanguage":"de-DE","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

```

---

<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 March 2020 09:56 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/14 "2020-03-17T09:56:16Z")

</div>

Add a fow - with an `inject` - to a `change` node to put the starting humidity into a flow variable maybe called startingHumidity.

Instead of using the server-state node `during testing`, just use three `inject` nodes with different numbers connected to a `change` node that moves the value into a flow variable - maybe call it newHumidity. Next use a `switch` node to compare the two values. if the condition arises where you want to do something, place a `change` node to move the new Humidity to the startingHumidity and output a message to a `debug` node.

Once you have this working, output your message to the Alexa-Routine to see if that works

next add the sensor or whatever is getting the humidity to the start to see if it works.

Once it is working you can remove the three `inject` nodes used for testing.

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [17 March 2020 11:00 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/15 "2020-03-17T11:00:11Z")

</div>

I'm afraid you got me wrong. I don't want to trigger if the value arise above a value but if it falls down below AGAIN after it was above before. I do not see this in your example to be honest.

Thx

---

<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 March 2020 12:06 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/16 "2020-03-17T12:06:31Z")

</div>

![Screen Shot 2020-03-17 at 8.02.59 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/9152615b204bfcfb674efbdd71b8e1ecdd264830.png)

when I said 'arise' I mean when the condition occurs. You define the condition. It might help you (me) it you were to write out the steps you see involved - create some psuedo code then set that as a guide to building your flow.

---

<div class="post-metadata">

### Author: ![florianmulatz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/florianmulatz/32/18414_2.png) [@florianmulatz](https://discourse.nodered.org/u/florianmulatz)
#### Post date: [17 March 2020 12:22 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/17 "2020-03-17T12:22:58Z")

</div>

Sorry for misunderstanding - english is not my native language. In this case - I don't get it. How should your example trigger after it falls below again. Sorry when I act stupid.

BR

---

<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 March 2020 13:51 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/18 "2020-03-17T13:51:32Z")

</div>

So you want to be reminded if the humidity goes below 50% after rising for a short period of time. First you should decide on what that time interval is...10 minutes, 30 minutes?

Lets say 15 minutes.

pseudo code - flow 1  
1 - store current time in start time (ST) and current time (CT)  
2 - read humidity and store it in highest humidity (HH)  
3 - humidity dropping (HD) to 'NO'

pseudo code - flow 2  
1 - read humidity  
2 - if current humidity (CH) \> highest humidity (HH), replace HH with CH  
3 - if current humidity (CH) \< highest humidity (HH), set humidity dropping to 'YES'  
4 - read time  
5 - if current time - start time (CT - ST) \< 15 do nothing else if HD = YES AND current humidity \< 50 shut the window

You realize you have a lot of edge cases to think about.

What if it is cold outside and the humidity is 30% will you still open the window to take the shower?  
What if it is hot outside and you have air conditioning on inside, will you still open the window?  
What if it is nice outside and you want to leave the window open even after taking the shower?  
Should you have a switch on the window to activate the flow - i.e. don't run it if the window is closed?

---

<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: [16 May 2020 13:51 UTC](https://discourse.nodered.org/t/start-above-and-send-message-if-below/23170/19 "2020-05-16T13:51:36Z")

</div>

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