# Help with \`trigger\` node and sending messages

**URL:** https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084
**Category:** General
**Created:** [27 February 2022 22:17 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084 "2022-02-27T22:17:20Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [27 February 2022 22:17 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/1 "2022-02-27T22:17:20Z")

</div>

This is odd as the machine on which it seems to work is older than the one on which I want it to work.

Basically I want to send two messages.

(Cut down version - and I hope it does/will work)

```auto
[{"id":"5fd21b95c3b19877","type":"trigger","z":"0918ee609bf69fc7","name":"","op1":"{\"payload\":\"this is the payload\",\"background_colour\":\"black\"}","op2":"{\"payload\":\"this is the payload\",\"background_colour\":\"blue\"}","op1type":"json","op2type":"json","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":2140,"y":360,"wires":[["c36a75c2bc55a97f"]]},{"id":"dfe818a695cd483d","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1970,"y":360,"wires":[["5fd21b95c3b19877"]]},{"id":"c36a75c2bc55a97f","type":"debug","z":"0918ee609bf69fc7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2340,"y":360,"wires":[]}]

```

I send a message with a `payload` and `background colour`.  
(That'll go into a `text` node)

The code as posted _works_ as in there are no errors with any of the nodes.

A **NEWER** version of NR on another machine doesn't like it.

☹

```auto
[{"id":"7d53d9a7865b9b30","type":"inject","z":"b7458cdd.85349","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1460,"y":1320,"wires":[["4aec9fd36a3168a6"]]},{"id":"4aec9fd36a3168a6","type":"trigger","z":"b7458cdd.85349","name":"","op1":"\"payload\":'<font color = \"lime\" <i class=\"fa fa-bullseye fa-2x\"></i>',\"colour\":\"red\"","op2":"<font color = \"black\" <i class=\"fa fa-bullseye fa-2x\"></i>","op1type":"json","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1450,"y":1400,"wires":[["3b76a45479264cad","092ca42c17689aa5"]]},{"id":"092ca42c17689aa5","type":"debug","z":"b7458cdd.85349","name":"Notification","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1670,"y":1340,"wires":[]}]

```

I've tried the leading / ending `{ }`. No change.  
The `trigger` node doesn't like something.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 February 2022 22:54 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/2 "2022-02-27T22:54:09Z")

</div>

This is your trigger node:

 ![Untitled 7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83835b5490e603eb50ed216323b4326dc807ec00.jpeg)

The red border round the first value to send shows that it's invalid.

But can you explain:

1. Why are you constructing an object {payload: "blah", color: "red"} instead of sending a string (which will be sent as msg.payload)?
2. What is the **colour: "red"** bit supposed to achieve?  
ps Does CSS recognise "colour" as "color"?
3. The string to be sent after 5 seconds works perfectly well to display the icon in black. Why not use a similar string for the first message?

Does this do what you are trying to achieve?  
(my suggestion hidden till you answer the questions 🙂 )

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [27 February 2022 23:03 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/3 "2022-02-27T23:03:19Z")

</div>

> [@jbudd](#):
>
> Why are you constructing an object

Because I don't know how else to do it.

The `red` is for the background colour.

I've tried sending strings, but they don't seem to work either.  
But I'll put that down to my now knowing that either.

I'll see if I can dig out the _eater egg_ in your reply.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [27 February 2022 23:16 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/4 "2022-02-27T23:16:31Z")

</div>

I found a _cheat_ way around the problem.

Set the `trigger` node to send the second message out a second port.

Then I just stick two `change` nodes and all is sweet.

Not the most elegant way, but it works.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 February 2022 23:24 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/5 "2022-02-27T23:24:57Z")

</div>

If you click on the pencil at the top of my reply (which shows I've edited it) you should be able to see my suggested way round the problem.

I'm trying to compose a reply to "Because I don't know how else to do it", trying to make it both correct and clear for my benefit and hopefully yours!

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [27 February 2022 23:43 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/6 "2022-02-27T23:43:09Z")

</div>

Ok, back to your edited post.

I type this in.... (as far as I can see it is the same as what you did)

 ![Screenshot from 2022-02-28 10-39-53](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/1963f424d4af34f59ba21460cfc2fa981d9fac27.png)

I really hope that at this level space are important.

So, that's looking good.

(Oh, the `colour` thing. I'm hoping that is `msg.colour` and I use that in/on the `button` and put `{{msg.colour}}`.

So I typed that in.

Move the mouse off the line.

 ![Screenshot from 2022-02-28 10-39-57](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f00355e4f2d41c2fd4f8d0ab3ff95c65ac38412.png)

I must need glasses. 😢

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 February 2022 23:52 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/7 "2022-02-27T23:52:38Z")

</div>

Sorry, that's not what I did, this is:

```auto
[
    {
        "id": "7d53d9a7865b9b30",
        "type": "inject",
        "z": "4be637d7361f36e2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 140,
        "wires": [
            [
                "4aec9fd36a3168a6"
            ]
        ]
    },
    {
        "id": "4aec9fd36a3168a6",
        "type": "trigger",
        "z": "4be637d7361f36e2",
        "name": "",
        "op1": "<font color = \"lime\" <i class=\"fa fa-bullseye fa-2x\"></i>",
        "op2": "<font color = \"black\" <i class=\"fa fa-bullseye fa-2x\"></i>",
        "op1type": "str",
        "op2type": "str",
        "duration": "5",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 360,
        "y": 140,
        "wires": [
            [
                "801c934030ec1f04"
            ]
        ]
    },
    {
        "id": "801c934030ec1f04",
        "type": "ui_text",
        "z": "4be637d7361f36e2",
        "group": "0b2c5ed94dd5b6dc",
        "order": 5,
        "width": 0,
        "height": 0,
        "name": "Starts green, goes black",
        "label": "Starts green, goes black",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "x": 570,
        "y": 140,
        "wires": []
    },
    {
        "id": "0b2c5ed94dd5b6dc",
        "type": "ui_group",
        "name": "Demo",
        "tab": "4311353dbffb7643",
        "order": 1,
        "disp": true,
        "width": "10",
        "collapse": false,
        "className": ""
    },
    {
        "id": "4311353dbffb7643",
        "type": "ui_tab",
        "name": "Demo",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

Ah, I understand about msg.colour now.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [27 February 2022 23:57 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/8 "2022-02-27T23:57:14Z")

</div>

Ok, thanks.

With you now.

This is what I got the _harder_ way that I mentioned.

If all that can be done in the `trigger` node, good.

But... Not holding my breath.

```auto
[{"id":"4aec9fd36a3168a6","type":"trigger","z":"b7458cdd.85349","g":"998e52a0534c7870","name":"","op1":"A","op2":"B","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":1120,"y":1360,"wires":[["e874c99fba05efc3"],["a1594ff0666a357a"]]},{"id":"e874c99fba05efc3","type":"change","z":"b7458cdd.85349","g":"998e52a0534c7870","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"<font color = \"black\" <i class=\"fa fa-thumbs-o-up fa-2x\"></i>","tot":"str"},{"t":"set","p":"background","pt":"msg","to":"lime","tot":"str"},{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1165,"y":1400,"wires":[["3b76a45479264cad","092ca42c17689aa5"]],"l":false},{"id":"a1594ff0666a357a","type":"change","z":"b7458cdd.85349","g":"998e52a0534c7870","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"<font color = \"black\" <i class=\"fa fa-bullseye fa-2x\"></i>","tot":"str"},{"t":"set","p":"background","pt":"msg","to":"red","tot":"str"},{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1165,"y":1430,"wires":[["3b76a45479264cad","092ca42c17689aa5"]],"l":false},{"id":"3b76a45479264cad","type":"ui_button","z":"b7458cdd.85349","g":"998e52a0534c7870","name":"","group":"55dfcd20.774cec","order":2,"width":"1","height":"1","passthru":false,"label":"{{msg.payload}}","tooltip":"","color":"","bgcolor":"{{background}}","icon":"","payload":"","payloadType":"str","topic":"","x":1280,"y":1410,"wires":[[]]},{"id":"55dfcd20.774cec","type":"ui_group","name":"Machine state control","tab":"7b4d3366.3e985c","order":6,"disp":true,"width":"4","collapse":false},{"id":"7b4d3366.3e985c","type":"ui_tab","name":"Alarmclock Telemetry","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

And I am sorry for wasting your time and maybe not being clear.  
I do appreciate it though. I really hope I learn from it. Just rocks aren't too accommodating to new information (I have rocks in my head - so I am told)

I am confused about _pasting only what is needed_ and keeping the examples simple.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 February 2022 00:03 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/9 "2022-02-28T00:03:21Z")

</div>

OK then, as a hopefully useful sideline

Here is a function node with three different ways of constructing a message with a javascript object in the payload

```auto
// First method - create a new, empty message then give it a payload
var newmsg1 = {};
newmsg1.payload = {"temp": 27, "humidity": 85};
node.send(newmsg1);

// Second method - create a new message all in one line
var newmsg2 = {"payload": {"temp": 27, "humidity": 85}}; 
node.send(newmsg2);

// Third method - use the existing message but change the payload
msg.payload = {};
msg.payload.temp = 27;
msg.payload.humidity = 85;
return msg;

```

I think they are all perfectly valid.

The second approach is the one you seem to prefer, but I find it confusing and it always takes me several tries to get the quotes and brackets right.

So I will usually use the third method because it has the absolute minimum of quotes and brackets and I don't need to declare a new variable for the message.

Occasionally I opt for the first method if it's a fairly simple javascript object.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [28 February 2022 00:06 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/10 "2022-02-28T00:06:53Z")

</div>

I'm ok with that... But I don't know how that applies to getting a complicated message out of the `trigger` node.

I am suspicious I was just asking too much of it, and I - now - accept this as probably the reason it wasn't working as I wanted.  
(Because the `trigger` node send a `msg.payload` and not a `msg.` - yes?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 February 2022 00:14 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/11 "2022-02-28T00:14:19Z")

</div>

You are not wasting my time.  
Trying to answer questions in the forum helps me learn and I often discover things I misunderstood before.

Your solution using change nodes to set msg.payload, msg.background and msg.enabled seems to work.  
There are several other ways to achieve the same thing but yours is as good as any other.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [28 February 2022 00:15 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/12 "2022-02-28T00:15:48Z")

</div>

But the`trigger` node.... It's output... It is `msg.payload....` and not `msg.......` as I was thinking originally when trying to send the complicated `{ }` (and/or) text strings with other attributes.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 February 2022 00:16 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/13 "2022-02-28T00:16:45Z")

</div>

As far as I know the trigger node can only set msg.payload. A change node is a good place to set multiple message properties.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [28 February 2022 00:17 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/14 "2022-02-28T00:17:17Z")

</div>

I goofed. Ooops. 😉

I'll probably leave it as I posted. I kind of understand that better.

---

<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: [28 February 2022 02:33 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/15 "2022-02-28T02:33:57Z")

</div>

All nodes pass a **msg** down the wire. One of the properties of a msg can be ‘payload’ or ‘topic’ or ‘myspecialproperty’ but it doesn’t **have** to have ‘payload’ as part of the msg but ‘payload’ is pretty much expected to be there.

Hope that helps

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [28 February 2022 23:17 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/16 "2022-02-28T23:17:20Z")

</div>

Yeah, I got _hung up_ on that point. It is the `msg.payload` that is sent out.

---

<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: [14 March 2022 23:17 UTC](https://discourse.nodered.org/t/help-with-trigger-node-and-sending-messages/59084/17 "2022-03-14T23:17:36Z")

</div>

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