# Flow for temperature control

**URL:** <https://discourse.nodered.org/t/flow-for-temperature-control/23117>\
**Category:** General\
**Created:** [14 March 2020 21:18 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117 "2020-03-14T21:18:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LarsAndersen](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@LarsAndersen](https://discourse.nodered.org/u/LarsAndersen)\
**Post date:** [14 March 2020 21:18 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/1 "2020-03-14T21:18:29Z")

</div>

I would like some input on the smartest way to do the following.  
I have 4 different states we can call them A, B, C and D.  
My states should run in a loop of 4 hours interval  
In case of state A I would like a switch do the following  
3 hours on and 1 hour off  
In case of state B I would like my switch to do the following:  
2 hours on and 2 hours off

and so on for the last two states.  
What is the smartest way to set this up?

---

<div class="post-metadata">

**Author:** ![hominidae](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hominidae/32/4174_2.png) [@hominidae](https://discourse.nodered.org/u/hominidae)\
**Post date:** [14 March 2020 21:55 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/2 "2020-03-14T21:55:23Z")

</div>

hmmmm...what is your intend on how to switch between the four states...i.e. on a timely schedule or totally random, like from an external trigger or how else?

---

<div class="post-metadata">

**Author:** ![LarsAndersen](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@LarsAndersen](https://discourse.nodered.org/u/LarsAndersen)\
**Post date:** [15 March 2020 07:32 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/3 "2020-03-15T07:32:56Z")

</div>

In case of A i would like to have the switch turned on the first hour and then off the next 3 hours.  
in case of B the switch is turned of the first two hours and then off the next two hours.  
In case of C, 3 hours on and 1 hour off.

Something like 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:** [15 March 2020 07:51 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/4 "2020-03-15T07:51:44Z")

</div>

Ok, so checking:  
You have 1 input.  
There are 4 states that are determined from the _input_.  
It is a 4 hour interval.

Ok, as it has been mentioned there is a timing problem, sort of.

Here's my take.

`inject` node set to inject (output) a signal every 4 hours to get the input reading.  
Though this may not make sense at this stage; you need to make a time line when/how things happen.

So, the `inject` node _gets_ the input value.  
That will need a bit of work, but let's keep things simple.  
The readings _range_ from 1 to 4.

Put a `switch` node to _switch_ (route?) the payload depending on the value.

If `==1` send it to a trigger node.  
The trigger node will be set to send `on` then `after 3 hours` send `off`  
If `==2` make the `trigger` node make the values 2 and 2. (Similar to 1)

And so on.

Does that help?

I can knock up a basic flow if you want. But understand that it will be _limited_ to a 1-4 input.

---

<div class="post-metadata">

**Author:** ![hominidae](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hominidae/32/4174_2.png) [@hominidae](https://discourse.nodered.org/u/hominidae)\
**Post date:** [15 March 2020 08:54 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/5 "2020-03-15T08:54:08Z")

</div>

Well, yes...this is quite clear from your first post, already.  
What I asked is, in what sequence are A, B C and D are "fired" ?.  
The "outside loop", so to say, like 16hrs, 4hrs each in a sequence of A,C,D,B, then again A,C,D,B, ...and so on over and over again ?

In this case, as a first design thought, I would create a cascade of DSM nodes, like in the traffic light example, here: [https://github.com/cflurin/node-red-contrib-dsm/wiki/Traffic-lights](https://github.com/cflurin/node-red-contrib-dsm/wiki/Traffic-lights)

Instead of three states, like in a traffic light, you have your four States, triggered hourly.  
Each state will follow its own sequence, where each hour event will determine if a state change will occur.  
The first DSM node, driving the "four state traffic light", will be responsible for driving/controlling the outer-sequence/loop of A,C,D,B

---

<div class="post-metadata">

**Author:** ![LarsAndersen](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@LarsAndersen](https://discourse.nodered.org/u/LarsAndersen)\
**Post date:** [15 March 2020 10:28 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/6 "2020-03-15T10:28:21Z")

</div>

The loop is 4 hours. Within that loop only one state can happend. And the state that happens must take 4 hours. Right now I have use the looptimer node as trigger. This triggers a http request that finds the state value and then one of the 4 states much run for 4 hours.

---

<div class="post-metadata">

**Author:** ![LarsAndersen](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@LarsAndersen](https://discourse.nodered.org/u/LarsAndersen)\
**Post date:** [15 March 2020 13:49 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/7 "2020-03-15T13:49:57Z")

</div>

Yes that helps a lot. Thanks for this. Could you also help me to understand how to setup this flow in home assistant. The trigger to start my flow should be when Home assistants starts as default. I would like to have a "button" in the overview dashboard where I can disable and enable the flow. In my current setup I have looptimer node (value 4 hours interval) that start a trigger which do a http request that determines the value of the State and then determines the range from 1-4.  
The only way I know how to start the looptimer is inject node I trigger manually. I guess this is not the way to do this as I have to go to the node red menu to trigger this.  
I have seen some use a http request on HACS server start, but is this the best way?

---

<div class="post-metadata">

**Author:** ![hominidae](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hominidae/32/4174_2.png) [@hominidae](https://discourse.nodered.org/u/hominidae)\
**Post date:** [15 March 2020 14:26 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/8 "2020-03-15T14:26:27Z")

</div>

...I don't know Home Assistant, but based on this: [home-assistant.io/docs/mqtt/](http://home-assistant.io/docs/mqtt/) it can integrate with a MQTT-Broker. Do you already have one, or are able to install one in your setup?

I would not fokus on starting/stopping complete node-red or the individual flow but sending an event that would let/make the inject messages pass/stop, like i.e. in a gate note ([https://flows.nodered.org/node/node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)) or using a trigger node instead of the inject node, which can be controlled via a message...more here: [https://cookbook.nodered.org/#flow-control](https://cookbook.nodered.org/#flow-control)

---

<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:** [16 March 2020 00:34 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/9 "2020-03-16T00:34:00Z")

</div>

Home assistant is beyond me.

> [@hominidae](#):
>
> like i.e. in a gate note ([node-red-contrib-simple-gate (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-simple-gate)) or using a trigger node instead of the inject node,

I'd go for the latter.  
The `gate` node would not be of much use to you.  
There are nodes out there that can do what is needed.

`trigger` is not exactly my first choice though.

You need a node which looks at a value and determines if it is over a _threshold_ or not and creates a simpler message output like `0` and `1`.

---

<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:** [15 May 2020 00:34 UTC](https://discourse.nodered.org/t/flow-for-temperature-control/23117/10 "2020-05-15T00:34:01Z")

</div>

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