Multi part Flow objects (solved)

Flow objects are killing me! I have read many tutorials about using flow objects and I'm stuck. I would like to use two different and changing variables in a simple temperature control function node. I've used the join node to get a set of numbers sorted by topic that looks like this

{"setTemp":233,"actualTemp":66}

and I'd like to use them in this:

const oHigh =5
const oLow =-5
let actualTemp = //topic actualTemp
let setTemp = //topic setTemp

if (setTemp >= oHigh+actualTemp) {
    return {payload: 0}
} else if (setTemp <= oLow+actualTemp) {
    return {payload: 1}
}
return msg;

Is there a way to do this with out setting up flow variables and counts and all the other stuff I don't think I need?

Lastly, my analog input from an arduino is giving a readings at about 100 per second, anyway to slow that down, either in the flow of at the arduino? It seams unnessasary, I tried the smooth node but that didn't work, the ideal would be to report the potentiometer setting once every 3-5 seconds. This is also the reason I don't want to add a count and store these values it seems like a waste. Thanks for the help

Do you mean that object is in the payload? If so then

let actualTemp = msg.payload.actualTemp

and similar for the other one.
Did you realise in your function that if the temperature lies inside the hysteresis band that it will return the message that you passed in, which may well confuse whatever comes next. Possibly you don't want to return anything in that case, in which case remove the return at the end. In fact I would have coded it

if (setTemp >= oHigh+actualTemp) {
   msg.payload = 0
} else if (setTemp <= oLow+actualTemp) {
    msg.payload = 1
} else {
    msg = null
}
return msg

Are you aware of node-red-contrib-ramp-thermostat? That provides a thermostat with variable hysteresis. It is also capable of generating ramps as input to the thermostat but you can just ignore that if you don't need it.
[Edit] Of course if you want decent control then you might like to consider node-red-contrib-pid

To slow your input down use a Delay node in Rate Limit mode with Drop Intermediate Messages set.

@Poodlepapa Or in the Arduino put a delay() in the loop then NR won't get too many things to process.

1 Like