Node Red Mail Delivery Alert Flows

The following flow utilizes a motion sensor to detect when the mailbox is opened. When opened a combination of switch and change nodes is used to determine the current status of the mailbox based on a variable and toggle the variable. If the toggle indicated the mail as delivered a mp3 file is played on a google mini and a 15 minute stop timer is activated which will re-trigger the alert and reset itself. If the toggle indicates the mail is being retrieved it sends a stop command to the timer.

I highly simplified this flow for the post and will post more complicated versions that include time of day trigger preventions (so you dont trigger mail alerts when putting mail out at night) along with text notifications to your phone in a bit… :wink:

Flow Copy Paste

[{"id":"460de637.7f30b","type":"tab","label":"Mail Call","disabled":false,"info":""},{"id":"fa134b7.00458b8","type":"device-status","z":"460de637.7f30b","name":"Mail Motion","deviceName":"Mailbox Motion Sensor","bridge":"ddaf8308.850e08","genericMqttDevice":false,"device":"","x":90,"y":220,"wires":[["15a3ca1c.4df44e"]]},{"id":"15a3ca1c.4df44e","type":"switch","z":"460de637.7f30b","name":"Activated","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":280,"y":220,"wires":[["cff6383f.8273c"]]},{"id":"cff6383f.8273c","type":"change","z":"460de637.7f30b","name":"Check Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::mail","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":220,"wires":[["71fc1b91.578664"]]},{"id":"71fc1b91.578664","type":"switch","z":"460de637.7f30b","name":"status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"retrieved","vt":"str"},{"t":"eq","v":"delivered","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":220,"wires":[["d652d67a.8e5cb8"],["7e14518a.3854f8"]]},{"id":"2ae3a93.efde356","type":"change","z":"460de637.7f30b","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":260,"wires":[["4a3033af.9dc314"]]},{"id":"4a3033af.9dc314","type":"stoptimer2","z":"460de637.7f30b","duration":"15","durationType":"num","units":"Minute","payloadtype":"str","payloadval":"0","name":"","x":1420,"y":240,"wires":[["2b4a2e3f.087402","9b40712c.9fc52"],[]]},{"id":"d652d67a.8e5cb8","type":"change","z":"460de637.7f30b","name":"Set delivered","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"delivered","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":200,"wires":[["4a3033af.9dc314","9b40712c.9fc52"]]},{"id":"7e14518a.3854f8","type":"change","z":"460de637.7f30b","name":"Set Retrieved","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"retrieved","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":240,"wires":[["2ae3a93.efde356"]]},{"id":"2b4a2e3f.087402","type":"delay","z":"460de637.7f30b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1340,"y":160,"wires":[["4a3033af.9dc314"]]},{"id":"4fcab398.fc391c","type":"cast-to-client","z":"460de637.7f30b","name":"Got Mail","url":"http://192.168.0.9:1880/files/gotmail.mp3","contentType":"","message":"","language":"en","ip":"192.168.24.28","port":"32000","volume":"50","x":1460,"y":40,"wires":[[]]},{"id":"9b40712c.9fc52","type":"change","z":"460de637.7f30b","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"devicename","pt":"msg"},{"t":"delete","p":"device","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":140,"wires":[["4fcab398.fc391c"]]},{"id":"ddaf8308.850e08","type":"zigbee2mqtt-bridge-config","name":"Pi","broker":"bccbde70.b7c568","baseTopic":"zigbee2mqtt","enabledLogging":false,"allowDeviceStatusRefresh":true},{"id":"bccbde70.b7c568","type":"mqtt-broker","name":"Pi","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
3 Likes

Lets add a bit more complexity to the last flow and spread our nodes out a bit to make it easier to follow.

In this flow we have added a text notification to our phone which is being sent via gmail, and we have also added some node red dashboard interfaces to show the current status of the mail, and allow us to manually toggle the status in case of false triggers.

Flow Copy Paste

[{"id":"460de637.7f30b","type":"tab","label":"Mail Call","disabled":false,"info":""},{"id":"5483239a.2d7abc","type":"function","z":"460de637.7f30b","name":"Compose Mail message","func":"var timeAsString = msg.mytimes;\n\nmsg.payload =               ' Mail Delivered at ' + \n              timeAsString + '.';\n                  \nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1290,"y":440,"wires":[["bdd66390.5e21a"]]},{"id":"ec28d5b0.55ac68","type":"change","z":"460de637.7f30b","name":"","rules":[{"t":"delete","p":"","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":380,"wires":[["fe7871b4.af07f"]]},{"id":"fe7871b4.af07f","type":"simpletime","z":"460de637.7f30b","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":1420,"y":380,"wires":[["5483239a.2d7abc"]]},{"id":"bdd66390.5e21a","type":"e-mail","z":"460de637.7f30b","server":"smtp.gmail.com","port":"465","secure":true,"tls":false,"name":"[email protected]","dname":"","x":1570,"y":440,"wires":[]},{"id":"fa134b7.00458b8","type":"device-status","z":"460de637.7f30b","name":"Mail Motion","deviceName":"Mailbox Motion Sensor","bridge":"ddaf8308.850e08","genericMqttDevice":false,"device":"","x":90,"y":220,"wires":[["15a3ca1c.4df44e"]]},{"id":"15a3ca1c.4df44e","type":"switch","z":"460de637.7f30b","name":"Activated","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":280,"y":220,"wires":[["cff6383f.8273c"]]},{"id":"cff6383f.8273c","type":"change","z":"460de637.7f30b","name":"Check Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::mail","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":220,"wires":[["71fc1b91.578664"]]},{"id":"71fc1b91.578664","type":"switch","z":"460de637.7f30b","name":"status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"retrieved","vt":"str"},{"t":"eq","v":"delivered","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":220,"wires":[["d652d67a.8e5cb8"],["7e14518a.3854f8"]]},{"id":"2ae3a93.efde356","type":"change","z":"460de637.7f30b","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":260,"wires":[["4a3033af.9dc314"]]},{"id":"4a3033af.9dc314","type":"stoptimer2","z":"460de637.7f30b","duration":"15","durationType":"num","units":"Minute","payloadtype":"str","payloadval":"0","name":"","x":1460,"y":240,"wires":[["2b4a2e3f.087402","9b40712c.9fc52"],[]]},{"id":"d652d67a.8e5cb8","type":"change","z":"460de637.7f30b","name":"Set delivered","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"delivered","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":180,"wires":[["4a3033af.9dc314","9b40712c.9fc52","a5fc8744.d54e1","e991d874.c95db","ec28d5b0.55ac68"]]},{"id":"7e14518a.3854f8","type":"change","z":"460de637.7f30b","name":"Set Retrieved","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"retrieved","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":320,"wires":[["2ae3a93.efde356","a5fc8744.d54e1","e991d874.c95db"]]},{"id":"2b4a2e3f.087402","type":"delay","z":"460de637.7f30b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1460,"y":320,"wires":[["4a3033af.9dc314"]]},{"id":"4fcab398.fc391c","type":"cast-to-client","z":"460de637.7f30b","name":"Got Mail","url":"http://192.168.0.9:1880/files/gotmail.mp3","contentType":"","message":"","language":"en","ip":"192.168.24.28","port":"32000","volume":"50","x":1460,"y":40,"wires":[[]]},{"id":"9b40712c.9fc52","type":"change","z":"460de637.7f30b","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"devicename","pt":"msg"},{"t":"delete","p":"device","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":140,"wires":[["4fcab398.fc391c"]]},{"id":"a5fc8744.d54e1","type":"ui_text","z":"460de637.7f30b","group":"dfb4a60f.d788f8","order":9,"width":0,"height":0,"name":"Mail Status","label":"Mail:","format":"{{msg.payload}}","layout":"col-center","x":990,"y":420,"wires":[]},{"id":"7670eba4.fce97c","type":"change","z":"460de637.7f30b","name":"Check Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::mail","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":420,"wires":[["a5fc8744.d54e1"]]},{"id":"c4f9252.f49af58","type":"inject","z":"460de637.7f30b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":420,"wires":[["7670eba4.fce97c"]]},{"id":"e991d874.c95db","type":"ui_switch","z":"460de637.7f30b","name":"","label":"Mail Over-Ride","tooltip":"off retrieved, on delivered","group":"dfb4a60f.d788f8","order":9,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"payload","topicType":"str","style":"","onvalue":"delivered","onvalueType":"str","onicon":"","oncolor":"","offvalue":"retrieved","offvalueType":"str","officon":"","offcolor":"","animate":false,"x":920,"y":60,"wires":[["cff6383f.8273c"]]},{"id":"ddaf8308.850e08","type":"zigbee2mqtt-bridge-config","name":"Pi","broker":"bccbde70.b7c568","baseTopic":"zigbee2mqtt","enabledLogging":false,"allowDeviceStatusRefresh":true},{"id":"dfb4a60f.d788f8","type":"ui_group","name":"Front Room","tab":"48418b79.0f5834","order":1,"disp":true,"width":"6","collapse":true},{"id":"bccbde70.b7c568","type":"mqtt-broker","name":"Pi","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"48418b79.0f5834","type":"ui_tab","name":"Front Room","icon":"Dashboard","order":1,"disabled":false,"hidden":false}]

And adding a time range trigger is one way to prevent false status changes and alerts outside of your normal mail delivery and retrieval times.

[{"id":"460de637.7f30b","type":"tab","label":"Mail Call","disabled":false,"info":""},{"id":"5483239a.2d7abc","type":"function","z":"460de637.7f30b","name":"Compose Mail message","func":"var timeAsString = msg.mytimes;\n\nmsg.payload =               ' Mail Delivered at ' + \n              timeAsString + '.';\n                  \nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1290,"y":440,"wires":[["bdd66390.5e21a"]]},{"id":"ec28d5b0.55ac68","type":"change","z":"460de637.7f30b","name":"","rules":[{"t":"delete","p":"","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":380,"wires":[["fe7871b4.af07f"]]},{"id":"fe7871b4.af07f","type":"simpletime","z":"460de637.7f30b","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":1420,"y":380,"wires":[["5483239a.2d7abc"]]},{"id":"bdd66390.5e21a","type":"e-mail","z":"460de637.7f30b","server":"smtp.gmail.com","port":"465","secure":true,"tls":false,"name":"[email protected]","dname":"","x":1570,"y":440,"wires":[]},{"id":"fa134b7.00458b8","type":"device-status","z":"460de637.7f30b","name":"Mail Motion","deviceName":"Mailbox Motion Sensor","bridge":"ddaf8308.850e08","genericMqttDevice":false,"device":"","x":90,"y":40,"wires":[["15a3ca1c.4df44e"]]},{"id":"15a3ca1c.4df44e","type":"switch","z":"460de637.7f30b","name":"Activated","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":40,"wires":[["4347eb8.9d42d14"]]},{"id":"cff6383f.8273c","type":"change","z":"460de637.7f30b","name":"Check Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::mail","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":220,"wires":[["71fc1b91.578664"]]},{"id":"71fc1b91.578664","type":"switch","z":"460de637.7f30b","name":"status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"retrieved","vt":"str"},{"t":"eq","v":"delivered","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":220,"wires":[["d652d67a.8e5cb8"],["7e14518a.3854f8"]]},{"id":"2ae3a93.efde356","type":"change","z":"460de637.7f30b","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":260,"wires":[["4a3033af.9dc314"]]},{"id":"4a3033af.9dc314","type":"stoptimer2","z":"460de637.7f30b","duration":"15","durationType":"num","units":"Minute","payloadtype":"str","payloadval":"0","name":"","x":1460,"y":240,"wires":[["2b4a2e3f.087402","9b40712c.9fc52"],[]]},{"id":"d652d67a.8e5cb8","type":"change","z":"460de637.7f30b","name":"Set delivered","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"delivered","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":180,"wires":[["4a3033af.9dc314","9b40712c.9fc52","a5fc8744.d54e1","e991d874.c95db","ec28d5b0.55ac68"]]},{"id":"7e14518a.3854f8","type":"change","z":"460de637.7f30b","name":"Set Retrieved","rules":[{"t":"delete","p":"#:(file)::mail","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"retrieved","tot":"str"},{"t":"set","p":"#:(file)::mail","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":320,"wires":[["2ae3a93.efde356","a5fc8744.d54e1","e991d874.c95db"]]},{"id":"2b4a2e3f.087402","type":"delay","z":"460de637.7f30b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1460,"y":320,"wires":[["4a3033af.9dc314"]]},{"id":"4fcab398.fc391c","type":"cast-to-client","z":"460de637.7f30b","name":"Got Mail","url":"http://192.168.0.9:1880/files/gotmail.mp3","contentType":"","message":"","language":"en","ip":"192.168.24.28","port":"32000","volume":"50","x":1460,"y":40,"wires":[[]]},{"id":"9b40712c.9fc52","type":"change","z":"460de637.7f30b","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"devicename","pt":"msg"},{"t":"delete","p":"device","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":140,"wires":[["4fcab398.fc391c"]]},{"id":"a5fc8744.d54e1","type":"ui_text","z":"460de637.7f30b","group":"dfb4a60f.d788f8","order":9,"width":0,"height":0,"name":"Mail Status","label":"Mail:","format":"{{msg.payload}}","layout":"col-center","x":990,"y":420,"wires":[]},{"id":"7670eba4.fce97c","type":"change","z":"460de637.7f30b","name":"Check Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::mail","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":420,"wires":[["a5fc8744.d54e1"]]},{"id":"c4f9252.f49af58","type":"inject","z":"460de637.7f30b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":420,"wires":[["7670eba4.fce97c"]]},{"id":"e991d874.c95db","type":"ui_switch","z":"460de637.7f30b","name":"","label":"Mail Over-Ride","tooltip":"off retrieved, on delivered","group":"dfb4a60f.d788f8","order":9,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"payload","topicType":"str","style":"","onvalue":"delivered","onvalueType":"str","onicon":"","oncolor":"","offvalue":"retrieved","offvalueType":"str","officon":"","offcolor":"","animate":false,"x":920,"y":60,"wires":[["cff6383f.8273c"]]},{"id":"4347eb8.9d42d14","type":"time-range-switch","z":"460de637.7f30b","name":"","lat":"","lon":"","startTime":"08:00","endTime":"4:00","startOffset":0,"endOffset":0,"x":350,"y":120,"wires":[["cff6383f.8273c"],[]]},{"id":"ddaf8308.850e08","type":"zigbee2mqtt-bridge-config","name":"Pi","broker":"bccbde70.b7c568","baseTopic":"zigbee2mqtt","enabledLogging":false,"allowDeviceStatusRefresh":true},{"id":"dfb4a60f.d788f8","type":"ui_group","name":"Front Room","tab":"48418b79.0f5834","order":1,"disp":true,"width":"6","collapse":true},{"id":"bccbde70.b7c568","type":"mqtt-broker","name":"Pi","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"48418b79.0f5834","type":"ui_tab","name":"Front Room","icon":"Dashboard","order":1,"disabled":false,"hidden":false}]

You can take the false alert prevention even further if you have multiple people who like to check the mail with a simple function/counter that only allows 2 messages to pass through per day.