flespi device exceeded certain storage size - telegram notification

Example of telegram notifications that the flespi device storage is full to a certain volume.

In the subscribe command, you must now specify the size, when exceeding which you want to receive a notification in the telegram messenger:

/subscribe messages_size 1024

(1024 in this example is the storage size in bytes)

[{"id":"26fdb68f.692cda","type":"tab","label":"Device messages size","disabled":false,"info":""},{"id":"3351aaec.720636","type":"mqtt in","z":"26fdb68f.692cda","name":"","topic":"flespi/state/gw/devices/+/messages_size","qos":"2","datatype":"utf8","broker":"b76fa1b5.ce51","x":180,"y":160,"wires":[["1cb53414.e2676c"]]},{"id":"261b1a03.6b9416","type":"debug","z":"26fdb68f.692cda","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":100,"wires":[]},{"id":"1cb53414.e2676c","type":"trigger","z":"26fdb68f.692cda","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":430,"y":160,"wires":[["e76f4405.0dbae8"]]},{"id":"176adc5c.727354","type":"telegram sender","z":"26fdb68f.692cda","name":"","bot":"6eaebea0.ccff3","haserroroutput":false,"outputs":1,"x":850,"y":160,"wires":[[]]},{"id":"f27f7ff3.4ea52","type":"telegram receiver","z":"26fdb68f.692cda","name":"","bot":"6eaebea0.ccff3","saveDataDir":"","filterCommands":false,"x":390,"y":100,"wires":[["9d23cf10.cad8d"],["9d23cf10.cad8d"]]},{"id":"e76f4405.0dbae8","type":"function","z":"26fdb68f.692cda","name":"Prepre telegram message","func":"var id = msg.topic.split('/')[4]\nvar chats = flow.get('chats') || {}\nvar devices = flow.get('devices') || {}\nvar messages = []\nvar current_size = parseInt(msg.payload)\nfor (var chatId in chats) {\n    if (\n        current_size >= chats[chatId] && \n        (devices[id] || 0) < chats[chatId] && \n        devices[id] < current_size\n    ) {\n        messages.push({topic: msg.topic, payload: {content: `Device ${id} is using too much storage (${current_size})`, type: 'message', chatId: chatId}})\n    }\n}\ndevices[id] = current_size\nflow.set('devices', devices)\nreturn [messages]","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":160,"wires":[["176adc5c.727354","261b1a03.6b9416"]]},{"id":"9d23cf10.cad8d","type":"function","z":"26fdb68f.692cda","name":"Process commands","func":"var chats = flow.get('chats') || {}\nif (msg.payload.content.indexOf('/subscribe messages_size') == 0) {\n    chats[msg.payload.chatId] = parseInt(msg.payload.content.replace('/subscribe messages_size', ''))\n}\nif (msg.payload.content === '/unsubscribe messages_size') {\n    delete chats[msg.payload.chatId]\n}\nflow.set('chats', chats)\nreturn msg;","outputs":1,"noerr":0,"initialize":"flow.set('chats', {})","finalize":"","x":610,"y":100,"wires":[["261b1a03.6b9416"]]},{"id":"9782a1dc.04acf","type":"comment","z":"26fdb68f.692cda","name":"Please use \"/subscribe messages_size 1024\" bot command after each restart (1024 bytes)","info":"","x":330,"y":40,"wires":[],"icon":"node-red/alert.svg"},{"id":"b76fa1b5.ce51","type":"mqtt-broker","name":"","broker":"mqtt.flespi.io","port":"1883","clientid":"noderedtest","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"6eaebea0.ccff3","type":"telegram bot","botname":"Telegram notify bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

Flow Info

Created 3 years, 3 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • function (x2)
  • mqtt in (x1)
  • mqtt-broker (x1)
  • trigger (x1)
Other

Tags

  • flespi
  • device
  • messages
  • size
  • telegram
  • notification
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option