Temp, humidity and current AC state flow

#1

New to NodeRed and not a programmer, trying to setup a flow where after polling the temperature and humidity sensors, and knowing the current state of the AC, I will

  • turn on the AC if the temp it >=28, but only if the AC is not currently "on"

  • turn on the AC if the temp >= 26 AND humidity is >=70, but only if the AC is not currently "on"

  • turn off the AC if the temperature is <=24, but only if the AC is not currently "off"

I can poll the temp/humidity sensors and the state of the AC unit (on or off), and I can turn the AC unit on and off, but I'm having difficultly understanding how to build this flow

#2

Take a look at this flow from the cookbook
https://cookbook.nodered.org/basic/route-on-context

which should explain the general idea. You can also do it in a function as described in the docs

#3

ukmoose, thanks! I've got this step, 2 switch nodes, one for temp and one for humidity, but what node would I then use to combine the output of the 2 switch nodes (temp and humidity), along with the current state mode of the AC, to then send a payload to the call service node to turn on the AC?

#4

To join temp and humidity i would look to use the JOIN node, there’s an example in the cookbook something along the lines of create a single flow from separate streams of messages

#5

Hi.

There are many ways to skin this cat. For example you could store each value in flow or global context. You could use join nodes. You could use function blocks etc.

What I'd suggest is just play, have fun and learn.

Drop an inject node (to generate test data). Drop a change node and debug node to see how it works. Drop a 2nd inject and wire both to a join node then to a debug node.

The important thing I find is getting people to understand the concept of passing the msg from node to node AND inspecting what happens to the msg after each node by using debug nodes.

Once a person understands the basics, they can quite literally throw this kind of node together in a few minutes.

One last thing, you find people on this forum very willing to help if you have given it a go yourself & got stuck. Post screenshots or for debug output, and post your flow (correctly formatted between ticks)

Good luck.

#6

Hey Steve-Mcl, thanks! This was my first flow using node-red...ever, it solved a problem I had so it was a bit challenging. I suspect I should be using flow/global variables, but that's beyond me at this point...maybe in the future. I ended up doing the following and it worked. I really like node-red, it takes the programming out (except for the function node). Looking forward to more flows.

3 Likes
#7

@bwanajag - just a point about your flow.
In the node is AC on? you exit from the top to turn on the AC, so I would assume thatt that is the NO response. On the node is AC off? you also exit from the top to turn off the AC. So you have similar nodes but the first ones top exit point is resulting from a 'NO' condition and the secont the top exit point is resulting from a 'YES' condition.

You might want to be consistent so that in the future it will make sense to you and remember to document your flow - the Comment node is great to put over a section of code explaining that section.

I hope you keep enjoying building flows! :grin: