No output from code

I’ve got this code shown below, it reads all inputs. The inputs feed a join node, which feed a function node with this code, which feed a call service node, which works if I inject a payload to it. A debug on the join node suggests they are all reporting. A debug on the function does not give any output.

var target;
var night_temp_target = msg.payload.room_1_night_temp_target;
var temperature_target = msg.payload.room_1_temperature_target;
var temperature_tolerance = msg.payload.room_1_temperature_tolerance;
var bh1750_room2 = msg.payload.bh1750_room2
var room_1_average_temp = msg.payload.room_1_average_temp

if (bh1750_room2 <= 10){ 
 target = night_temp_target;
 }else{
 target = temperature_target;
  }
if (room_1_average_temp < (target - {temperature_tolerance})) 
{
 return [msg, null];
 }else{
 return [null, msg];
 }

Debug node on the function out just repeats the sensor inputs seemingly?

As expected then?
Your not doing anything with the message in the function node.

The only thing you do is return it with a null value in an array.

You need to explain and show what you are doing and what you are expecting.

Well I had some help with this code to get it this far, I have only just started with this and trying to work my way around it all.

I want it to read the bh1750, determine whether to use the night or day target, and use that for this code

(room_1_average_temp < (target - {temperature_tolerance})) 

to activate a svc call/switch which is tested and working.

Any advice on how to resolve this would be much appreciated.

Hello again :wink:,
so the function node is doing what is expected as you return the whole message that comes in with:
return msg; or return [msg, null];
Do the messages come out of the right output? So if the average temp is below the target - tolerance, it comes out of output 1 and if not output 2?

Small world. Keen to get this sorted as you can see!

I’m not sure, it doesn’t look like there is anything coming out of the function nodes. If I put a debug on the function it just repeats the data coming out of the join node, looking at other working flows, this seems to be normal.

This is what comes out of the function node debug. Seems to be taking the measurements fine.

/20/2021, 7:38:10 AMnode: f427f400.2c4de8
input_number.room_1_temperature_target : msg.payload : Object
object
sensor.bh1750_room2: 179.2
input_number.room_1_night_temp_target: 21
sensor.room_1_average_temp: 20.1
input_number.room_1_temperature_tolerance: 1
input_number.room_1_temperature_target: 17

There are debugs on the current states which usually report on or off in other working flows, but these don’t, does this suggest a fault at the function code?

Looks good. Are the messages coming out of the right outputs?
Did you configure two outputs?

Seemingly not. Yes, the outputs are configured, they work with inject nodes before the current state nodes.

You are using the domains before the sensors. It should look like this:

20.4.2021, 09:30:07node: 9215ef97.bf023
bh1750_room2 : msg.payload : Object
object
room_1_night_temperature_target: 17
room_1_temperature_target: 24
room_1_temperature_tolerance: 2
room_1_average_temp: 20
bh1750_room2: 179.2