Help with `node-status` message format

I am writing a subflow and it will have a status.
(If only it was that easy)

Basically I have a status node (and change node) to make the payload reflect the message which will control the status.
On-line will give a status of a filled green circle.
Off-line will give a status of a filled red circle.
Not rocket science. But I'm stuck.

(from the subflow code)

[{"id":"7d7b13d11484d98b","type":"status","z":"7a2637e78f8d7294","name":"A","scope":["ed9ed367ddd1d60e"],"x":90,"y":210,"wires":[["3ea3c98af3827c65","d014ced04fa4a26b"]]},{"id":"3ea3c98af3827c65","type":"change","z":"7a2637e78f8d7294","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"status.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":210,"wires":[["1f18987f9248d181"]]},{"id":"1f18987f9248d181","type":"switch","z":"7a2637e78f8d7294","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"On-line","vt":"str"},{"t":"eq","v":"Off-line","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":210,"wires":[[],[]]}]

So I will put 2 x change nodes and construct the payload for the two options.
Then they both go to the status output node of the subflow.

What structure does the message need to be?

Sorry for the dumb question.

Ok, help with this.

I said I was going to use a switch and two change nodes to make the two messages.

I put in two change nodes with messages like
({ fill: "red", text: "Offline" })
but all I got was the text below the node.

I decided (after more digging) to use this, and it works.
So what is the difference between this and how I was doing it the long way?
I was doing it that (the long way) to establish a working baseline.

This code (below) is basically the switch and the two change nodes combined.
And the nodes already shown just for context.

[{"id":"58c43f990cfcc4ed","type":"status","z":"a29b660bf678ae94","name":"","scope":["f7a5739094e4627b"],"x":140,"y":290,"wires":[["d05b7d56d254176c"]]},{"id":"4ad44ebed6115a2a","type":"function","z":"a29b660bf678ae94","name":"function 7","func":"if (msg.payload == \"Off-line\") {\n    msg.payload = ({ fill: \"red\", text: \"Offline\" });\n}\nif (msg.payload == \"On-line\") {\n    msg.payload = ({ fill: \"green\", text: \"Online\" });\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":290,"wires":[[]]},{"id":"d05b7d56d254176c","type":"change","z":"a29b660bf678ae94","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"status.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":290,"wires":[["4ad44ebed6115a2a"]]}]

I'm not really sure what's now your issue...
Yet, are you aware of this documentation for Node status?

Discussing a bit further:

  • There's no need to move msg.status.text to msg.payload prior to the Switch node. Why don't you do the check like:

  • The status message object has to pass this test to create shape & fill; otherwise it will only create the text line.

  • There's even no need to construct a new status message object in msg.payload. The subflow's statusNode accepts as well msg.status - if msg.payload is undefined.

The message was moved only because I prefer to work on payload and it was going to be sent out as part of the status message.

That first link explains how to make messages to show a node's status.
I didn't understand that as also the structure to send out on a subflow to set it's status.

Live and learn. Alas I don't know if I am going to live long enough to learn anything good/useful. :frowning:

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