# Function tried to send a message of type boolean

**URL:** https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340
**Category:** General
**Created:** [9 January 2022 10:57 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340 "2022-01-09T10:57:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hermiot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hermiot/32/28140_2.png) [@hermiot](https://discourse.nodered.org/u/hermiot)
#### Post date: [9 January 2022 10:57 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/1 "2022-01-09T10:57:29Z")

</div>

Hi,

I'm trying to build up a logic to control my ventilator.  
Only one of the four switches can be active at one time. So I'm trying to send the message to activate/deactivate the relays with a function.

```auto
var L1_on = msg.payload.On === true;
var L1_off = {payload:"stufe1"};
var L2_on = {payload:"stufe2"};
var L2_off = {payload:"stufe2"};
var L3_on = {payload:"stufe3"};
var L3_off = {payload:"stufe3"};
var L4_on = {payload:"stufe4"};
var L4_off = {payload:"stufe4"};

var topic=msg.topic;
if (topic=="stufe1"){
    if(msg.payload.On == true){
    return L1_on;
    } 
} else if (topic=="stufe2"){
    if(msg.payload.On == true){
    return L2_on;
    }
} else if (topic=="stufe3"){
    if(msg.payload.On == true){
    return L3_on;
    }
} else if (topic=="stufe4"){
    if(msg.payload.On == true){
    return L4_on;
    }
}

```

It would help a lot, if the vars contain the corresponding messages so I can send them as bulk.  
I.e.  
`return [L1_on, L2_off, L3_off, L4_off]`  
if button 1 is pressed or  
`return [L1_off, L2_on, L3_off, L4_off]`  
if button 2 is pressed and so on.

How can I assign the variables a bool message as objects?  
I attached a picture of the message I want to store in var L1\_on.

![Ohne Titel](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fcd9a99ba0ffdbedb406ecb1b2d9d501f14ea34b.jpeg)

I tried `var L1_on = msg.payload.On === true;` but this ends up in an error (Function tried to send a message of type boolean).

Thank you very much!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 January 2022 10:59 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/2 "2022-01-09T10:59:26Z")

</div>

> [@hermiot](#):
>
> ```auto
> var L1_on = msg.payload.On === true;
> 
> ```

This will make a Boolean value.

Maybe you meant

```auto
var L1_on = {payload: msg.payload.On === true}

```

---

<div class="post-metadata">

### Author: ![hermiot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hermiot/32/28140_2.png) [@hermiot](https://discourse.nodered.org/u/hermiot)
#### Post date: [9 January 2022 11:02 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/3 "2022-01-09T11:02:47Z")

</div>

> [@Steve-Mcl](#):
>
> `{payload: msg.payload.On === true}`

This only returns  
msg.payload : boolean  
true

Is there a way to send the message like defined in the picture without using the change node?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 January 2022 11:09 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/4 "2022-01-09T11:09:37Z")

</div>

> [@hermiot](#):
>
> Is there a way to send the message like defined in the picture without using the change node

Of course

```auto
var L1_on = {
  payload: {
    On: msg.payload.On === true
  }
}

```

Though I must point out it is good practice to keep the original msg object (just update its payload) as there may be properties in it that are required down stream.

---

<div class="post-metadata">

### Author: ![hermiot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hermiot/32/28140_2.png) [@hermiot](https://discourse.nodered.org/u/hermiot)
#### Post date: [9 January 2022 11:24 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/5 "2022-01-09T11:24:59Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> var L1_on = {
> payload: {
> On: msg.payload.On === true
> }
> }
> 
> ```

\o/ Thank you! \o/

---

<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: [23 January 2022 11:25 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-boolean/56340/6 "2022-01-23T11:25:49Z")

</div>

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