I have two payloads, both are in numeric format.
I would like to multiply the two numbers and use the product on a dashboard as text and in a gauge.
This is the flow:
My attempt:-
Any pointers will be appreciated very much
Kind Regards
Frits
I have two payloads, both are in numeric format.
I would like to multiply the two numbers and use the product on a dashboard as text and in a gauge.
This is the flow:
My attempt:-
Any pointers will be appreciated very much
Kind Regards
Frits
A key point all node-red users must understand is that messages travel down each wire separately. In otherwords, the 2 wires feeding into function "West DC Watts" will NEVER arrive at the same time.
With that in mind, there are a couple of ways to solve this, but ultimately, you need both values in the same msg.
I will show you 1 (join node) others may provide an alternative method (context)
See this article in the cookbook for an example of how to join messages into one object.
Once you can see obth values in a single msg, you can access them in a function like this...
msg.payload = msg.payload.property1 * msg.payload.property2
return msg;
where property1 and property1 match the topics you gave them in the above cookbook example.
Show us what is coming out of the MQTT node please.
3/6/2023, 4:10:01 PMnode: SBF-Spot sbfspot/2130438358 : msg.payload : Object object Timestamp: "06/03/2023 16:10:02" SunRise: "06/03/2023 06:06:00" SunSet: "06/03/2023 18:31:00" InvSerial: 2130438358 InvName: "SB 4000TL-21 358 Regs" InvTime: "06/03/2023 16:10:00" InvStatus: "Ok" InvTemperature: 38.53 InvGridRelay: "Closed" EToday: 14.204 ETotal: 33229.644 PACTot: 196 UDC1: 223.59 UDC2: 251.94 IDC1: 0.504 IDC2: 0.416 PDC1: 112 PDC2: 104
3/6/2023, 4:10:01 PMnode: SBF-Spotsbfspot/2130438358 : msg.payload : Object
object
Timestamp: "06/03/2023 16:10:02"
SunRise: "06/03/2023 06:06:00"
SunSet: "06/03/2023 18:31:00"
InvSerial: 2130438358
InvName: "SB 4000TL-21 358 Regs"
InvTime: "06/03/2023 16:10:00"
InvStatus: "Ok"
InvTemperature: 38.53
InvGridRelay: "Closed"
EToday: 14.204
ETotal: 33229.644
PACTot: 196
UDC1: 223.59
UDC2: 251.94
IDC1: 0.504
IDC2: 0.416
PDC1: 112
PDC2: 104
It looks like both values are already in the same payload so you should be able to just use them as I explained above...
msg.payload = msg.payload.UDC2* msg.payload.IDC2
return msg;
You are correct. They are in the same payload:
Let me try the formula then:
Thanks @Steve-Mcl ,
I got it to work now.
What do I add to that formula to only show two digits after the dot
msg.payload = msg.payload.UDC2* msg.payload.IDC2
return msg;
3/6/2023, 4:30:02 PM[node: West DC Watts](http://192.168.1.110:1880/#)sbfspot/2130438358 : msg.payload : number
100.07844
3/6/2023, 4:30:02 PM[node: East DC Watts](http://192.168.1.110:1880/#)sbfspot/2130438358 : msg.payload : number
85.60538999999999
it depends what you are doing with it.
Typically, you leave the number as is (for accuracy) but then trim it down when displaying it on a dashboard or spreadsheet.
On a dashboard item (like ui-label) you would use angular decimal pipe {{msg.payload|number:2}}
to limit the display on a dashboard item.
Oh Oh:-
not correct
No, like this on a dashboard UI Text (or other dashboard item)
Thanks Steve. Now I understand the part:
Typically, you leave the number as is (for accuracy) but then trim it down when displaying it on a dashboard or spreadsheet.
For the future, one of the golden rules is not to send a message down two different paths at the same time unless you need to, and particularly don't send it down different paths and then try to join them back together.
Several of the dashboard nodes allow you to specify where in the message the data resides, so in a gauge, for example, you can specify, in the Value Format field something like {{msg.payload.InvTemperature|number: 2}}
, which can avoid the need for moving data into msg.payload.
Thanks Colin.
It makes sense.
Thanks for the kind help gents. I really appreciate it
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.