Turn flow on/off via iphone

Here's a quick lash-up for a NR flow using the telegram node to control a set of LEDs arranged like a traffic light signal on a WeMos D1 Mini breadboard.
You can modify the "control action" to control something a bit more interesting than a set of LEDs.
You will need to install the Telegram app on your mobile phone and set-up the "bot".
The flow sends an in-line keyboard to your phone that sets up three buttons that will enable you to control the corresponding LEDs connected to a WeMos D1 Mini.

I hope you find this screenshot and flow useful.

[{"id":"5a0551ff.d8fc28","type":"telegram event","z":"3a0044e9.7e57bc","name":"","bot":"8c9e51ff.e69e08","event":"callback_query","autoanswer":true,"x":180,"y":340,"wires":[["f1202281.e315c","8bab54b1.a5515","66ec2f88.3efd28","702874df.c52de4"]]},{"id":"3d29ea20.b65ca6","type":"telegram sender","z":"3a0044e9.7e57bc","name":"show inline keyboard","bot":"8c9e51ff.e69e08","x":720,"y":140,"wires":[["540b658c.2f7064"]]},{"id":"e40d1203.8693f8","type":"function","z":"3a0044e9.7e57bc","name":"initial inline keyboard message","func":"// context.global.keyboard = { pending : true, messageId : msg.payload.messageId };\n\nvar opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\n \"text\": \"RED - \" + flow.get(\"red\") ,\n \"callback_data\": \"red\" \n }, \n {\n \"text\": \"YELLOW - \" + flow.get(\"yellow\"),\n \"callback_data\": \"yellow\" \n },\n {\n \"text\": \"GREEN - \" + flow.get(\"green\"),\n \"callback_data\": \"green\" \n }\n ]]\n })\n};\n\nmsg.payload.content = 'Click to toggle LEDs';\nmsg.payload.options = opts;\n\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":450,"y":140,"wires":[["3d29ea20.b65ca6"]]},{"id":"987c8fb4.be7e1","type":"telegram command","z":"3a0044e9.7e57bc","name":"/start","command":"/start","bot":"8c9e51ff.e69e08","strict":false,"x":150,"y":160,"wires":[["e40d1203.8693f8"],[]]},{"id":"be868f52.d4394","type":"function","z":"3a0044e9.7e57bc","name":"evaluate callback query","func":"var red    = flow.get(\"red\") || \"off\";\nvar yellow = flow.get(\"yellow\") || \"off\";\nvar green  = flow.get(\"green\") || \"off\";\n\n// msg.payload.reply_to_message_Id = msg.payload.messageId;\n\n// This is a sample switch to demonstrate the handling of the user input.\n// msg.payload.options = context.global.keyboard.messageId;\n// msg.payload.type = 'editMessageReplyMarkup';\n// msg.payload.options = {parse_mode: \"Markdown\"};\n\nmsg.payload.options = {reply_to_message_id: msg.payload.messageId};\n\nmsg.payload.type = 'message';\n\nmsg.payload.content= \"- - - Status report for LEDs - - -\\r\\n\\r\\n\";\nmsg.payload.content += \"RED led = \" + red + \"\\r\\n\";\nmsg.payload.content += \"YEL led = \" + yellow + \"\\r\\n\";\nmsg.payload.content += \"GRN led = \" + green + \"\\r\\n\";\nmsg.payload.content += \"\\r\\n- - - End of status report - - -\\r\\n\";\n\nreturn [ msg ];","outputs":1,"noerr":0,"x":610,"y":340,"wires":[["5af6f94f.291c48"]]},{"id":"cc1866de.733b7","type":"telegram sender","z":"3a0044e9.7e57bc","name":"answer callback query","bot":"8c9e51ff.e69e08","x":1040,"y":340,"wires":[["82e7f9b9.9dd768","74dab1ae.dff4"]]},{"id":"540b658c.2f7064","type":"debug","z":"3a0044e9.7e57bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":140,"wires":[]},{"id":"82e7f9b9.9dd768","type":"debug","z":"3a0044e9.7e57bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1250,"y":340,"wires":[]},{"id":"74dab1ae.dff4","type":"delay","z":"3a0044e9.7e57bc","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":470,"y":220,"wires":[["e40d1203.8693f8"]]},{"id":"be1b818d.cb2bb8","type":"mqtt out","z":"3a0044e9.7e57bc","name":"","topic":"/node23/gpio/15","qos":"","retain":"","broker":"6a53712f.418b4","x":790,"y":440,"wires":[]},{"id":"8132eb24.b6952","type":"inject","z":"3a0044e9.7e57bc","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":"1","x":170,"y":80,"wires":[["fb34f30d.36e15"]]},{"id":"fb34f30d.36e15","type":"function","z":"3a0044e9.7e57bc","name":"","func":"flow.set(\"red\",\"off\");\nflow.set(\"yellow\",\"off\");\nflow.set(\"green\",\"off\");\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":80,"wires":[[]]},{"id":"f1202281.e315c","type":"function","z":"3a0044e9.7e57bc","name":"evaluate callback query for RED led","func":"var red = flow.get(\"red\")|| \"off\";\n\nif (msg.payload.content == \"red\")\n{\n    if (red == \"off\")\n    {\n        red = \"on\";\n        msg.payload = 1;\n        node.status({fill:\"red\",shape:\"dot\"});\n    }\n\n    else\n    {\n        red = \"off\";\n        msg.payload = 0;\n        node.status({});\n    }\n    flow.set(\"red\",red);\n}\n\n \nreturn msg;","outputs":1,"noerr":0,"x":460,"y":440,"wires":[["be1b818d.cb2bb8"]]},{"id":"8bab54b1.a5515","type":"delay","z":"3a0044e9.7e57bc","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":390,"y":340,"wires":[["be868f52.d4394"]]},{"id":"59869912.0aa24","type":"mqtt out","z":"3a0044e9.7e57bc","name":"","topic":"/node23/gpio/13","qos":"","retain":"","broker":"6a53712f.418b4","x":790,"y":500,"wires":[]},{"id":"66ec2f88.3efd28","type":"function","z":"3a0044e9.7e57bc","name":"evaluate callback query for YELLOW led","func":"var yellow = flow.get(\"yellow\")|| \"off\";\n\nif (msg.payload.content == \"yellow\")\n{\n    if (yellow == \"off\")\n    {\n        yellow = \"on\";\n        msg.payload = 1;\n        node.status({fill:\"yellow\",shape:\"dot\"});\n    }\n\n    else\n    {\n        yellow = \"off\";\n        msg.payload = 0;\n        node.status({});\n    }\n    flow.set(\"yellow\",yellow);\n}\n\n \nreturn msg;","outputs":1,"noerr":0,"x":480,"y":500,"wires":[["59869912.0aa24"]]},{"id":"933358fb.2c4218","type":"mqtt out","z":"3a0044e9.7e57bc","name":"","topic":"/node23/gpio/12","qos":"","retain":"","broker":"6a53712f.418b4","x":790,"y":560,"wires":[]},{"id":"702874df.c52de4","type":"function","z":"3a0044e9.7e57bc","name":"evaluate callback query for GREEN led","func":"var green = flow.get(\"green\")|| \"off\";\n\nif (msg.payload.content == \"green\")\n{\n    if (green == \"off\")\n    {\n        green = \"on\";\n        msg.payload = 1;\n        node.status({fill:\"green\",shape:\"dot\"});\n    }\n\n    else\n    {\n        green = \"off\";\n        msg.payload = 0;\n        node.status({});\n    }\n    flow.set(\"green\",green);\n}\n\n \nreturn msg;","outputs":1,"noerr":0,"x":470,"y":560,"wires":[["933358fb.2c4218"]]},{"id":"5af6f94f.291c48","type":"delay","z":"3a0044e9.7e57bc","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":830,"y":340,"wires":[["cc1866de.733b7"]]},{"id":"8c9e51ff.e69e08","type":"telegram bot","z":"","botname":"rgb_leds_bot","usernames":"","chatids":"","baseapiurl":"","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"verboselogging":false},{"id":"6a53712f.418b4","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.140","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
3 Likes