Simply try the function node from this flow:
[
{
"id": "2e6a5c51.991544",
"type": "inject",
"z": "6b8efe0d.bc75e",
"name": "",
"topic": "",
"payload": "{\"sid\":89597,\"ludt\":\"2020-03-18 09:21:40\",\"E-Today\":{\"unit\":\"kWh\",\"value\":31.5},\"E-Month\":{\"unit\":\"kWh\",\"value\":33.57},\"E-Total\":{\"unit\":\"kWh\",\"value\":33.67},\"TotalYield\":{\"unit\":\"$\",\"value\":23.57},\"CO2Avoided\":{\"unit\":\"kg\",\"value\":26.94},\"Power\":{\"unit\":\"kW\",\"value\":3.45}}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 1820,
"wires": [
[
"8b49d860.fe48f8",
"d572b70.44fc348"
]
]
},
{
"id": "d572b70.44fc348",
"type": "debug",
"z": "6b8efe0d.bc75e",
"name": "Snapcast",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 720,
"y": 1820,
"wires": []
},
{
"id": "8b49d860.fe48f8",
"type": "function",
"z": "6b8efe0d.bc75e",
"name": "kW or W",
"func": "newmsg = {}\n\nif (msg.payload.Power.unit == \"kW\")\n{ \n newmsg.payload = msg.payload.Power.value * 1000;\n}\nelse\n{\n newmsg.payload = msg.payload.Power.value;\n}\n\n\n\nreturn newmsg;",
"outputs": 1,
"noerr": 0,
"x": 440,
"y": 1820,
"wires": [
[
"d572b70.44fc348"
]
]
}
]
Or if you want to do it without a function node you can also easily do it with a switch and a calculator node:
[
{
"id": "2e6a5c51.991544",
"type": "inject",
"z": "6b8efe0d.bc75e",
"name": "",
"topic": "",
"payload": "{\"sid\":89597,\"ludt\":\"2020-03-18 09:21:40\",\"E-Today\":{\"unit\":\"kWh\",\"value\":31.5},\"E-Month\":{\"unit\":\"kWh\",\"value\":33.57},\"E-Total\":{\"unit\":\"kWh\",\"value\":33.67},\"TotalYield\":{\"unit\":\"$\",\"value\":23.57},\"CO2Avoided\":{\"unit\":\"kg\",\"value\":26.94},\"Power\":{\"unit\":\"kW\",\"value\":3.45}}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 130,
"y": 1740,
"wires": [
[
"aca318a0.2d54a8"
]
]
},
{
"id": "d572b70.44fc348",
"type": "debug",
"z": "6b8efe0d.bc75e",
"name": "VALUE",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 600,
"y": 1800,
"wires": []
},
{
"id": "226b12.573534ee",
"type": "calculator",
"z": "6b8efe0d.bc75e",
"name": "",
"inputMsgField": "payload.Power.value",
"outputMsgField": "payload.Power.value",
"operation": "mult",
"constant": "1000",
"x": 440,
"y": 1740,
"wires": [
[
"d572b70.44fc348"
]
]
},
{
"id": "aca318a0.2d54a8",
"type": "switch",
"z": "6b8efe0d.bc75e",
"name": "",
"property": "payload.Power.unit",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "kW",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 270,
"y": 1740,
"wires": [
[
"226b12.573534ee"
],
[
"d572b70.44fc348"
]
]
}
]