Greetings,
I have been using a door reed switch to notify via mqtt when a door is open or closed. My node-red code has worked really well with one reed switch. Now that I want to add more reed switches I need to modify my code, but I am unsure the best approach. With a single door I wrote my code to have wording for just that door, but for multiple doors I am thinking I will need code that sends alerts absed upon the door alerting.
Here's my code...
[
{
"id": "f24af96c839adf16",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "bce559e2bcf01975",
"type": "mqtt in",
"z": "f24af96c839adf16",
"name": "Studio Door Status",
"topic": "HomeAssistant/Studio/Door/Status",
"qos": "0",
"datatype": "utf8",
"broker": "f1621f1e.35326",
"x": 170,
"y": 400,
"wires": [
[
"13d92fc5e5a8357d"
]
]
},
{
"id": "2d1e24499952a054",
"type": "blynk-ws-out-write",
"z": "f24af96c839adf16",
"name": "DoorStatus",
"pin": "6",
"pinmode": 0,
"client": "e2371786.305248",
"x": 930,
"y": 520,
"wires": []
},
{
"id": "ec9ac712a27e6e78",
"type": "blynk-ws-out-notify",
"z": "f24af96c839adf16",
"name": "Studio Door Open Notify",
"client": "e2371786.305248",
"queue": false,
"rate": 5,
"x": 1210,
"y": 380,
"wires": []
},
{
"id": "7271816e933f2255",
"type": "change",
"z": "f24af96c839adf16",
"name": "Convert Door Status",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "1",
"fromt": "num",
"to": "0",
"tot": "num"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "0",
"fromt": "str",
"to": "255",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 620,
"y": 440,
"wires": [
[
"2d1e24499952a054"
]
]
},
{
"id": "750f0ca47adfc748",
"type": "function",
"z": "f24af96c839adf16",
"name": "Door Open Email",
"func": "msg = {\n payload : \"The Studio Door is OPEN!! \" + Date().toString() + \", Door Status \" +\n msg.payload,\n topic : \"WARNING!! DOOR STATUS\"\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 910,
"y": 420,
"wires": [
[]
]
},
{
"id": "13d92fc5e5a8357d",
"type": "rbe",
"z": "f24af96c839adf16",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 430,
"y": 400,
"wires": [
[
"7271816e933f2255",
"b33070f839a44b63"
]
]
},
{
"id": "b33070f839a44b63",
"type": "switch",
"z": "f24af96c839adf16",
"name": "Door Status Check",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 610,
"y": 360,
"wires": [
[
"60187f35357b3506",
"d975bb60d8ce0667"
],
[
"750f0ca47adfc748",
"84834fd9eb2dec3c"
]
]
},
{
"id": "60187f35357b3506",
"type": "function",
"z": "f24af96c839adf16",
"name": "Door Closed Email",
"func": "msg = {\n payload : \"The Studio Door is CLOSED!! \" + Date().toString() + \", Door Status \" +\n msg.payload,\n topic : \"WARNING!! DOOR STATUS\"\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 910,
"y": 380,
"wires": [
[]
]
},
{
"id": "84834fd9eb2dec3c",
"type": "function",
"z": "f24af96c839adf16",
"name": "Door Open Notification",
"func": "msg = {\n payload : \"The Studio Door is OPEN!! \"\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 920,
"y": 460,
"wires": [
[
"ec9ac712a27e6e78"
]
]
},
{
"id": "d975bb60d8ce0667",
"type": "function",
"z": "f24af96c839adf16",
"name": "Door Closed Notification",
"func": "msg = {\n payload : \"The Studio Door is CLOSED!! \"\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 930,
"y": 340,
"wires": [
[
"ec9ac712a27e6e78"
]
]
},
{
"id": "9a186ae478ba6066",
"type": "mqtt in",
"z": "f24af96c839adf16",
"name": "Man Cave Door",
"topic": "zigbee2mqtt/Man Cave Door",
"qos": "0",
"datatype": "json",
"broker": "f1621f1e.35326",
"nl": false,
"rap": false,
"x": 160,
"y": 340,
"wires": [
[
"b33070f839a44b63"
]
]
},
{
"id": "f1621f1e.35326",
"type": "mqtt-broker",
"name": "Mosquitto",
"broker": "<IP Redacted>",
"port": "<Port Redacted>",
"clientid": "",
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "<REDACTED>",
"type": "blynk-ws-client",
"name": "",
"path": "ws://blynk-cloud.com/websockets",
"key": "<REDACTED>",
"dbg_all": false,
"dbg_read": false,
"dbg_write": false,
"dbg_notify": false,
"dbg_mail": false,
"dbg_prop": false,
"dbg_sync": false,
"dbg_bridge": false,
"dbg_low": false,
"dbg_pins": "",
"multi_cmd": false,
"proxy_type": "no",
"proxy_url": "",
"enabled": true
}
]
I would really like to have a method of alerting where the alert that is emailed out uses the node-red name assigned to the sensor(reed switch). I feel like I am not making this clear, apology.