# Switch nodes problem - change nodes when certain value and reset

**URL:** <https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367>\
**Category:** General\
**Created:** [7 January 2024 19:36 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367 "2024-01-07T19:36:05Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:33 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/23 "2024-01-07T23:33:10Z")

</div>

It is set to chill but it takes a little while to start chilling so temperature carries on rising when it is switched on.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:35 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/24 "2024-01-07T23:35:25Z")

</div>

ARGH!

Ok......

😉🙂

So the unit it turned on and starts spitting out the temperature every 15 seconds.  
It starts around 65 and then wobbles a bit up and/or down.

`0` means CHILL and `1` means HEAT.

That is in the `raspberry` part of the payload.

(Again: that is confusing.)  
`mode` would be better. Then you can have `0` as cooling and `1` as heating.

Or even better:  
`msg.payload.mode` and it can be `heat` or `cool`.  
No ambiguity then.

All these changes can be done easily with a `change` node upstream from this part of the flow at no real cost to you.

# But again I ask:

What are the values expected?  
min - max

If you have it split to heating and cooling, say:  
40-60 heating  
61-80 cooling

I still don't really know or understand.

---

<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:** [7 January 2024 23:35 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/25 "2024-01-07T23:35:52Z")

</div>

So to restate your problem. You are trying to control a heater and a cooler in some container. There is also a sensor in the container.

If the temperature goes above 66 you want to turn on the chiller.  
Once the container gets above 69 you want to turn off the chiller and turn on the heater.

In other words you want to keep the temperature as close as you can to between 66 and 69 degrees.

Is that about right?  
How often does the sensor read the temperature?

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:38 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/26 "2024-01-07T23:38:01Z")

</div>

If the temperature goes above 66 I want to turn on chiller = correct

It will go over 70.

When it goes under 70 I want it to turn off and heater to come on.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:38 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/27 "2024-01-07T23:38:18Z")

</div>

> [@zenofmud](#):
>
> f the temperature goes above 66 you want to turn on the chiller.  
> Once the container gets above 69 you want to turn off the chiller and turn on the heater.

Sorry, but is that right?  
Just want to check as the confusion level is already fairly high.

---

<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:** [7 January 2024 23:39 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/28 "2024-01-07T23:39:48Z")

</div>

How often does the sensor read the temperature?

what do the two items in the inject nodes represent  
msg.payload,raspberry and msg.payload.test?

So basically either the heater or the chiller is going to be on.  
The heater goes on and chiller goes off when the temp drops below 66 (I should have said below in my prior post)  
The chiller goes off and the heater goes on when the temperature goes above 70.

with out knowing what the two values (msg.payload,raspberry and msg.payload.test) are for it is hard to help you.

It seems one of them should be msg.temperature (as Andrew suggested) to make it easy to understand the logic in your flow.

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:40 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/29 "2024-01-07T23:40:24Z")

</div>

The raspberry payload switches it to the '30' switch node. Nothing else. There is a reason for that as it reacts different depending on if the raspberry is receiving value 0 or 1. I'm just going to confuse things if I go into the reasons for that.

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:40 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/30 "2024-01-07T23:40:38Z")

</div>

It reads every 15 seconds

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:42 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/31 "2024-01-07T23:42:26Z")

</div>

payload.raspberry represents something that changes the way heating and cooling need to be controlled.  
payload.test has the temp value (and lots of other stuff that is doesn't effect this)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:42 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/32 "2024-01-07T23:42:46Z")

</div>

Ok, may I suggest this:

An absolute MINIMUM temperature - which we hope will never be seen.  
An absolute MAXIMUM temperature - as above.

The lowest temperature you want to see BEFORE you start heating.  
So if it gets to this temperature (or below) the heater is turned on.

The highest temperature you want to see BEFORE you start cooling.  
~~(as above but replace~~  
So if it gets to this temperature (or above) the cooler is turned on.

And another value:  
How long must these temperatures be read before you actually do things.

eg:  
(argh temperature in Fahrenheit is painful at best)

30 abs minimum  
100 abs max

50 start heating  
70 start cooling

3 messages

Then:  
If you receive `3` consecutive messages of \<50, you start heating.

Then, when you receive `3` consecutive messages of \>70, you start cooling.

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:49 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/33 "2024-01-07T23:49:13Z")

</div>

It switches the moment payload.test value is above threshold.

Node '66' works perfectly for turning it on. But when the temp starts falling doesn't turn it off at correct temp.

turns on at 65c temp rises above 70c and then comes back down. Needs to turn off when goes back under 70c.

So node '66' for turning on and after 70c node '70' to turn off and on from thereafter until RS switches and then resets to '66' when RS received value 0 again.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:49 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/34 "2024-01-07T23:49:34Z")

</div>

# And just to put it out there, I see there is a fundamental flaw with what you are doing.

Sorry, but just saying.

This isn't **CRITICAL** and can be worked around but a bit more code.  
Not a big deal.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:51 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/35 "2024-01-07T23:51:11Z")

</div>

For the sake of making it easier for this idiot - that is me by the way.

Let's make it a lot bigger between the START COOLING and START HEATING values.

Because the post I just posted is going to have a big effect on the whole working of things.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:55 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/36 "2024-01-07T23:55:24Z")

</div>

Oh, and the other question begging to be asked:

What **EXACTLY** is this?  
A household fridge?  
An INDUSTRIAL cooler?

And what is it storing?  
Food, Milk, Blood, Meat?????

And:  
What is the ALLOWABLE temperature range before what ever it is is spoiled?

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [7 January 2024 23:55 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/37 "2024-01-07T23:55:55Z")

</div>

RS receives payload.raspberry 0 payload.test 64 = START COOLING

RS receives payload.raspberry 0 payload.test 68 = START COOLING

RS receives payload.raspberry 0 payload.test 72 = START COOLING

as the payload.test has gone over 70 then

RS receives payload.raspberry 0 payload.test 68 = START HEATING

That's why I had two different switch nodes '66' and '70'.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 January 2024 23:58 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/38 "2024-01-07T23:58:53Z")

</div>

I SORT of understand what you are saying/wanting to say.

As I see it, until the values for which I've asked are CLEARLY defined, you are chasing your tail and you will get very dizzy very quickly.

You will spend a lot of time achieving little.  
Sorry.

Once the values are set, I can explain methods to greatly reduce the complexity of what you are doing.  
I'm not saying it is the best way, but at least I can explain it clearly to you and hope you understand.

As it is, we are talking conceptually just now.

---

<div class="post-metadata">

**Author:** ![btbr](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@btbr](https://discourse.nodered.org/u/btbr)\
**Post date:** [8 January 2024 00:00 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/39 "2024-01-08T00:00:04Z")

</div>

It's an environment control project. I've tried to simplify it as much as possible with heat and chill not to add to the confusion. It would definitely add to the confusion.

I'm not sure what you mean by allowable temperature range. The ranges set are in '66' and '70'. It works presently but chills too much. Back down to 64c as set in '66'.

---

<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:** [8 January 2024 00:00 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/40 "2024-01-08T00:00:11Z")

</div>

Take a look at this flow (it just deals with the temperature) and see if it has the basics down

 ![Screenshot 2024-01-07 at 6.59.35 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b6c280a37fd24bdefa37bb375a6d22f9abc2ea5.png)

```auto
[{"id":"97780b9e6ba1dff2","type":"switch","z":"7f2f416d9e78b7fb","name":"Is temp < 66","property":"temperature","propertyType":"msg","rules":[{"t":"lte","v":"66","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":580,"wires":[["cc4bf93a4db44b0a","ec5f534c2a796b31"],["a2ca243b0b4bebc1"]]},{"id":"cc4bf93a4db44b0a","type":"change","z":"7f2f416d9e78b7fb","name":"turn heater on","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"turn heater on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":440,"wires":[["ef2dde12c16c38d5"]]},{"id":"a2ca243b0b4bebc1","type":"switch","z":"7f2f416d9e78b7fb","name":"is temp > 70","property":"temperature","propertyType":"msg","rules":[{"t":"gte","v":"70","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":640,"wires":[["8656a6b439efaaf3","ca36ca3480733fd5"],["c9475c7e3a8a0e94"]]},{"id":"7047dbc02dccdedd","type":"inject","z":"7f2f416d9e78b7fb","name":"temperature 60","props":[{"p":"temperature","v":"60","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":500,"wires":[["97780b9e6ba1dff2"]]},{"id":"ef2dde12c16c38d5","type":"debug","z":"7f2f416d9e78b7fb","name":"Heater control debug 306","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":520,"wires":[]},{"id":"135e32dc9c0afd00","type":"debug","z":"7f2f416d9e78b7fb","name":"Chiller control debug 307","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":580,"wires":[]},{"id":"3a5abfbf86654841","type":"inject","z":"7f2f416d9e78b7fb","name":"temperature 65","props":[{"p":"temperature","v":"65","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":540,"wires":[[]]},{"id":"a76b29057aa85025","type":"inject","z":"7f2f416d9e78b7fb","name":"temperature 72","props":[{"p":"temperature","v":"72","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":580,"wires":[["97780b9e6ba1dff2"]]},{"id":"9968ccbfb9808694","type":"inject","z":"7f2f416d9e78b7fb","name":"temperature 30","props":[{"p":"temperature","v":"30","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":640,"wires":[["97780b9e6ba1dff2"]]},{"id":"559a8a47bd676f12","type":"inject","z":"7f2f416d9e78b7fb","name":"temperature 60","props":[{"p":"temperature","v":"60","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":680,"wires":[["97780b9e6ba1dff2"]]},{"id":"ec5f534c2a796b31","type":"change","z":"7f2f416d9e78b7fb","name":"turn chiller off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"turn chiller off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":480,"wires":[["135e32dc9c0afd00"]]},{"id":"ca36ca3480733fd5","type":"change","z":"7f2f416d9e78b7fb","name":"turn heater off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"turn heater off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":560,"wires":[["ef2dde12c16c38d5"]]},{"id":"8656a6b439efaaf3","type":"change","z":"7f2f416d9e78b7fb","name":"turn chiller on","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"turn chiller on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":600,"wires":[["135e32dc9c0afd00"]]},{"id":"c9475c7e3a8a0e94","type":"debug","z":"7f2f416d9e78b7fb","name":"do nothing","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":680,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 January 2024 00:02 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/41 "2024-01-08T00:02:10Z")

</div>

> [@btbr](#):
>
> I'm not sure what you mean by allowable temperature range. The ranges set are in '66' and '70'. It works presently but chills too much. Back down to 64c as set in '66'.

As you are using values like 66 and 64 I take it you are talking Fahrenheit.

So 4deg F is the absolute maximum allowable change?

Yikes! That is worrying to me.  
I don't really know how much that is in my language, but that is TIGHT TOLERANCES!

And again: What environment is it?  
A household fridge or an industrial one?

_Or is it just the dog house in the back yard?_

Again, see back to my post 33

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 January 2024 00:05 UTC](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367/42 "2024-01-08T00:05:43Z")

</div>

I like you did add a `do nothing` output.

That is good. 😉

And I also like how you used the `topic` to explain what is happening.  
Top marks for that.  
👍

[Previous page](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367.md?page=1)

[Next page](https://discourse.nodered.org/t/switch-nodes-problem-change-nodes-when-certain-value-and-reset/84367.md?page=3)
