Skip to content

Instantly share code, notes, and snippets.

@dexif

dexif/README.md Secret

Created April 4, 2021 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexif/de243d8394546753b0419007680654a1 to your computer and use it in GitHub Desktop.
Save dexif/de243d8394546753b0419007680654a1 to your computer and use it in GitHub Desktop.
flespi device disconnected more than 10s - telegram notification

Sometimes it is useful to know that some of your devices are disconnected from flespi servers or unavailable for a long time.

This example shows how quickly and easily it is possible to set up a notification using NodeRed that devices are not available for more than 10 seconds.

You can freely change the response time or change how to notify you.

For example, it may not be a telegram bot, but a REST API request to some service.

[
{
"id": "47285342.2138ec",
"type": "tab",
"label": "Disconnected device",
"disabled": false,
"info": ""
},
{
"id": "d2781dc0.2e318",
"type": "mqtt in",
"z": "47285342.2138ec",
"name": "",
"topic": "flespi/state/gw/devices/+/connected",
"qos": "2",
"datatype": "utf8",
"broker": "b76fa1b5.ce51",
"x": 220,
"y": 220,
"wires": [
[
"84bf212f.09e3f"
]
]
},
{
"id": "c18064a9.df40f8",
"type": "debug",
"z": "47285342.2138ec",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 80,
"wires": []
},
{
"id": "84bf212f.09e3f",
"type": "trigger",
"z": "47285342.2138ec",
"name": "Wait for it (c) Barney (10s)",
"op1": "",
"op2": "",
"op1type": "nul",
"op2type": "payl",
"duration": "10",
"extend": true,
"overrideDelay": false,
"units": "s",
"reset": "true",
"bytopic": "topic",
"topic": "topic",
"outputs": 1,
"x": 490,
"y": 220,
"wires": [
[
"6a9a1525.6ec80c"
]
]
},
{
"id": "cfc279b2.2358d8",
"type": "telegram sender",
"z": "47285342.2138ec",
"name": "",
"bot": "6eaebea0.ccff3",
"haserroroutput": false,
"outputs": 1,
"x": 950,
"y": 220,
"wires": [
[]
]
},
{
"id": "f5d183b1.7b7fa",
"type": "telegram receiver",
"z": "47285342.2138ec",
"name": "",
"bot": "6eaebea0.ccff3",
"saveDataDir": "",
"filterCommands": false,
"x": 170,
"y": 80,
"wires": [
[
"71890518.2a56bc"
],
[
"71890518.2a56bc"
]
]
},
{
"id": "6a9a1525.6ec80c",
"type": "function",
"z": "47285342.2138ec",
"name": "Prepre telegram message",
"func": "var id = msg.topic.split('/')[4]\nvar chats = flow.get('chats') || {}\nvar messages = []\nfor (var chatId in chats) {\n messages.push({topic: msg.topic, payload: {content: `Device ${id} offline for a long time.`, type: 'message', chatId: chatId}})\n}\nreturn [messages];",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 730,
"y": 220,
"wires": [
[
"cfc279b2.2358d8"
]
]
},
{
"id": "71890518.2a56bc",
"type": "function",
"z": "47285342.2138ec",
"name": "Subscribe/Unsubscribe commands",
"func": "var chats = flow.get('chats') || {}\nif (msg.payload.content === '/subscribe') {\n chats[msg.payload.chatId] = true\n}\nif (msg.payload.content === '/unsubscribe') {\n delete chats[msg.payload.chatId]\n}\nflow.set('chats', chats)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "flow.set('chats', {})",
"finalize": "",
"x": 440,
"y": 80,
"wires": [
[
"c18064a9.df40f8"
]
]
},
{
"id": "59599288.5080ec",
"type": "comment",
"z": "47285342.2138ec",
"name": "Please use /subscribe bot command after each restart.",
"info": "",
"x": 280,
"y": 140,
"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
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment