# Converting hex to decimal

**URL:** <https://discourse.nodered.org/t/converting-hex-to-decimal/49580>\
**Category:** General\
**Created:** [10 August 2021 18:48 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580 "2021-08-10T18:48:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [10 August 2021 18:48 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/1 "2021-08-10T18:48:13Z")

</div>

Hello,  
for you perhaps something stupids, but for me a problem  
Ho do i get decimal data from (wx)sensors  
TEMP;'00f6' ; HUM;'62';  
Dick

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 August 2021 19:11 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/2 "2021-08-10T19:11:13Z")

</div>

```auto
msg.payload.TEMP = parseInt(msg.payload.TEMP,16);
msg.payload.HUM = parseInt(msg.payload.HUM,16)
return msg;

```

in a function node  
[https://www.w3schools.com/jsref/jsref\_parseint.asp](https://www.w3schools.com/jsref/jsref_parseint.asp)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 August 2021 19:36 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/3 "2021-08-10T19:36:42Z")

</div>

> [@dick](#):
>
> TEMP;'00f6' ; HUM;'62';

Assuming that ↑ is a single string,

In a function node,

- remove all spaces and apostrophes
  - that makes the string `TEMP;00f6;HUM;62;`

- then use split function with `;` as a delimiter break the string into 4 parts.
  - now value is `['TEMP','00f6','HUM','62',] `

- Then loop through that array (stepping 2 places) and assign the name and the value to an object (using `parseInt(value, 16)` to make the hexadecimal into decimal)

e.g...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c9a061c5e1f677ed2eb1be6d0e1e186f6262b8e.png)

demo flow...

```auto
[{"id":"664e5b6b546a7850","type":"inject","z":"9af9141769558c7a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TEMP;'00f6' ; HUM;'62';","payloadType":"str","x":2480,"y":220,"wires":[["e7128a7b36bb9235"]]},{"id":"e7128a7b36bb9235","type":"function","z":"9af9141769558c7a","name":"","func":"var str = msg.payload;\nstr = str.replace(/[']/g, ''); //remove spaces and single quotes\nvar parts = str.split(\";\");\nvar result = {};\n\nfor (let index = 0; index < parts.length; index = index+2) {\n const name = parts[index];\n const val = parts[index + 1];\n if (name && val) {\n result[name] = parseInt(val, 16);\n }\n}\nmsg.payload = result\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2530,"y":280,"wires":[["46d739b7dfe9d2a7"]]},{"id":"46d739b7dfe9d2a7","type":"debug","z":"9af9141769558c7a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2570,"y":340,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [11 August 2021 10:40 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/4 "2021-08-11T10:40:03Z")

</div>

the whole datarange is  
20;0A;Cresta;ID=2C01;TEMP=00e8;HUM=63;BAT=OK;  
with change is it reformed to:  
20;05;Cresta;ID;2C01;TEMP;00f2;HUM;65;BAT;OK;  
with function data split i got the information needed  
temp: "00f3" hum: "65"

and then ?? Ho do i get decimal data from (wx)sensors  
it is no working.  
Dick

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 August 2021 12:27 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/5 "2021-08-11T12:27:13Z")

</div>

Try this you can add the values you want in the wanted array so you could add ID.

```auto
[{"id":"e9366ca3.d23888","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20;0A;Cresta;ID=2C01;TEMP=00e8;HUM=63;BAT=OK;","payloadType":"str","x":260,"y":4440,"wires":[["8b74d6ff.7a673"]]},{"id":"8b74d6ff.7a673","type":"function","z":"c74669a0.6a34f8","name":"","func":"const split_array = msg.payload.split(\";\");\nconst wanted = [\"TEMP\",\"HUM\"]\nmsg.payload={};\nfor(let i in split_array){\n let parts =split_array[i].split(\"=\");\n if(wanted.includes(parts[0]))\n msg.payload[parts[0]]=parseInt(parts[1], 16);\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":4440,"wires":[["183c25e0.2effaa"]]},{"id":"183c25e0.2effaa","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":4440,"wires":[]}]

```

```auto
const split_array = msg.payload.split(";");
const wanted = ["TEMP","HUM"]
msg.payload={};
for(let i in split_array){
    let parts =split_array[i].split("=");
    if(wanted.includes(parts[0]))
        msg.payload[parts[0]]=parseInt(parts[1], 16);
}
return msg;

```

If payload string is always in the same order and always contains the same info you could do

```auto
msg.payload = msg.payload.split(/=|;/);
msg.payload = {
    [msg.payload[5]]: parseInt(msg.payload[6],16),
    [msg.payload[7]]: parseInt(msg.payload[8],16)
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [11 August 2021 14:40 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/6 "2021-08-11T14:40:16Z")

</div>

thanks E1cid  
that input gives needed data ,but the input for temp is '00e8' hex--\> dec 246  
that '00e8' is to high (perhaps even hum to high 99 !)  
I can divide by 10, Is that the right solution for temp, but not for hum.?  
Perhaps i made a mistake or is something else possible.  
Dick

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2021 14:57 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/7 "2021-08-11T14:57:03Z")

</div>

So what real values do those hex values represent?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 August 2021 15:29 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/8 "2021-08-11T15:29:36Z")

</div>

As Colin said would need the real values.  
Can not say for sure but it looks like the temp is hex and needs to be divided by 10, and the humidity is probably a decimal value already.  
try

```auto
const split_array = msg.payload.split(";");
msg.payload={};
for(let i in split_array){
    let parts =split_array[i].split("=");
    if(parts.length === 2){
        if(parts[0]==="HUM") msg.payload[parts[0]]=parseInt(parts[1]);
        else if(parts[0] === "TEMP") msg.payload[parts[0]] = parseInt(parts[1], 16)/10;
        else if(parts[0]==="ID") msg.payload [parts[0]] = parseInt(parts[1], 16);
        else msg.payload[parts[0]] = parts[1];
    }
}

/* or
msg.payload = msg.payload.split(/=|;/);
msg.payload = {
    [msg.payload[5]]: parseInt(msg.payload[6],16)/10,
    [msg.payload[7]]: parseInt(msg.payload[8])
}
*/
return msg;

```

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [11 August 2021 18:29 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/9 "2021-08-11T18:29:57Z")

</div>

Thanks GUYS  
for this GOOD help.

Now i can go on with the other possibilities in Node-Red  
e.g gauge and so on.

Dick

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [11 August 2021 18:56 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/10 "2021-08-11T18:56:14Z")

</div>

@dick  
It may be a little late but may be useful.  
I have the impression to recognize the data coming out of the Rflink?  
Then I remembered that I use a flow to manage several probes or other radio frequencies at 433 Mhz.  
So here is an extract of my flow which deals with a ThermPro probe.  
You can remove the node concerning influxdb.  
Oh yes, you must also have installed the **node-red-contrib-convert**.  
/JL

```auto
[{"id":"6f4cb128.939ec8","type":"serial in","z":"a9e1c168.34a4a","name":"RFlink","serial":"25737c2e.cc1f2c","x":90,"y":120,"wires":[["5a2cbe93.deba8","bb86b8ee.825a08"]]},{"id":"5a2cbe93.deba8","type":"switch","z":"a9e1c168.34a4a","name":"Sonde OWL_CM180 ou ThermPro ?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"OWL_CM180","vt":"str"},{"t":"cont","v":"Prologue","vt":"str"},{"t":"cont","v":"Pollin","vt":"str"},{"t":"cont","v":"Digitech","vt":"str"},{"t":"else"}],"checkall":"true","repair":true,"outputs":5,"x":370,"y":120,"wires":[["ab1f1a01.78957","884c8e43.8de71","4cc5e484.e6a7cc"],["af46a898.a464c","b7f6c495.0f8a98","24def373.15ef84"],["b166d934.c892f"],["551cce52.c9a3a"],["e6dd9539.5fcda"]],"outputLabels":["Sonde ampermétrique OWL180","Sonde Humidité+Temp Therm Pro","Sonde Pollin PFR-130 Pluie","Digitech Weather Station","Inconnu"]},{"id":"b7f6c495.0f8a98","type":"function","z":"a9e1c168.34a4a","name":"add timestamp","func":"msg.payload = new Date().toString() + \" - \" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":80,"wires":[["1990c5ed.67c982"]]},{"id":"1990c5ed.67c982","type":"file","z":"a9e1c168.34a4a","name":"Log du Thermpro","filename":"/home/pi/Documents/ThermPro-Log_temp.dump","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":910,"y":80,"wires":[[]]},{"id":"38e5744e.fc6ccc","type":"comment","z":"a9e1c168.34a4a","name":"Les Sondes ThermPro de température & humidité","info":" **ThermPro**","x":240,"y":540,"wires":[]},{"id":"1268ba70.600b06","type":"comment","z":"a9e1c168.34a4a","name":"Sonde Vide Sanitaire","info":"","x":620,"y":580,"wires":[]},{"id":"af46a898.a464c","type":"string","z":"a9e1c168.34a4a","name":"SondeID","methods":[{"name":"between","params":[{"type":"str","value":";ID="},{"type":"str","value":";TEMP="}]}],"prop":"payload","propout":"sondeID","object":"msg","objectout":"msg","x":120,"y":640,"wires":[["35fc3439.6d4d2c"]]},{"id":"35fc3439.6d4d2c","type":"switch","z":"a9e1c168.34a4a","name":"quelle sonde","property":"sondeID","propertyType":"msg","rules":[{"t":"eq","v":"9171","vt":"str"},{"t":"eq","v":"9100","vt":"str"},{"t":"eq","v":"9142","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":270,"y":640,"wires":[["a906a7b4.e860b8","27d828bb.626bc"],["44c34056.d92ce","d6272baf.3c069","9eddd65a.5cc38"],["d0abd187.406e5","9f7203aa.e9563"]],"outputLabels":["Sonde extérieur - (9171)","Sonde vide sanitaire - (9100)","Sonde armoire PhotoVoltaique - (9142)"]},{"id":"44c34056.d92ce","type":"string","z":"a9e1c168.34a4a","name":"Température","methods":[{"name":"between","params":[{"type":"str","value":"TEMP="},{"type":"str","value":";HUM="}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":470,"y":640,"wires":[["b1976976.ac7098"]]},{"id":"b1976976.ac7098","type":"switch","z":"a9e1c168.34a4a","name":"Id not Null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":640,"wires":[["7f7894a3.3e3f04"]]},{"id":"7f7894a3.3e3f04","type":"function","z":"a9e1c168.34a4a","name":"Hex2Dec","func":"global.set('hex2dec', function(hexa) {\n return parseInt(hexa, 16);\n}, 'memoryOnly');\nvar msg2convert = msg.payload;\nmsg.payload = global.get('hex2dec', 'memoryOnly')(msg2convert)\n//msg.payload = {\n// dec: global.get('hex2dec', 'memoryOnly')(msg2convert) \n//}\nmsg.payload = msg.payload / 10\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":640,"wires":[["89b9b966.dffbc8","b2546b8b.793998","5619ecf7.808654","36e2a997.dc5d76"]]},{"id":"89b9b966.dffbc8","type":"ui_gauge","z":"a9e1c168.34a4a","name":"","group":"e010ab31.a5b8e8","order":0,"width":"3","height":"2","gtype":"gage","title":"Température","label":"units","format":"{{value}}°C","min":"-10","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":950,"y":640,"wires":[]},{"id":"5619ecf7.808654","type":"influxdb out","z":"a9e1c168.34a4a","influxdb":"f737d1a1.c06c08","name":"","measurement":"ThermPro_Temperature","precision":"","retentionPolicy":"","x":1110,"y":680,"wires":[]},{"id":"b2546b8b.793998","type":"file","z":"a9e1c168.34a4a","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_temp.dump","appendNewline":true,"createDir":false,"overwriteFile":"true","x":950,"y":720,"wires":[[]]},{"id":"36e2a997.dc5d76","type":"ui_chart","z":"a9e1c168.34a4a","name":"","group":"99b72a6.83225d8","order":3,"width":"6","height":"3","label":"Température","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"...Attente des données (max 15s)","dot":false,"ymin":"","ymax":"","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":950,"y":760,"wires":[[]]},{"id":"8be2ab74.cf3608","type":"file in","z":"a9e1c168.34a4a","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_temp.dump","format":"utf8","sendError":true,"x":650,"y":760,"wires":[["36e2a997.dc5d76"]]},{"id":"9c78f903.9eece8","type":"inject","z":"a9e1c168.34a4a","name":"Startup","repeat":"","crontab":"","once":true,"topic":"","payload":"","payloadType":"date","x":480,"y":760,"wires":[["8be2ab74.cf3608"]]},{"id":"d6272baf.3c069","type":"string","z":"a9e1c168.34a4a","name":"Humidité","methods":[{"name":"between","params":[{"type":"str","value":";HUM="},{"type":"str","value":";"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":460,"y":820,"wires":[["901563b9.d7879","abcf17a2.cc6288"]]},{"id":"abcf17a2.cc6288","type":"convert","z":"a9e1c168.34a4a","name":"","convertTo":"number","x":670,"y":820,"wires":[["cf915f5d.283f4","d84a4dae.5e5e58","3465add8.d1a93a"]]},{"id":"cf915f5d.283f4","type":"ui_gauge","z":"a9e1c168.34a4a","name":"","group":"e010ab31.a5b8e8","order":0,"width":"3","height":"2","gtype":"gage","title":"Humidité","label":"units","format":"{{value}}%","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":940,"y":820,"wires":[]},{"id":"d84a4dae.5e5e58","type":"influxdb out","z":"a9e1c168.34a4a","influxdb":"f737d1a1.c06c08","name":"","measurement":"ThermPro_Humidity","precision":"","retentionPolicy":"","x":1100,"y":860,"wires":[]},{"id":"901563b9.d7879","type":"file","z":"a9e1c168.34a4a","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_humidity.dump","appendNewline":true,"createDir":false,"overwriteFile":"true","x":650,"y":860,"wires":[[]]},{"id":"ac20f4f3.b1e63","type":"file in","z":"a9e1c168.34a4a","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_humidity.dump","format":"utf8","sendError":true,"x":650,"y":900,"wires":[["3465add8.d1a93a"]]},{"id":"c742c0a2.e8035","type":"inject","z":"a9e1c168.34a4a","name":"Startup","repeat":"","crontab":"","once":true,"topic":"","payload":"","payloadType":"date","x":480,"y":900,"wires":[["ac20f4f3.b1e63"]]},{"id":"3465add8.d1a93a","type":"ui_chart","z":"a9e1c168.34a4a","name":"","group":"99b72a6.83225d8","order":4,"width":"6","height":"3","label":"Humidité","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"...Attente des données (max 15s)","dot":false,"ymin":"","ymax":"","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":940,"y":900,"wires":[[]]},{"id":"9eddd65a.5cc38","type":"debug","z":"a9e1c168.34a4a","name":"humidité","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":680,"wires":[]},{"id":"25737c2e.cc1f2c","type":"serial-port","serialport":"/dev/rflink","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"e010ab31.a5b8e8","type":"ui_group","name":"Vide-sanitaire","tab":"eb894080.edb56","order":7,"disp":true,"width":"6","collapse":false},{"id":"f737d1a1.c06c08","type":"influxdb","hostname":"192.168.1.200","port":"8086","protocol":"http","database":"CAPTEURS","name":"","usetls":false,"tls":"","influxdbVersion":"1.x"},{"id":"99b72a6.83225d8","type":"ui_group","name":"Vide-sanitaire","tab":"9d93e8f.e13c718","order":7,"disp":true,"width":"6","collapse":false},{"id":"eb894080.edb56","type":"ui_tab","name":"Temp. & Humidité","icon":"fa-thermometer-full ","order":19,"disabled":false,"hidden":false},{"id":"9d93e8f.e13c718","type":"ui_tab","name":"Graph. Temp.","icon":"fa-line-chart","order":6,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [12 August 2021 07:30 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/11 "2021-08-12T07:30:59Z")

</div>

Hallo Jean-Luc,

For good news it is never to late.

Please can you resend the node again.

I cannot read it , there is something wrong in one commando/ word .

I cannot copy this node

Thanks

Dick

Verzonden vanuit [Mail](https://go.microsoft.com/fwlink/?LinkId=550986) voor Windows

 ![1DBDCCB5B6C74A51A4340270580B4443.png](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/7159a975d714a6caee787759490140daf4d4fda6.png)

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [12 August 2021 07:57 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/12 "2021-08-12T07:57:06Z")

</div>

Jean-Luc

You are rightit is data from RFlink /433Mhz.

I looked for the eroor.

But i cannot find

Gr

Dick

Verzonden vanuit [Mail](https://go.microsoft.com/fwlink/?LinkId=550986) voor Windows

 ![1DBDCCB5B6C74A51A4340270580B4443.png](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/7159a975d714a6caee787759490140daf4d4fda6.png)

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [12 August 2021 09:26 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/13 "2021-08-12T09:26:06Z")

</div>

Hey Dick,

I imported the flow in another NR and it's ok. Anyway.  
So I removed the nodes for influxdb. Not useful for the demo.  
But you really have to import via the palette the node-red-contrib-convert before importing the flow.  
I hope it will work this time 🙂

```auto
[{"id":"573bebda.551b3c","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"6f4cb128.939ec8","type":"serial in","z":"573bebda.551b3c","name":"RFlink","serial":"25737c2e.cc1f2c","x":150,"y":400,"wires":[["5a2cbe93.deba8"]]},{"id":"5a2cbe93.deba8","type":"switch","z":"573bebda.551b3c","name":"Sonde OWL_CM180 ou ThermPro ?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"OWL_CM180","vt":"str"},{"t":"cont","v":"Prologue","vt":"str"},{"t":"cont","v":"Pollin","vt":"str"},{"t":"cont","v":"Digitech","vt":"str"},{"t":"else"}],"checkall":"true","repair":true,"outputs":5,"x":390,"y":400,"wires":[[],["af46a898.a464c","b7f6c495.0f8a98"],[],[],[]],"outputLabels":["Sonde ampermétrique OWL180","Sonde Humidité+Temp Therm Pro","Sonde Pollin PFR-130 Pluie","Digitech Weather Station","Inconnu"]},{"id":"b7f6c495.0f8a98","type":"function","z":"573bebda.551b3c","name":"add timestamp","func":"msg.payload = new Date().toString() + \" - \" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":380,"wires":[["1990c5ed.67c982"]]},{"id":"1990c5ed.67c982","type":"file","z":"573bebda.551b3c","name":"Log du Thermpro","filename":"/home/pi/Documents/ThermPro-Log_temp.dump","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":930,"y":380,"wires":[[]]},{"id":"38e5744e.fc6ccc","type":"comment","z":"573bebda.551b3c","name":"Les Sondes ThermPro de température & humidité","info":" **ThermPro**","x":300,"y":540,"wires":[]},{"id":"1268ba70.600b06","type":"comment","z":"573bebda.551b3c","name":"Sonde Vide Sanitaire","info":"","x":700,"y":540,"wires":[]},{"id":"af46a898.a464c","type":"string","z":"573bebda.551b3c","name":"SondeID","methods":[{"name":"between","params":[{"type":"str","value":";ID="},{"type":"str","value":";TEMP="}]}],"prop":"payload","propout":"sondeID","object":"msg","objectout":"msg","x":200,"y":600,"wires":[["35fc3439.6d4d2c"]]},{"id":"35fc3439.6d4d2c","type":"switch","z":"573bebda.551b3c","name":"quelle sonde","property":"sondeID","propertyType":"msg","rules":[{"t":"eq","v":"9171","vt":"str"},{"t":"eq","v":"9100","vt":"str"},{"t":"eq","v":"9142","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":350,"y":600,"wires":[[],["44c34056.d92ce","d6272baf.3c069","9eddd65a.5cc38"],[]],"outputLabels":["Sonde extérieur - (9171)","Sonde vide sanitaire - (9100)","Sonde armoire PhotoVoltaique - (9142)"]},{"id":"44c34056.d92ce","type":"string","z":"573bebda.551b3c","name":"Température","methods":[{"name":"between","params":[{"type":"str","value":"TEMP="},{"type":"str","value":";HUM="}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":550,"y":600,"wires":[["b1976976.ac7098"]]},{"id":"b1976976.ac7098","type":"switch","z":"573bebda.551b3c","name":"Id not Null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":700,"y":600,"wires":[["7f7894a3.3e3f04"]]},{"id":"7f7894a3.3e3f04","type":"function","z":"573bebda.551b3c","name":"Hex2Dec","func":"global.set('hex2dec', function(hexa) {\n return parseInt(hexa, 16);\n}, 'memoryOnly');\nvar msg2convert = msg.payload;\nmsg.payload = global.get('hex2dec', 'memoryOnly')(msg2convert)\n//msg.payload = {\n// dec: global.get('hex2dec', 'memoryOnly')(msg2convert) \n//}\nmsg.payload = msg.payload / 10\nreturn msg;","outputs":1,"noerr":0,"x":840,"y":600,"wires":[["89b9b966.dffbc8","b2546b8b.793998","36e2a997.dc5d76"]]},{"id":"89b9b966.dffbc8","type":"ui_gauge","z":"573bebda.551b3c","name":"","group":"e010ab31.a5b8e8","order":0,"width":"3","height":"2","gtype":"gage","title":"Température","label":"units","format":"{{value}}°C","min":"-10","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1030,"y":600,"wires":[]},{"id":"b2546b8b.793998","type":"file","z":"573bebda.551b3c","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_temp.dump","appendNewline":true,"createDir":false,"overwriteFile":"true","x":1030,"y":680,"wires":[[]]},{"id":"36e2a997.dc5d76","type":"ui_chart","z":"573bebda.551b3c","name":"","group":"99b72a6.83225d8","order":3,"width":"6","height":"3","label":"Température","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"...Attente des données (max 15s)","dot":false,"ymin":"","ymax":"","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":1030,"y":720,"wires":[[]]},{"id":"8be2ab74.cf3608","type":"file in","z":"573bebda.551b3c","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_temp.dump","format":"utf8","sendError":true,"x":730,"y":720,"wires":[["36e2a997.dc5d76"]]},{"id":"9c78f903.9eece8","type":"inject","z":"573bebda.551b3c","name":"Startup","repeat":"","crontab":"","once":true,"topic":"","payload":"","payloadType":"date","x":560,"y":720,"wires":[["8be2ab74.cf3608"]]},{"id":"d6272baf.3c069","type":"string","z":"573bebda.551b3c","name":"Humidité","methods":[{"name":"between","params":[{"type":"str","value":";HUM="},{"type":"str","value":";"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":540,"y":780,"wires":[["901563b9.d7879","abcf17a2.cc6288"]]},{"id":"cf915f5d.283f4","type":"ui_gauge","z":"573bebda.551b3c","name":"","group":"e010ab31.a5b8e8","order":0,"width":"3","height":"2","gtype":"gage","title":"Humidité","label":"units","format":"{{value}}%","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1020,"y":780,"wires":[]},{"id":"901563b9.d7879","type":"file","z":"573bebda.551b3c","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_humidity.dump","appendNewline":true,"createDir":false,"overwriteFile":"true","x":730,"y":820,"wires":[[]]},{"id":"ac20f4f3.b1e63","type":"file in","z":"573bebda.551b3c","name":"Chart dump","filename":"/home/pi/Documents/ThermPro-01_humidity.dump","format":"utf8","sendError":true,"x":730,"y":860,"wires":[["3465add8.d1a93a"]]},{"id":"c742c0a2.e8035","type":"inject","z":"573bebda.551b3c","name":"Startup","repeat":"","crontab":"","once":true,"topic":"","payload":"","payloadType":"date","x":560,"y":860,"wires":[["ac20f4f3.b1e63"]]},{"id":"3465add8.d1a93a","type":"ui_chart","z":"573bebda.551b3c","name":"","group":"99b72a6.83225d8","order":4,"width":"6","height":"3","label":"Humidité","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"...Attente des données (max 15s)","dot":false,"ymin":"","ymax":"","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":1020,"y":860,"wires":[[]]},{"id":"9eddd65a.5cc38","type":"debug","z":"573bebda.551b3c","name":"humidité","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":640,"wires":[]},{"id":"abcf17a2.cc6288","type":"convert","z":"573bebda.551b3c","name":"","convertTo":"number","x":750,"y":780,"wires":[["cf915f5d.283f4","3465add8.d1a93a"]]},{"id":"25737c2e.cc1f2c","type":"serial-port","serialport":"/dev/rflink","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"e010ab31.a5b8e8","type":"ui_group","name":"Vide-sanitaire","tab":"eb894080.edb56","order":7,"disp":true,"width":"6","collapse":false},{"id":"99b72a6.83225d8","type":"ui_group","name":"Vide-sanitaire","tab":"9d93e8f.e13c718","order":7,"disp":true,"width":"6","collapse":false},{"id":"eb894080.edb56","type":"ui_tab","name":"Temp. & Humidité","icon":"fa-thermometer-full ","order":19,"disabled":false,"hidden":false},{"id":"9d93e8f.e13c718","type":"ui_tab","name":"Graph. Temp.","icon":"fa-line-chart","order":6,"disabled":false,"hidden":false}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e90dc6077ae6944d59f3df5af5cc75e5f30aaff.png)

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [12 August 2021 11:36 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/14 "2021-08-12T11:36:59Z")

</div>

Ok Jean-Luc

I tried to insert

But there is an errori

(see picture)

But i made it

Thanks

Dick

Verzonden vanuit [Mail](https://go.microsoft.com/fwlink/?LinkId=550986) voor Windows

 ![error.jpg](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fa530d2db92a49d093adc4ece73ee33f996fcf2.jpeg)

 ![1DBDCCB5B6C74A51A4340270580B4443.png](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/7159a975d714a6caee787759490140daf4d4fda6.png)

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [13 August 2021 15:08 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/15 "2021-08-13T15:08:43Z")

</div>

Heeo,  
here i come again  
20;0A;Cresta;ID=2C01;TEMP=00e8;HUM=63;BAT=OK;  
with change is it reformed to:  
20;05;Cresta;ID;2C01;TEMP;00f2;HUM;65;BAT;OK

it is working till  
{"ID":147,"TEMP":27,4,BAT":OK,"HUM":78}

what shall i do to get this information  
in a eg gauge temperature , gauge humidity  
ID in text for the dashboard?  
thanks in advance.  
gr  
Dick

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 August 2021 15:28 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/16 "2021-08-13T15:28:38Z")

</div>

Most ui nodes allow you to select the property to show, using the Value Format field. So if you want a gauge with temperature then put in that field `{{payload.TEMP}}`  
That assumes the the payload is a javascript object containing the property TEMP, which I think is what you say you have.

If that doesn't work then feed the message into a debug node and show us what you get there.

---

<div class="post-metadata">

**Author:** ![dick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dick/32/61180_2.png) [@dick](https://discourse.nodered.org/u/dick)\
**Post date:** [14 August 2021 09:54 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/17 "2021-08-14T09:54:55Z")

</div>

Colin thanks,  
I follow the various advices during this data.  
the debugs are as follows:  
sensor gives:20;07;Cresta;ID=2C01;TEMP=00ef;HUM=64;BAT=OK;  
with function {"ID":2C01,"TEMP":23,"HUM":100,"BAT":null}  
with function temperature:20;3C;Cresta;ID=2C01;TEMP=00ef;HUM=64;BAT=OK;  
{"TEMP":22,"HUM":98}  
function temperature  
msg.payload = msg.TEMP;  
return msg; is the result undefined.  
msg.payload = msg.HUM; gives also undefined.

(With other sensor eg dht11 gives with he same command i get the right temp and hum)  
I think a made mistake during the whole process.  
I hope this is enough for you to find a solution for me?  
gr  
Dick

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 August 2021 10:05 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/18 "2021-08-14T10:05:37Z")

</div>

> [@dick](#):
>
> {"ID":147,"TEMP":27,4,BAT":OK,"HUM":78}

You have `"TEMP":27,4` - notice the comma (`,`) between the `27` and `4`, that should be a period (`.`) or the object will be messed up. It should be `"TEMP":27.4` so you would have:  
{"ID":147,"TEMP":27.4,BAT":OK,"HUM":78}

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 August 2021 10:06 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/19 "2021-08-14T10:06:18Z")

</div>

The sample code I posted leaves TEMP and HUM in msg.payload.  
You should not need any further function nodes to move things around

As Colin said you should be able to just use {{payload.TEMP}}  
e.g

```auto
[{"id":"114c43cf.aa1ea4","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20;0A;Cresta;ID=2C01;TEMP=00e8;HUM=63;BAT=OK;","payloadType":"str","x":90,"y":820,"wires":[["525b3f06.acd908"]]},{"id":"525b3f06.acd908","type":"function","z":"b779de97.b1b46","name":"","func":"const split_array = msg.payload.split(\";\");\nmsg.payload={};\nfor(let i in split_array){\n let parts =split_array[i].split(\"=\");\n if(parts.length === 2){\n if(parts[0]===\"HUM\") msg.payload[parts[0]]=parseInt(parts[1]);\n else if(parts[0] === \"TEMP\") msg.payload[parts[0]] = parseInt(parts[1], 16)/10;\n else if(parts[0]===\"ID\") msg.payload [parts[0]] = parseInt(parts[1], 16);\n else msg.payload[parts[0]] = parts[1];\n }\n}\n\n\n/* or\nmsg.payload = msg.payload.split(/=|;/);\nmsg.payload = {\n [msg.payload[5]]: parseInt(msg.payload[6],16)/10,\n [msg.payload[7]]: parseInt(msg.payload[8])\n}\n*/\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":250,"y":820,"wires":[["28a29eb7.ccf372","20de9a3f.02141e","762a773f.c7cb38"]]},{"id":"28a29eb7.ccf372","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":820,"wires":[]},{"id":"20de9a3f.02141e","type":"ui_gauge","z":"b779de97.b1b46","name":"","group":"8b5cde76.edd58","order":14,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"units","format":"{{payload.TEMP}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":450,"y":880,"wires":[]},{"id":"762a773f.c7cb38","type":"ui_gauge","z":"b779de97.b1b46","name":"","group":"8b5cde76.edd58","order":14,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"units","format":"{{payload.HUM}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":450,"y":920,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

If this is failing post the section of your flow that you are having difficulty with.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 August 2021 10:27 UTC](https://discourse.nodered.org/t/converting-hex-to-decimal/49580/20 "2021-08-14T10:27:29Z")

</div>

> [@dick](#):
>
> msg.payload = msg.TEMP;  
> return msg; is the result undefined.  
> msg.payload = msg.HUM; gives also undefined.

That is because it msg.payload.TEMP not msg.TEMP. But no need to do that if you just want to feed it into a gauge.

[Next page](https://discourse.nodered.org/t/converting-hex-to-decimal/49580.md?page=2)
