Display two payloads in one Text

Hi,
i´m completely new to node-red and this may be a stupid question but I cant get it work:
Got 2 values from a CCU node: Temperature and Humidity
I want to display these two values in one line Text on the Dashboard (xx °C / yy %)
I created a function to store the payload in msg.temp and msg.hum.
Value format for the "Text" is {{msg.temp}} °C / {{msg.hum}} %
That basically works, but just for one value at a time.
CCU sends the correspondig value when it changes, so for example the temp is send every 10 minutes, the humidity once in a hour - so I cant use a join.
Whats the simples way to achieve this?

2

Hi.

We all have to start somewhere. There is nothing wrong with not knowing.

The node you need to look at is the join node.

Set it to manual and set it to accept 2 messages.

That will get that part of it better.

Then look at the template node... There are two. The one you want is the one with a { icon in its node symbol.

@zimb86 The way I would do this is to have each sensor store it's values in a flow variable. You could use a change node to do this:
Screen Shot 2020-08-06 at 4.22.38 AM
This way flow.temperature and flow.humidity will always have the latest value. Then connect the outputs of both change nodes to another 'change' node and use the 'replace' option to move in the values


and feed that to your ui-text node.

Here is a sample flow using inject nodes in-place of the mqtt-in nodes and a debug in-place of the ui-text`

[{"id":"1cc4dda7.44b11a","type":"change","z":"3e1ce002.535ce8","name":"","rules":[{"t":"set","p":"humidity","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":80,"wires":[["1788d09e.f95897"]]},{"id":"6d010fab.b62d28","type":"change","z":"3e1ce002.535ce8","name":"","rules":[{"t":"set","p":"temperature","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":160,"wires":[["1788d09e.f95897"]]},{"id":"1788d09e.f95897","type":"change","z":"3e1ce002.535ce8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"temp °C / humi %","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"temp","fromt":"str","to":"temperature","tot":"flow"},{"t":"change","p":"payload","pt":"msg","from":"humi","fromt":"str","to":"humidity","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":120,"wires":[["e8d8301b.957a78"]]},{"id":"2bb527d5.911e38","type":"inject","z":"3e1ce002.535ce8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"56","payloadType":"num","x":90,"y":80,"wires":[["1cc4dda7.44b11a"]]},{"id":"eb2f94c2.4e8178","type":"inject","z":"3e1ce002.535ce8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"45","payloadType":"num","x":90,"y":160,"wires":[["6d010fab.b62d28"]]},{"id":"e8d8301b.957a78","type":"debug","z":"3e1ce002.535ce8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":120,"wires":[]}]
1 Like

Thanks @zenofmud, That works like expected!
So if I got multiple sensors on one flow i have to use unique variables for each, right?

@Trying_to_learn In my understanding the problem using join is, that the values are only updated if both (temp/hum) are submitted. Giving the case that temp is updated just now and hum in about 2 hours the current received temp is not displayed on the dashboard until hum is submitted in 2h.
Is that correct?

Can you expand on this?

As for the join you are correct, both msgs would have to arrive before it was sent on. That is why I gave my suggestion to use to flow variables.

Sure, I want to create a dashboard of all my room temperature sensors.
So I have to modify flow.humidity to flow.humidity.werkstatt
otherwise the incoming temperature values would all use the same variable?

3

If you set the message parts count in the Join node to 1 then you will get a message every time either of them arrives (but it will include the latest values of both. Alternatively if you want to wait initially for both but then get a message every time either of them appears again then set the parts count to 2 and select and every subsequent message.

It might be easier to use two text nodes side by side, or does that not work for you?

1 Like

Using a join you can do this, which copes with the differing sample rates.

image

[{"id":"25720941.ac4676","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp","payload":"56","payloadType":"num","x":100,"y":1080,"wires":[["27050894.921978"]]},{"id":"ceb4d080.f0bd4","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"hum","payload":"45","payloadType":"num","x":100,"y":1160,"wires":[["27050894.921978"]]},{"id":"4951d89f.89625","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":1220,"wires":[]},{"id":"27050894.921978","type":"join","z":"bdd7be38.d3b55","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":1140,"wires":[["d659d4f3.25077"]]},{"id":"d659d4f3.25077","type":"function","z":"bdd7be38.d3b55","name":"","func":"let temp = msg.payload.temp === undefined ? \"\" : msg.payload.temp\nlet hum = msg.payload.hum === undefined ? \"\" : msg.payload.hum\nmsg.payload = `${temp} C / ${hum} %`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":1220,"wires":[["4951d89f.89625"]]}]

Thanks everyone, finally I used @Colin s example to get it work.


1 Like

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