String to number convert

Hi
I am currently trying to read the consumption of my washing machine.
My problem I can not separate the string so far that I have only the numbers.
I have already tried with split node but no solution found.
can someone help me?


ewf
Screenshot 2022-08-14 100318
Thanks for help :slight_smile:

Instead of a screen print, can you paste the string value (The 'copy value' button to the right of the value in the debug sidebar).

...also, you can select in the http request node to select 'a parsed JSON object', which would remove the need for a json node in your flow.

json

thanks for the tip without the json node.
the output from the hhtp request is then the following

{"type":"status","description":"Gesamtverbrauch","command":"ecomXstatXtotal","value":"๎Œ 2,5 kWh, ๎Œ€ 534โ„“ "}

Then I used the function node to take only the value

I'm sure someone will produce a shorter/better way to achieve this, but meanwhile, try this;

[{"id":"ae7f927eba3b434f","type":"inject","z":"8ec88bd9c36c3f6b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"status\",\"description\":\"Gesamtverbrauch\",\"command\":\"ecomXstatXtotal\",\"value\":\"๎Œ 2,5 kWh, ๎Œ€ 534โ„“ \"}","payloadType":"json","x":90,"y":560,"wires":[["09592e25093ad1d3"]]},{"id":"09592e25093ad1d3","type":"change","z":"8ec88bd9c36c3f6b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":255,"y":560,"wires":[["47a13779bf90e0e5"]]},{"id":"47a13779bf90e0e5","type":"csv","z":"8ec88bd9c36c3f6b","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":425,"y":560,"wires":[["e635f76538b1bd97"]]},{"id":"e635f76538b1bd97","type":"function","z":"8ec88bd9c36c3f6b","name":"Obtain energy","func":"const string = msg.payload.col2\nmsg.payload = Number(string.replace(\",\", \".\"))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":575,"y":560,"wires":[["f9e923ee9521431a"]]},{"id":"f9e923ee9521431a","type":"debug","z":"8ec88bd9c36c3f6b","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":560,"wires":[]}]

EDIT - The following post by @E1cid is a better solution !!

2 Likes

Not a bad way, could be improved on slightly using the columns input field to select which values are required, and to give property names.

[{"id":"ae7f927eba3b434f","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"status\",\"description\":\"Gesamtverbrauch\",\"command\":\"ecomXstatXtotal\",\"value\":\"๎Œ 2,5 kWh, ๎Œ€ 534โ„“ \"}","payloadType":"json","x":70,"y":240,"wires":[["09592e25093ad1d3","7fce01dc.4cafc"]]},{"id":"09592e25093ad1d3","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":",","fromt":"str","to":".","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"โ„“","fromt":"str","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":280,"wires":[["ead43a1.09bfe48"]]},{"id":"7fce01dc.4cafc","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":240,"wires":[["47a13779bf90e0e5"]]},{"id":"ead43a1.09bfe48","type":"csv","z":"30af2d3e.d94ea2","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":",kw,,,l","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":410,"y":280,"wires":[["f51c8aa4.4a2fe8"]]},{"id":"47a13779bf90e0e5","type":"csv","z":"30af2d3e.d94ea2","name":"","sep":" ","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":",kw,,,l","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":405,"y":240,"wires":[["f9e923ee9521431a"]]},{"id":"f51c8aa4.4a2fe8","type":"debug","z":"30af2d3e.d94ea2","name":"numbers","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":555,"y":280,"wires":[]},{"id":"f9e923ee9521431a","type":"debug","z":"30af2d3e.d94ea2","name":"strings","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":240,"wires":[]}]
3 Likes

Thanks for the help works perfectly :grinning:

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