Hi @AleXSR700 Alex,
Yesterday I stumbled on a very similar issue you had and spent half a day looking for the elegant solution, tested JSonata, tried different javascripts, etc, etc, but nothing worked well enough, or wasn't elegant And looks like I am using a similar setup to yours - few Mi reflashed temp/humidity sensors (ATC), some Flora plant sensors, some low temperature sensors from other providers (can't remember exact brandname), as well as ESP32 with Tasmota and tasmota-blerry (GitHub - tony-fav/tasmota-blerry). So my JSON payloads looked very similar and it had part of the MAC address incorporated into the message attribute as well as single msg would have data from a few sensors. So after countless hours I guess I found a solution that works really nice, looks absolutely simple, and even notifies me by sending a Telegram message if some new BT sensor appears in near proximity advertising any data. And the solution was to split these messages using Split node! After that, I can use a Switch node where I just route messages to different outputs using MAC address of each sensor. There is my flow, just change MAC addresses at the Split node and it should be good to go!
[
{
"id": "52b2a545b72cfa71",
"type": "tab",
"label": "BT playground",
"disabled": false,
"info": ""
},
{
"id": "04e1de72fcd923c9",
"type": "mqtt in",
"z": "52b2a545b72cfa71",
"name": "",
"topic": "tele/ESP32_TTGO/SENSOR",
"qos": "2",
"datatype": "auto",
"broker": "e48f09ae03fedc14",
"nl": false,
"rap": true,
"rh": 0,
"x": 180,
"y": 360,
"wires": [
[
"4b5cdbfc0e4aa168"
]
]
},
{
"id": "4b5cdbfc0e4aa168",
"type": "json",
"z": "52b2a545b72cfa71",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 130,
"y": 420,
"wires": [
[
"681534a78b9adc5e"
]
]
},
{
"id": "681534a78b9adc5e",
"type": "split",
"z": "52b2a545b72cfa71",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 270,
"y": 420,
"wires": [
[
"e5a77bf21953892c"
]
]
},
{
"id": "32486456ea455ed3",
"type": "switch",
"z": "52b2a545b72cfa71",
"name": "MAC",
"property": "payload.mac",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "a4c138ff28a3",
"vt": "str"
},
{
"t": "eq",
"v": "a4c1386897d4",
"vt": "str"
},
{
"t": "eq",
"v": "c47c8d6d5f6a",
"vt": "str"
},
{
"t": "eq",
"v": "a4c13848693f",
"vt": "str"
},
{
"t": "eq",
"v": "a4c1387d88b3",
"vt": "str"
},
{
"t": "eq",
"v": "a4c138ba35d5",
"vt": "str"
},
{
"t": "eq",
"v": "a4c138743a83",
"vt": "str"
},
{
"t": "eq",
"v": "a4c138957b93",
"vt": "str"
},
{
"t": "eq",
"v": "a4c138861f45",
"vt": "str"
},
{
"t": "eq",
"v": "c47c8d6d614e",
"vt": "str"
},
{
"t": "eq",
"v": "a4c138cce2c4",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 12,
"x": 550,
"y": 420,
"wires": [
[
"4c36bebd1fb7117a"
],
[
"084e113f9cf70f54"
],
[
"d4d41c4f1837a37e"
],
[
"47aad4e57787631d"
],
[
"805c966f49cbb098"
],
[
"5e36a488f2e45872"
],
[
"f9e6a5b9858ed54e"
],
[
"3daec7313e6d86c1"
],
[
"9790c2af543dd33e"
],
[
"09dfe887802b3db9"
],
[
"de3801a43ae74740"
],
[
"2101bf4b50b16521"
]
]
},
{
"id": "4c36bebd1fb7117a",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138ff28a3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 220,
"wires": [],
"icon": "font-awesome/fa-terminal"
},
{
"id": "084e113f9cf70f54",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c1386897d4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 260,
"wires": []
},
{
"id": "d4d41c4f1837a37e",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "c47c8d6d5f6a",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 300,
"wires": []
},
{
"id": "47aad4e57787631d",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c13848693f",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 340,
"wires": []
},
{
"id": "805c966f49cbb098",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c1387d88b3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 380,
"wires": []
},
{
"id": "5e36a488f2e45872",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138ba35d5",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 420,
"wires": []
},
{
"id": "f9e6a5b9858ed54e",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138743a83",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 460,
"wires": []
},
{
"id": "3daec7313e6d86c1",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138957b93",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 500,
"wires": []
},
{
"id": "9790c2af543dd33e",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138861f45",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 540,
"wires": []
},
{
"id": "09dfe887802b3db9",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "c47c8d6d614e",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 580,
"wires": []
},
{
"id": "de3801a43ae74740",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "a4c138cce2c4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 740,
"y": 620,
"wires": []
},
{
"id": "e5a77bf21953892c",
"type": "function",
"z": "52b2a545b72cfa71",
"name": "Filter",
"func": "if (msg.payload != \"C\") {\n return msg;}\nelse {\n return null;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 410,
"y": 420,
"wires": [
[
"32486456ea455ed3"
]
]
},
{
"id": "ba5ad095c774f057",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "Time",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 870,
"y": 60,
"wires": []
},
{
"id": "2101bf4b50b16521",
"type": "switch",
"z": "52b2a545b72cfa71",
"name": "non MAC",
"property": "parts.key",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "Time",
"vt": "str"
},
{
"t": "eq",
"v": "ANALOG",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 720,
"y": 100,
"wires": [
[
"ba5ad095c774f057"
],
[
"8a11aa18418b980e"
],
[
"480f31ca3b8cb9f7",
"a1ee28e00882e162"
]
]
},
{
"id": "8a11aa18418b980e",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "Range1",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 100,
"wires": []
},
{
"id": "480f31ca3b8cb9f7",
"type": "debug",
"z": "52b2a545b72cfa71",
"name": "Unknown",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 140,
"wires": []
},
{
"id": "546f7588d1738427",
"type": "telegram sender",
"z": "52b2a545b72cfa71",
"name": "New BT Device",
"bot": "XXX",
"haserroroutput": false,
"outputs": 1,
"x": 900,
"y": 180,
"wires": [
[]
]
},
{
"id": "a1ee28e00882e162",
"type": "function",
"z": "52b2a545b72cfa71",
"name": "Format",
"func": "payload = {\n chatId:XXX,\n type:\"message\",\n content: \"New BT device discovered\"\n};\n\nreturn {payload};\n\n/*\nhi= \"New BT device discovered \";\npayload={chatId:XXX,\ntype:\"message\",\ncontent: hi\n};\nreturn {payload};\n*/",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 740,
"y": 180,
"wires": [
[
"546f7588d1738427"
]
]
},
{
"id": "XXX",
"type": "mqtt-broker",
"name": "Brain",
"broker": "123.123.123.123",
"port": "1883",
"tls": "",
"clientid": "",
"usetls": false,
"protocolVersion": "5",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "XXXXX",
"type": "telegram bot",
"botname": "New BT Device",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"usesocks": false,
"sockshost": "",
"socksprotocol": "socks5",
"socksport": "6667",
"socksusername": "anonymous",
"sockspassword": "",
"bothost": "",
"botpath": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"useselfsignedcertificate": false,
"sslterminated": false,
"verboselogging": false
}
]