question

Mark avatar image
Mark asked

Node-Red charger (mppt) State to text output on display

Hi All

New to Red-Node.

I expect this to be a simple thing, how do I get to display words when the output is a number. (I have tried reading, looking for examples, google foo, all my tests fail).

ie. Charger state = 0 to display Off

Value types

0 - Off
2 - Fault
3 - Bulk
4 - Absorption
5 - Float
6 - Storage
7 - Equalize
245 - Off
247 - Equalize
252 - External Control


So basically if a value turns up I want to replace it with a text message.


Thanks in advance

Cheers

Mark


Node-RED
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

6 Answers
Peter Van Tienen avatar image
Peter Van Tienen answered ·

I used the "change node", pretty straight forward.


screenshot-2024-03-04-at-91911am.png


1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Mark avatar image Mark commented ·
I tried testing this again and I got it to work.

I believe that my problem was not selecting the “number” in the search for.

Those characters are so small for those of us optically challanged.

Cheers

Mark

0 Likes 0 ·
matt1309 avatar image
matt1309 answered ·

Hi @Mark


Im not a javascript programmer so i might use the wrong terms here. But what you want is a map.

define the map like this:

const statusMap = {
  0: 'Off',
  2: 'Fault',
  3: 'Bulk',
  4: 'Absorption',
  5: 'Float',
  6: 'Storage',
  7: 'Equalize',
  245: 'Off',
  247: 'Equalize',
  252: 'External Control'
};



Then to get the message from the number you would go


statusMap[0] would output Off


So if the message coming into the function node is the number and you want to output the message you would do:


msg.payload = statusMap[msg.payload];


Hope this helps


The other option is you can probably get a change node to do this. Depending on if you'll have other payloads with those numbers in. ie change from 0 to Off.
and repeat for each code. However this probably wont work if you have other messages that happen to include '0'

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Mark avatar image Mark commented ·

Hi this is what I’m looking for.

But can you answer where do I put this code?

0 Likes 0 ·
Show more comments
Dirk-Jan Faber (Victron Energy) avatar image
Dirk-Jan Faber (Victron Energy) answered ·

But that is a nice idea. I can modify the nodes to also output the text value in case of an enumerated type as `msg.textvalue`. Which I'll add to the 1.5.14 release of node-red-contrib-victron (note that it will still take a while before being part of the normal Venus release)

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nickdb avatar image nickdb ♦♦ commented ·

That would be a great idea. I have way too many functions translating these states for dashboarding.

Now if only dash 2.0 allowed you to specify the payload, like v1..

1 Like 1 ·

Modified the code to show the textual value of the enums together with the value. And also output the value as `msg.textvalue`. I'll make a release of it and see if it can be squeezed into the next beta release.

1709332159251.png

1709332211442.png

0 Likes 0 ·
1709332159251.png (51.5 KiB)
1709332211442.png (45.3 KiB)
Dirk-Jan Faber (Victron Energy) avatar image Dirk-Jan Faber (Victron Energy) ♦♦ Dirk-Jan Faber (Victron Energy) ♦♦ commented ·
This has become available for users running the beta feed of Venus.
2 Likes 2 ·
Mark avatar image
Mark answered ·

Sounds good.

I know the VRM portal displays this info.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Mark avatar image
Mark answered ·

img-0613.pngWorked it out

Using convert payload

img-0612.png


img-0612.png (782.5 KiB)
img-0613.png (472.3 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Mark avatar image
Mark answered ·

I tried change mode first but it did not work for me. Endless hair pulling I gave up on this idea.

Thanks

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.