Help with `trigger` node and sending messages

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)

[{"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.

:frowning:

[{"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.

This is your trigger node:

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 :slight_smile: )

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.

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.

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!

Ok, back to your edited post.

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

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.

I must need glasses. :cry:

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

[
    {
        "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.

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.

[{"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.

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

// 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.

1 Like

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?

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.

2 Likes

But thetrigger 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.

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.

I goofed. Ooops. :wink:

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

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

Yeah, I got hung up on that point. It is the msg.payload that is sent out.

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