Hi,
Busy trying to learn Node-red. I'm trying to search a message using match and appropriate REGEX. I've got this working however the result is an Object with a group and associated array. How am I able to output the message as a string with the value of the group that matched.
In my example flow below I'm trying to have the output of msg.area = bathroom much as the msg.topic does.
Code
[
{
"id": "e9ac906fde06ca7e",
"type": "inject",
"z": "92f311dc4ccbcf60",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 220,
"y": 2200,
"wires": [
[
"05cfb0bb4a03329b"
]
]
},
{
"id": "05cfb0bb4a03329b",
"type": "api-current-state",
"z": "92f311dc4ccbcf60",
"name": "",
"server": "2244d24e336a3d2c",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "binary_sensor.bathroom_occupancy",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
},
{
"property": "area",
"propertyType": "msg",
"value": "{\t \"area\":$match(data.entity_id,/^[\\w_]+\\.(\\w+)_.*$/)\t}",
"valueType": "jsonata"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 510,
"y": 2200,
"wires": [
[
"e8455e8d022d6cf0",
"e2f6c8a3bfbb0232"
]
]
},
{
"id": "058dfb0e82cefc9e",
"type": "debug",
"z": "92f311dc4ccbcf60",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "topic",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1020,
"y": 2240,
"wires": []
},
{
"id": "e8455e8d022d6cf0",
"type": "debug",
"z": "92f311dc4ccbcf60",
"name": "Area",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "area",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 850,
"y": 2200,
"wires": []
},
{
"id": "e2f6c8a3bfbb0232",
"type": "change",
"z": "92f311dc4ccbcf60",
"name": "Area",
"rules": [
{
"t": "change",
"p": "topic",
"pt": "msg",
"from": "^[\\w_]+\\.(\\w+)_.*$",
"fromt": "re",
"to": "$1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 830,
"y": 2240,
"wires": [
[
"058dfb0e82cefc9e"
]
]
},
{
"id": "2244d24e336a3d2c",
"type": "server",
"name": "Home Assistant",
"version": 2,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": 30
}
]
Debug output
Thanks!