[
    {
        "id": "2a361e6d99e7bd96",
        "type": "tab",
        "label": "Mailbox",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e9664bc26576c9aa",
        "type": "inject",
        "z": "2a361e6d99e7bd96",
        "name": "Midnight",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "00 00 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 240,
        "wires": [
            [
                "aa213164acdd6432"
            ]
        ]
    },
    {
        "id": "997ea23ed9f0b345",
        "type": "mqtt in",
        "z": "2a361e6d99e7bd96",
        "name": "Message from mailbox",
        "topic": "esp32/lora/relay/mb",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "4c361b39d29448c0",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 340,
        "wires": [
            [
                "387a2e1a7732e8ac"
            ]
        ]
    },
    {
        "id": "aa213164acdd6432",
        "type": "function",
        "z": "2a361e6d99e7bd96",
        "name": "Reset mail count",
        "func": "global.set('daily_mail_count', 0);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "adddb202641a95e3",
        "type": "function",
        "z": "2a361e6d99e7bd96",
        "name": "Update counts and times",
        "func": "var day_count = global.get('daily_mail_count') || 0;\nglobal.set('daily_mail_count', day_count + 1)\n\nvar current_time = new Date().getTime();\nvar last_msg_time = global.get('last_msg_time') || 0;\n\nvar seconds_since_last_msg = (current_time - last_msg_time) / 1000;\n\nif (seconds_since_last_msg < 180) {\n    node.error(\"Got another message with 180 seconds.\", msg);\n    return;\n} else {\n    global.set('last_msg_time', current_time);\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 320,
        "wires": [
            [
                "a33ba283d10fd334",
                "251a6dcebbbf79a2"
            ]
        ]
    },
    {
        "id": "a33ba283d10fd334",
        "type": "switch",
        "z": "2a361e6d99e7bd96",
        "name": "How many today?",
        "property": "daily_mail_count",
        "propertyType": "global",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "num"
            },
            {
                "t": "gte",
                "v": "5",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 5,
        "x": 650,
        "y": 360,
        "wires": [
            [
                "71cd1c68ac48e5a4"
            ],
            [
                "2f8cede90621ce23"
            ],
            [
                "566319d19233358f"
            ],
            [
                "56828d5203524101"
            ],
            [
                "e83b367147d5493d"
            ]
        ]
    },
    {
        "id": "71cd1c68ac48e5a4",
        "type": "change",
        "z": "2a361e6d99e7bd96",
        "name": "First mail",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "The mail's here! 📬. Go get it! 🏃",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 860,
        "y": 160,
        "wires": [
            [
                "73a0190109010a4b",
                "8d111b550cee8c7d"
            ]
        ]
    },
    {
        "id": "2f8cede90621ce23",
        "type": "change",
        "z": "2a361e6d99e7bd96",
        "name": "Second mail",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Someone got the mail? 📫. Good work! 💪",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 870,
        "y": 260,
        "wires": [
            [
                "73a0190109010a4b",
                "8d111b550cee8c7d"
            ]
        ]
    },
    {
        "id": "566319d19233358f",
        "type": "change",
        "z": "2a361e6d99e7bd96",
        "name": "Third mail",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Mailbox opened again? 📬. Maybe it fell open? 🤦",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 860,
        "y": 400,
        "wires": [
            [
                "73a0190109010a4b",
                "8d111b550cee8c7d"
            ]
        ]
    },
    {
        "id": "56828d5203524101",
        "type": "change",
        "z": "2a361e6d99e7bd96",
        "name": "Fourth mail",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Mailbox opened again? 📫. Maybe there's a package on top? 📦",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 870,
        "y": 480,
        "wires": [
            [
                "73a0190109010a4b",
                "8d111b550cee8c7d"
            ]
        ]
    },
    {
        "id": "e83b367147d5493d",
        "type": "change",
        "z": "2a361e6d99e7bd96",
        "name": "More mail",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Mailbox opened again? 📫. What is going on? 💩",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 860,
        "y": 580,
        "wires": [
            [
                "73a0190109010a4b",
                "8d111b550cee8c7d"
            ]
        ]
    },
    {
        "id": "387a2e1a7732e8ac",
        "type": "time-range-switch",
        "z": "2a361e6d99e7bd96",
        "name": "Awake hours",
        "lat": "",
        "lon": "",
        "startTime": "08:00",
        "endTime": "22:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 290,
        "y": 400,
        "wires": [
            [
                "adddb202641a95e3",
                "df609ad5ae77609a"
            ],
            [
                "f4657a3181f295ac"
            ]
        ]
    },
    {
        "id": "f4657a3181f295ac",
        "type": "debug",
        "z": "2a361e6d99e7bd96",
        "name": "Really late",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 540,
        "wires": []
    },
    {
        "id": "251a6dcebbbf79a2",
        "type": "debug",
        "z": "2a361e6d99e7bd96",
        "name": "debug 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 240,
        "wires": []
    },
    {
        "id": "df609ad5ae77609a",
        "type": "debug",
        "z": "2a361e6d99e7bd96",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 460,
        "wires": []
    },
    {
        "id": "8d111b550cee8c7d",
        "type": "twilio out",
        "z": "2a361e6d99e7bd96",
        "twilio": "34907fc35f6b9b6d",
        "twilioType": "sms",
        "url": "",
        "number": "<phone 1>",
        "name": "Text Wife",
        "x": 1140,
        "y": 440,
        "wires": []
    },
    {
        "id": "73a0190109010a4b",
        "type": "twilio out",
        "z": "2a361e6d99e7bd96",
        "twilio": "34907fc35f6b9b6d",
        "twilioType": "sms",
        "url": "",
        "number": "<phone 2>",
        "name": "Text Me",
        "x": 1120,
        "y": 240,
        "wires": []
    },
    {
        "id": "4c361b39d29448c0",
        "type": "mqtt-broker",
        "name": "My Broker",
        "broker": "<broker host>",
        "port": "<broker port>",
        "tls": "31c2c8368e7c4144",
        "clientid": "nodered",
        "autoConnect": true,
        "usetls": true,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": "3600"
    },
    {
        "id": "34907fc35f6b9b6d",
        "type": "twilio-api",
        "name": "",
        "sid": "<twilio sid>",
        "from": "<twilio number>",
        "credentials": {}
    },
    {
        "id": "31c2c8368e7c4144",
        "type": "tls-config",
        "name": "",
        "cert": "",
        "key": "",
        "ca": "",
        "certname": "",
        "keyname": "",
        "caname": "ISRG_Root_X1.pem",
        "servername": "<broker host>",
        "verifyservercert": true,
        "alpnprotocol": ""
    }
]
