My payload is :
msg.payload : string[14]
"amp:volume=38$"
I want to only send 38 in my sensor in home assistant .
what can I do ?
Thx
My payload is :
msg.payload : string[14]
"amp:volume=38$"
I want to only send 38 in my sensor in home assistant .
what can I do ?
Thx
In a Change node, use
Set: msg payload (or whatever you wish) to
to the value J: Expression
and enter the following JSONata expression
$match(payload, /\d+/ )[0].match~>$number()
That performs a regex match for a group of one or more digits [0-9], returns an array of the matches (there should only be one), picks the first match string, and turns it into a number (if you want just the “38” as a string, drop the ~>$number() part).
Should work for you as long as your embedded number is an integer.
[
{
"id": "2c0d97e5832a9126",
"type": "change",
"z": "e6f8ea0317d4f26a",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$match(payload, /\\d+/ )[0].match~>$number()",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 500,
"y": 2820,
"wires": [
[
"9aad677dd5839800"
]
]
}
]