# Help with \`node-status\` message format

**URL:** https://discourse.nodered.org/t/help-with-node-status-message-format/72751
**Category:** General
**Created:** [27 December 2022 03:16 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751 "2022-12-27T03:16:32Z")
**Posts on this page:** 5
**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 December 2022 03:16 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751/1 "2022-12-27T03:16:32Z")

</div>

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)

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

---

<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 December 2022 03:59 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751/2 "2022-12-27T03:59:34Z")

</div>

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.

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [27 December 2022 07:31 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751/3 "2022-12-27T07:31:00Z")

</div>

I'm not really sure what's now your issue...  
Yet, are you aware of this [documentation for Node status](https://nodered.org/docs/creating-nodes/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](https://github.com/node-red/node-red/blob/113d42ef35ccd55cb114c391fa3a55c7b8e94f18/packages/node_modules/%40node-red/runtime/lib/flows/Subflow.js#L178) 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](https://github.com/node-red/node-red/blob/113d42ef35ccd55cb114c391fa3a55c7b8e94f18/packages/node_modules/%40node-red/runtime/lib/flows/Subflow.js#L189-L194) `msg.status` - if `msg.payload` is undefined.

---

<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 December 2022 08:56 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751/4 "2022-12-28T08:56:32Z")

</div>

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

---

<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: [26 February 2023 08:56 UTC](https://discourse.nodered.org/t/help-with-node-status-message-format/72751/5 "2023-02-26T08:56:35Z")

</div>

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