# Help with the function node

**URL:** https://discourse.nodered.org/t/help-with-the-function-node/89603
**Category:** General
**Tags:** function-node
**Created:** [18 July 2024 15:05 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603 "2024-07-18T15:05:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 15:05 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/1 "2024-07-18T15:05:02Z")

</div>

Hello.I'm new and I need some advice-help with my node function. I can't write the code to make it work properly, it always sends the value from pvpower.it should work as follows: I have three input nodes, namely soc, pvpower, temperature. These nodes enter the function node where I try to create these oversights:the value from pvpower will be sent only if the following conditions are met:if the soc\>80 and the temperature\<80 will send a value from PVPOWER. If it is soc\>80 and the temperature is \>80, it will only send the value off.If the SOC\>80 and temperature is \<80, it will send a value from PVPOWER

---

<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: [18 July 2024 15:08 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/2 "2024-07-18T15:08:48Z")

</div>

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Each msg entering a `function` node has no idea of the other msgs sent to it.

Take a look at the join node if all three msgs need to be combined.

(If I’m wrong about what you are trying, I apologize- I have a head cold.)

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 15:18 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/3 "2024-07-18T15:18:10Z")

</div>

let pvpower = msg.payload;

if (msg.payload.temperature \> 80 && msg.payload.soc \< 80) {  
msg.payload = "vypnut";  
} else if (msg.payload.temperature \< 80 && msg.payload.soc \< 80) {  
msg.payload = "vypnutSoc";  
} else if (msg.payload.temperature \< 80 && msg.payload.soc \> 80) {  
msg.payload = "pvpower";  
}

return msg; I apologize for any mistakes, but I'm writing here through the translator 🙂 I'm going to try to write it again.If the SOC values are \>80 and the temperature is \>80, it will send a message ,turn off,.If the SOC values are\<80 and temperature \>80 will send the message ,turn off,.If the SOC\>80 and the temperature is \<80, it will only send a message/value from PVPOWER.I can't achieve this, I still have all the values at the exit from the node and not the specific ones according to the conditions.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [18 July 2024 15:57 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/4 "2024-07-18T15:57:16Z")

</div>

> [@migel](#):
>
> These nodes enter the function node

A key concept of node-red is that every message will be handled separately.

When you want to check for both `msg.payload.soc` and `msg.payload.temperature` - these properties need to exist in `msg.payload.<prop>` - as it is not aware of other messages.

So if you have 3 values coming from 3 different nodes, you will need to combine them first.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [18 July 2024 16:04 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/5 "2024-07-18T16:04:38Z")

</div>

Hello and welcome to the Node-RED forum.

Could you post the flow you have created so far - so people can explain how to "join" the messages, you have arriving from various sources, together?

This is a classic situation faced by a lot of people who are new to Node-RED.

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 16:27 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/6 "2024-07-18T16:27:57Z")

</div>

```auto
[
    {
        "id": "117b79b80e9dee47",
        "type": "victron-input-battery",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.battery/277",
        "path": "/Soc",
        "serviceObj": {
            "service": "com.victronenergy.battery/277",
            "name": "Baterka"
        },
        "pathObj": {
            "path": "/Soc",
            "type": "float",
            "name": "State of charge (%)"
        },
        "name": "soc",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 410,
        "y": 240,
        "wires": [
            [
                "1eacab5dd3e2d5e2"
            ]
        ]
    },
    {
        "id": "6ca94153591f21e8",
        "type": "victron-input-temperature",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.temperature/24",
        "path": "/Temperature",
        "serviceObj": {
            "service": "com.victronenergy.temperature/24",
            "name": "Akumulacka vrch"
        },
        "pathObj": {
            "path": "/Temperature",
            "type": "float",
            "name": "Temperature (°C)"
        },
        "name": "temperature",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 430,
        "y": 360,
        "wires": [
            [
                "1eacab5dd3e2d5e2"
            ]
        ]
    },
    {
        "id": "1eacab5dd3e2d5e2",
        "type": "function",
        "z": "7bb4b982f37a1f91",
        "name": "function 13",
        "func": "let pvpower = msg.payload;\n\nif (msg.payload.temperature > 80 && msg.payload.soc < 80) {\n msg.payload = \"vypnut\";\n} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {\n msg.payload = \"vypnutSoc\";\n} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {\n msg.payload = \"pvpower\";\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 630,
        "y": 300,
        "wires": [
            [
                "0aadc31f18dd37ed"
            ]
        ]
    },
    {
        "id": "e6f7416282436479",
        "type": "victron-input-solarcharger",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.solarcharger/278",
        "path": "/Yield/Power",
        "serviceObj": {
            "service": "com.victronenergy.solarcharger/278",
            "name": "Epever 8415AN"
        },
        "pathObj": {
            "path": "/Yield/Power",
            "type": "float",
            "name": "PV Power (W)"
        },
        "name": "pvpower",
        "onlyChanges": false,
        "roundValues": "0",
        "x": 420,
        "y": 300,
        "wires": [
            [
                "1eacab5dd3e2d5e2"
            ]
        ]
    },
    {
        "id": "0aadc31f18dd37ed",
        "type": "debug",
        "z": "7bb4b982f37a1f91",
        "name": "debug 32",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 240,
        "wires": []
    }
]

```

There is complet flow

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [18 July 2024 18:22 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/7 "2024-07-18T18:22:54Z")

</div>

Your flow is corrupted as you have not posted the code in the correct manner for forum to parse correctly

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

Two forum members have noted that you need to join the messages as they are coming from different node, so the messages do not arrive in your function at the same time.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [18 July 2024 18:39 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/8 "2024-07-18T18:39:20Z")

</div>

Here is your function with comments:

```auto
// The below line isn't needed, does nothing
let pvpower = msg.payload;

// The below lines set `msg.payload` to equal the string of characters "vypnut", "vypnutSoc", or "pvpower"
if (msg.payload.temperature > 80 && msg.payload.soc < 80) {
    msg.payload = "vypnut";

} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {
    msg.payload = "vypnutSoc";

} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {
    msg.payload = "pvpower";
    
}

// this sends the msg to the next node
return msg;

```

If that is not the intended behavior, please try to state what you intend it to do?

Because it sounds like you intend to set `msg.payload` or the entire `msg` object to other values/properties not those strings.

```auto
// The below lines set `msg.payload` to equal the incoming values in `msg.payload.vypnut`, `msg.payload.vypnutSoc`, or `msg.payload.pvpower`
if (msg.payload.temperature > 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnut;

} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnutSoc;

} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {
    msg.payload = msg.payload.pvpower;
    
}

// this sends the msg to the next node
return msg;

```

Also your debug node is set to only show the `msg.payload`, I find it useful when debugging functions to set the debug node to output `complete msg object` to better analyze what is happening.

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 19:36 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/9 "2024-07-18T19:36:31Z")

</div>

From this function node, it will go further to the switch node, where there are already other conditions based on the performance from PVPOWER. That's why I only need to get the pvpower value there, but only if the conditions I wrote are met. If the conditions were not met and the function node would only send a message to turn off or offSOC, then it would also be further processed

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [18 July 2024 19:55 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/10 "2024-07-18T19:55:04Z")

</div>

> [@migel](#):
>
> I only need to get the pvpower value

Then it sounds like the second function I wrote is what you need, it will only send the value of `msg.payload.pvpower` as the `msg.payload` that leaves the function node if the `temperature` is less than `80` and the `soc` is greater than `80`.

To add a condition for `no conditions are met` you can just use an else statement at the end of the if function like:

```auto
// The below lines set `msg.payload` to equal the incoming values in `msg.payload.vypnut`, `msg.payload.vypnutSoc`, or `msg.payload.pvpower`
if (msg.payload.temperature > 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnut;

} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnutSoc;

} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {
    msg.payload = msg.payload.pvpower;
    
} else {
    // This only triggers if no conditions are met
    // The below line might need a different value depending on your use case
    msg.payload = "turn off";
}

// this sends the msg to the next node
return msg;

```

However, no conditions are met only if both values are greater than `80`  
EDIT: or if any of those properties is `undefined`

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 20:24 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/11 "2024-07-18T20:24:16Z")

</div>

With this code of yours, it still sends a Turn Off for all 3 entry topics.  
but I wrote the conditions as they are, and that if the temperature is more than 80 then it will not send any other messages but only turn off.If the soc is less than 80 it will not send any message only the message turn off the soc. If the temperature is less than 80 and the soc is greater than 80, it will only send messages/values from the controller because this value changes and in the next switch node the outputs are adjusted based on this value as it changes.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [18 July 2024 20:48 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/12 "2024-07-18T20:48:58Z")

</div>

If you are sending 3 separate msg objects then they are NOT aware of each other and need to be joined.

It sounds like you are sending messages that are formatted like this:

```auto
msg = {
    "payload": {
        "vypnut": "value"
    }
}

msg = {
    "payload": {
        "vypnutSoc": "value"
    }
}

msg = {
    "payload": {
        "pvpower": "value"
    }
}

```

They need to be combined into one message object like this so the function can perform correctly:

```auto
msg = {
    "payload": {
        "vypnut": "value",
        "vypnutSoc": "value",
        "pvpower": "value"
    }
}

```

You can combine the messages with a `join` node from the core Node-RED nodes placed before your function node. The `join` node will likely need to be set to the following settings.  
Mode: manual  
Combine each: msg.payload  
to create: a merged object  
uncheck the boxes  
send the message after `3` parts

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [18 July 2024 21:12 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/13 "2024-07-18T21:12:13Z")

</div>

thank you very much, I will try tomorrow, I turned off my computer a while ago and I don't want to turn it on and read.  
but I still ask..: if I create it according to what you wrote to me that at the beginning there will be three nodes soc, temperature and pvpower, then those nodes will send msg.values ​​to the join node, which I will set up as you wrote and from the join node it will go there is already a function in node where I have to write all the msg.payload together in the code you sent above?..I will try tomorrow and write it here.  
I thought that this function would change the incoming values ​​according to those conditions and send only one specific value to the output that corresponds to the given fulfilled condition.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [18 July 2024 22:10 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/14 "2024-07-18T22:10:53Z")

</div>

> [@migel](#):
>
> there is already a function in node where I have to write all the msg.payload together in the code you sent above?

After the join node is the function node with the following code:

```auto
// The below lines set `msg.payload` to equal the incoming values in `msg.payload.vypnut`, `msg.payload.vypnutSoc`, or `msg.payload.pvpower`
if (msg.payload.temperature > 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnut;

} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {
    msg.payload = msg.payload.vypnutSoc;

} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {
    msg.payload = msg.payload.pvpower;
    
} else {
    // This only triggers if no conditions are met
    // The below line might need a different value depending on your use case
    msg.payload = "turn off";
}

// this sends the msg to the next node
return msg;

```

That code is designed to work with the combined msg from the join node.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [19 July 2024 06:14 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/15 "2024-07-19T06:14:22Z")

</div>

Here's a simple example to "join" the values from three inputs that arrive at different times.  
The contents of the resultant object can then be used in your function node.  
 ![friday_join_A](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/dd3d83f35cb16c7ea113a5b62f2cfd35d2eaeca3.png)

![friday_join_B](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f864d57b433e25e76ab3d57baeb229f4c45856ed.png)

Here's the Node-RED flow you can import and try out.

```auto
[{"id":"7b8698059fd2bbef","type":"tab","label":"Join_Example","disabled":false,"info":"","env":[]},{"id":"684ac4402a1bd08b","type":"inject","z":"7b8698059fd2bbef","name":"","props":[{"p":"payload.temperature","v":"21","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","x":230,"y":220,"wires":[["15bef60d2e5de063"]]},{"id":"5ed32446c518aa4e","type":"inject","z":"7b8698059fd2bbef","name":"","props":[{"p":"payload.soc","v":"6","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"soc","x":210,"y":260,"wires":[["15bef60d2e5de063"]]},{"id":"084672b6c8770d95","type":"inject","z":"7b8698059fd2bbef","name":"","props":[{"p":"payload.pvpower","v":"3","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pvpower","x":220,"y":300,"wires":[["15bef60d2e5de063"]]},{"id":"15bef60d2e5de063","type":"join","z":"7b8698059fd2bbef","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":260,"wires":[["3ead3536dc67e2d8"]]},{"id":"3ead3536dc67e2d8","type":"debug","z":"7b8698059fd2bbef","name":"combined_object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":260,"wires":[]},{"id":"27ed164bb6f81c44","type":"comment","z":"7b8698059fd2bbef","name":"Simulate three inputs","info":"","x":240,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 July 2024 06:55 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/16 "2024-07-19T06:55:36Z")

</div>

> [@migel](#):
>
> I thought that this function would change the incoming values ​​according to those conditions and send only one specific value to the output that corresponds to the given fulfilled condition.

There is a lot of confusion about exactly what is happening in your system. The problem is that we do not know exactly what is being fed to your function. Please attach a Debug node showing what is going _into_ your function and copy/paste here what you see., Then we will know exactly what you need to do.

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [19 July 2024 08:16 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/17 "2024-07-19T08:16:56Z")

</div>

```auto
[
    {
        "id": "117b79b80e9dee47",
        "type": "victron-input-battery",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.battery/277",
        "path": "/Soc",
        "serviceObj": {
            "service": "com.victronenergy.battery/277",
            "name": "Baterka"
        },
        "pathObj": {
            "path": "/Soc",
            "type": "float",
            "name": "State of charge (%)"
        },
        "name": "soc",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 70,
        "y": 360,
        "wires": [
            [
                "4855f3e6df26aa74"
            ]
        ]
    },
    {
        "id": "6ca94153591f21e8",
        "type": "victron-input-temperature",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.temperature/24",
        "path": "/Temperature",
        "serviceObj": {
            "service": "com.victronenergy.temperature/24",
            "name": "Akumulacka vrch"
        },
        "pathObj": {
            "path": "/Temperature",
            "type": "float",
            "name": "Temperature (°C)"
        },
        "name": "temperature",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 90,
        "y": 420,
        "wires": [
            [
                "4855f3e6df26aa74"
            ]
        ]
    },
    {
        "id": "e6f7416282436479",
        "type": "victron-input-solarcharger",
        "z": "7bb4b982f37a1f91",
        "service": "com.victronenergy.solarcharger/278",
        "path": "/Yield/Power",
        "serviceObj": {
            "service": "com.victronenergy.solarcharger/278",
            "name": "Epever 8415AN"
        },
        "pathObj": {
            "path": "/Yield/Power",
            "type": "float",
            "name": "PV Power (W)"
        },
        "name": "pvpower",
        "onlyChanges": false,
        "roundValues": "0",
        "x": 80,
        "y": 480,
        "wires": [
            [
                "4855f3e6df26aa74"
            ]
        ]
    },
    {
        "id": "20435912dccc97e2",
        "type": "debug",
        "z": "7bb4b982f37a1f91",
        "name": "debug 34",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 540,
        "wires": []
    },
    {
        "id": "c06643a5c5e1446c",
        "type": "inject",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "temperature",
        "payload": "81",
        "payloadType": "num",
        "x": 120,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "316e028858f147aa",
        "type": "inject",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "soc",
        "payload": "78",
        "payloadType": "num",
        "x": 90,
        "y": 580,
        "wires": [
            []
        ]
    },
    {
        "id": "100dbf9b8f2e9d37",
        "type": "function",
        "z": "7bb4b982f37a1f91",
        "name": "function 26",
        "func": "// The below lines set `msg.payload` to equal the incoming values in `msg.payload.vypnut`, `msg.payload.vypnutSoc`, or `msg.payload.pvpower`\nif (msg.payload.temperature > 80 && msg.payload.soc < 80) {\n msg.payload = msg.payload.vypnut;\n\n} else if (msg.payload.temperature < 80 && msg.payload.soc < 80) {\n msg.payload = msg.payload.vypnutSoc;\n\n} else if (msg.payload.temperature < 80 && msg.payload.soc > 80) {\n msg.payload = msg.payload.pvpower;\n \n}\n\n// this sends the msg to the next node\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 460,
        "wires": [
            [
                "20435912dccc97e2"
            ]
        ]
    },
    {
        "id": "4855f3e6df26aa74",
        "type": "join",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 290,
        "y": 440,
        "wires": [
            [
                "100dbf9b8f2e9d37"
            ]
        ]
    }
]

```

I'm hoping that the flow has already been well copied... I need to receive messages from pvpower at the output from the function but if either the temperature is more than 80 or soc less than 80, it won't send anything, just turn it off- so that it doesn't send the value from the controller further to the switch.I hope you understand what I mean...

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [19 July 2024 08:22 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/18 "2024-07-19T08:22:33Z")

</div>

```auto
[
    {
        "id": "36716a5223beff25",
        "type": "debug",
        "z": "7bb4b982f37a1f91",
        "name": "Spirala1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1580,
        "y": 260,
        "wires": []
    },
    {
        "id": "1511e1b371de1637",
        "type": "switch",
        "z": "7bb4b982f37a1f91",
        "name": "AN hore",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "1400",
                "vt": "num"
            },
            {
                "t": "gte",
                "v": "2700",
                "vt": "num"
            },
            {
                "t": "gte",
                "v": "3600",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "1250",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "2300",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "3500",
                "vt": "num"
            },
            {
                "t": "cont",
                "v": "vypnut",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 7,
        "x": 900,
        "y": 360,
        "wires": [
            [
                "e9f4977478ac912a"
            ],
            [
                "75a39dd2fc6ef851"
            ],
            [
                "182040fcdab23e38"
            ],
            [
                "d3f7bfc0673ff796"
            ],
            [
                "8614a7dae0045d5f"
            ],
            [
                "3be2887da9e71f59"
            ],
            [
                "d3f7bfc0673ff796"
            ]
        ]
    },
    {
        "id": "e9f4977478ac912a",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "zapni spiralu 1",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "1",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1140,
        "y": 220,
        "wires": [
            [
                "24fcf09cfc3b4451"
            ]
        ]
    },
    {
        "id": "75a39dd2fc6ef851",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "zapni spiralu 2",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "1",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1140,
        "y": 280,
        "wires": [
            [
                "f26ddf7274948a65"
            ]
        ]
    },
    {
        "id": "182040fcdab23e38",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "zapni spiralu 3",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "1",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1140,
        "y": 340,
        "wires": [
            [
                "4b41ab92ae16e9ca"
            ]
        ]
    },
    {
        "id": "25593a8b0d34c2f5",
        "type": "debug",
        "z": "7bb4b982f37a1f91",
        "name": "Spirala2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1580,
        "y": 380,
        "wires": []
    },
    {
        "id": "b628eef3ff1a26ba",
        "type": "debug",
        "z": "7bb4b982f37a1f91",
        "name": "Spirala3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1580,
        "y": 500,
        "wires": []
    },
    {
        "id": "d3f7bfc0673ff796",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "vypni vsetko",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1130,
        "y": 420,
        "wires": [
            [
                "24fcf09cfc3b4451",
                "f26ddf7274948a65",
                "4b41ab92ae16e9ca"
            ]
        ]
    },
    {
        "id": "3be2887da9e71f59",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "vypni 3",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1140,
        "y": 540,
        "wires": [
            [
                "4b41ab92ae16e9ca"
            ]
        ]
    },
    {
        "id": "8614a7dae0045d5f",
        "type": "change",
        "z": "7bb4b982f37a1f91",
        "name": "vypni 2",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1140,
        "y": 480,
        "wires": [
            [
                "f26ddf7274948a65"
            ]
        ]
    },
    {
        "id": "24fcf09cfc3b4451",
        "type": "rbe",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1410,
        "y": 260,
        "wires": [
            [
                "36716a5223beff25"
            ]
        ]
    },
    {
        "id": "f26ddf7274948a65",
        "type": "rbe",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1410,
        "y": 380,
        "wires": [
            [
                "25593a8b0d34c2f5"
            ]
        ]
    },
    {
        "id": "4b41ab92ae16e9ca",
        "type": "rbe",
        "z": "7bb4b982f37a1f91",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1410,
        "y": 500,
        "wires": [
            [
                "b628eef3ff1a26ba"
            ]
        ]
    }
] 

```

and this is the flow where the output with the function node will go (but here I'm not sure if I have the filters set up well, as I've been struggling with the function node for two weeks) 🙂

---

<div class="post-metadata">

### Author: ![migel](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@migel](https://discourse.nodered.org/u/migel)
#### Post date: [19 July 2024 08:28 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/19 "2024-07-19T08:28:12Z")

</div>

And I wanted more of those conditions at first 😉 and I'm still struggling with only three 🙂

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [19 July 2024 09:10 UTC](https://discourse.nodered.org/t/help-with-the-function-node/89603/20 "2024-07-19T09:10:56Z")

</div>

Try this version... it should implement your stated requirement...  
_I need to receive messages from pvpower at the output from the function but if either the temperature is more than 80 or soc less than 80, it won't send anything_

 ![friday_join_C](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04d2209ba3637ab0ca29346a971166f0dc8b776b.png)

```auto
[{"id":"7b8698059fd2bbef","type":"tab","label":"Join_Example","disabled":false,"info":"","env":[]},{"id":"684ac4402a1bd08b","type":"inject","z":"7b8698059fd2bbef","name":"temperature = 80","props":[{"p":"payload.temperature","v":"80","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","x":220,"y":140,"wires":[["15bef60d2e5de063"]]},{"id":"5ed32446c518aa4e","type":"inject","z":"7b8698059fd2bbef","name":"soc = 80","props":[{"p":"payload.soc","v":"81","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"soc","x":200,"y":260,"wires":[["15bef60d2e5de063"]]},{"id":"084672b6c8770d95","type":"inject","z":"7b8698059fd2bbef","name":"pvpower = 3","props":[{"p":"payload.pvpower","v":"3","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pvpower","x":210,"y":380,"wires":[["15bef60d2e5de063"]]},{"id":"15bef60d2e5de063","type":"join","z":"7b8698059fd2bbef","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":260,"wires":[["c18b8624139b5775","efa07285342ca10a"]]},{"id":"3ead3536dc67e2d8","type":"debug","z":"7b8698059fd2bbef","name":"combined_object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":260,"wires":[]},{"id":"27ed164bb6f81c44","type":"comment","z":"7b8698059fd2bbef","name":"Simulate three inputs","info":"","x":240,"y":60,"wires":[]},{"id":"c18b8624139b5775","type":"function","z":"7b8698059fd2bbef","name":"OR function","func":"if ((msg.payload.temperature.temperature > 80) || (msg.payload.soc.soc < 80)) {\n return null;\n}\n\nelse {\n msg.payload = msg.payload.pvpower.pvpower;\n return msg;\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":260,"wires":[["3ead3536dc67e2d8"]]},{"id":"f491dbeb5e49bb28","type":"inject","z":"7b8698059fd2bbef","name":"temperature = 81","props":[{"p":"payload.temperature","v":"81","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","x":220,"y":180,"wires":[["15bef60d2e5de063"]]},{"id":"c3be77599c673b66","type":"inject","z":"7b8698059fd2bbef","name":"soc = 79","props":[{"p":"payload.soc","v":"79","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"soc","x":200,"y":300,"wires":[["15bef60d2e5de063"]]},{"id":"efa07285342ca10a","type":"debug","z":"7b8698059fd2bbef","name":"debug 3430","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":320,"wires":[]}]

```

[Next page](https://discourse.nodered.org/t/help-with-the-function-node/89603.md?page=2)
