Skip to content

Instantly share code, notes, and snippets.

@marciogranzotto
Last active November 21, 2020 03:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciogranzotto/90c289032e1931d84f6501a8ebdf0513 to your computer and use it in GitHub Desktop.
Save marciogranzotto/90c289032e1931d84f6501a8ebdf0513 to your computer and use it in GitHub Desktop.
Flow do Node-RED que uso pra mostrar minha glicemia, e outras infos, no meu display Wemos Lolin32

[{"id":"3e727e47.c13612","type":"subflow","name":"1 USD to BRL","info":"","category":"","in":[{"x":280,"y":320,"wires":[{"id":"6ca501bf.1854a"}]}],"out":[{"x":820,"y":320,"wires":[{"id":"f5176590.468c78","port":0}]}],"env":[],"color":"#3FADB5","outputLabels":["Dolar value"],"icon":"font-awesome/fa-money"},{"id":"f5176590.468c78","type":"function","z":"3e727e47.c13612","name":"parse dolar value","func":"function getMatches(string, regex, index) {\n  index || (index = 1); // default to the first capturing group\n  var matches = [];\n  var match;\n  while (match = regex.exec(string)) {\n    matches.push(match[index]);\n  }\n  return matches;\n}\n\n\nvar regex = /(\\d\\,\\d\\d) Real brasileiro/g\nvar result = getMatches(msg.payload, regex, 1)\nvar dolar = result[0]\n\nmsg.payload = dolar\nmsg.topic = \"dolar_reais\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":320,"wires":[[]]},{"id":"46f0411b.e38e4","type":"www-request","z":"3e727e47.c13612","name":"google","method":"GET","ret":"txt","url":"https://www.google.com/search?q=1+usd","follow-redirects":true,"tls":"","x":530,"y":320,"wires":[["f5176590.468c78"]]},{"id":"6ca501bf.1854a","type":"function","z":"3e727e47.c13612","name":"user-agent","func":"function stringToBinary(str, spaceSeparatedOctets) {\n    function zeroPad(num) {\n        return \"00000000\".slice(String(num).length) + num;\n    }\n\n    return str.replace(/[\\s\\S]/g, function(str) {\n        str = zeroPad(str.charCodeAt().toString(2));\n        return !1 == spaceSeparatedOctets ? str : str + \" \"\n    });\n};\nvar binary = stringToBinary(\"Mozilla/5.0 (X11; Linux x86_64…) Gecko/20100101 Firefox/61.0\")\nmsg.headers = {\"User-Agent\": binary}\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":320,"wires":[["46f0411b.e38e4"]]},{"id":"8db46920.e3fe88","type":"subflow","name":"YoutubeStats","info":"","category":"","in":[{"x":120,"y":320,"wires":[{"id":"a7753457.ca12d8"}]}],"out":[{"x":680,"y":280,"wires":[{"id":"c59bfc76.546d","port":0}]},{"x":680,"y":340,"wires":[{"id":"3eb4c802.cb9dc8","port":0}]}],"env":[],"outputLabels":["Subscribers","Views"]},{"id":"a7753457.ca12d8","type":"http request","z":"8db46920.e3fe88","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://www.googleapis.com/youtube/v3/channels?part=statistics&id=&key=","tls":"","proxy":"","authType":"basic","x":230,"y":320,"wires":[["59e3b400.84337c"]]},{"id":"59e3b400.84337c","type":"json","z":"8db46920.e3fe88","name":"","property":"payload","action":"obj","pretty":false,"x":380,"y":320,"wires":[["c59bfc76.546d","3eb4c802.cb9dc8","76df1150.3beeb"]]},{"id":"c59bfc76.546d","type":"change","z":"8db46920.e3fe88","name":"Subscribers","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.items[0].statistics.subscriberCount","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":280,"wires":[[]]},{"id":"3eb4c802.cb9dc8","type":"change","z":"8db46920.e3fe88","name":"Views","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.items[0].statistics.viewCount","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":320,"wires":[[]]},{"id":"76df1150.3beeb","type":"debug","z":"8db46920.e3fe88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":520,"y":380,"wires":[]},{"id":"88f87d58.49fe7","type":"mqtt out","z":"ec77e20d.6c3df","name":"Display 0","topic":"display/wemos/0","qos":"","retain":"true","broker":"e1a868b9.a931c8","x":1040,"y":420,"wires":[]},{"id":"dec0c829.dd7a28","type":"Cache out","z":"ec77e20d.6c3df","name":"","cache":"4258a859.949268","keyType":"msg","keyProperty":"topic","valueType":"msg","valueProperty":"payload","ttlType":"msg","ttlProperty":"","useString":false,"x":570,"y":120,"wires":[]},{"id":"9698f9f0.873e38","type":"Cache out","z":"ec77e20d.6c3df","name":"","cache":"4258a859.949268","keyType":"msg","keyProperty":"topic","valueType":"msg","valueProperty":"payload","ttlType":"msg","ttlProperty":"","useString":false,"x":470,"y":260,"wires":[]},{"id":"2071ebc3.4ab874","type":"Cache in","z":"ec77e20d.6c3df","name":"","cache":"4258a859.949268","keyType":"msg","keyProperty":"topic","valueType":"msg","valueProperty":"payload","useString":false,"outputs":1,"x":610,"y":480,"wires":[["a5253864.d89f18"]]},{"id":"c83dc847.def508","type":"change","z":"ec77e20d.6c3df","name":"glucose_value","rules":[{"t":"set","p":"topic","pt":"msg","to":"glucose_value","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":400,"wires":[["2071ebc3.4ab874"]]},{"id":"68eb86eb.1b09e8","type":"change","z":"ec77e20d.6c3df","name":"glucose_direction","rules":[{"t":"set","p":"topic","pt":"msg","to":"glucose_direction","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":440,"wires":[["2071ebc3.4ab874"]]},{"id":"d6842ba4.f06768","type":"change","z":"ec77e20d.6c3df","name":"dolar_reais","rules":[{"t":"set","p":"topic","pt":"msg","to":"dolar_reais","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":480,"wires":[["2071ebc3.4ab874"]]},{"id":"f07c54a5.cacbb8","type":"inject","z":"ec77e20d.6c3df","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":180,"y":460,"wires":[["fdc252a3.25326"]]},{"id":"a5253864.d89f18","type":"join","z":"ec77e20d.6c3df","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":480,"wires":[["fd96ae5a.bc4c1"]]},{"id":"bb2c12c8.c7e25","type":"inject","z":"ec77e20d.6c3df","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":300,"wires":[["accd7966.51a198","b728e4dc.f14ce8"]]},{"id":"4828a8b0.06b998","type":"mqtt out","z":"ec77e20d.6c3df","name":"Display 1","topic":"display/wemos/1","qos":"1","retain":"true","broker":"e1a868b9.a931c8","x":1040,"y":480,"wires":[]},{"id":"fd96ae5a.bc4c1","type":"function","z":"ec77e20d.6c3df","name":"to display v2","func":"var require = global.get('require');\nvar DOMParser = require('xmldom').DOMParser;\nvar moment = require('moment');\n\nlet currentDate = moment().format('ddd [-] HH:mm:ss')\n\n\nlet glucoseValue = msg.payload.glucose_value\nlet glucoseDirection = msg.payload.glucose_direction\nlet dolar = msg.payload.dolar_reais\nlet motion = msg.payload.office_motion\nlet subscribers = msg.payload.subscribers\nlet views = msg.payload.youtube_views\n\nlet translatedDirection = \"\";\nswitch(glucoseDirection) {\n    case \"Flat\":\n        translatedDirection = \" >\";\n        break;\n    case \"SingleDown\":\n        translatedDirection = \" v\";\n        break;\n    case \"FortyFiveDown\":\n        translatedDirection = \" \\\\\";\n        break;\n    case \"DoubleDown\":\n        translatedDirection = \" vv\";\n        break;\n    case \"SingleUp\":\n        translatedDirection = \" ^\";\n        break;\n    case \"FortyFiveUp\":\n        translatedDirection = \" /\";\n        break;\n    case \"DoubleUp\":\n        translatedDirection = \" ^^\";\n        break;\n}\n\nmsg = {}\nmsg.payload = {\n  \"pages\": [\n    {\n      \"1\": {\n        \"text\": currentDate,\n        \"size\": 10\n      },\n      \"2\": {\n        \"text\": glucoseValue + \"mg/dL\" + translatedDirection,\n        \"size\": 24\n      },\n      \"3\": {\n        \"text\": \"R$ \" + dolar,\n        \"size\": 24\n      }\n    },\n    {\n      \"1\": {\n        \"text\": \"AutoMarcio\",\n        \"size\": 10\n      },\n      \"2\": {\n        \"text\": subscribers + \" Subs\",\n        \"size\": 24\n      },\n      \"3\": {\n        \"text\": views + \" Views\",\n        \"size\": 24\n      }\n    }\n  ]\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":870,"y":480,"wires":[["4828a8b0.06b998","88f87d58.49fe7"]]},{"id":"accd7966.51a198","type":"subflow:8db46920.e3fe88","z":"ec77e20d.6c3df","name":"","env":[],"x":330,"y":300,"wires":[["b3d292d0.b698e"],["1de82c08.890944"]]},{"id":"b3d292d0.b698e","type":"change","z":"ec77e20d.6c3df","name":"subscribers","rules":[{"t":"set","p":"topic","pt":"msg","to":"subscribers","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[["274df9b.2bba406","7fba15a5.10d64c","cf19350.53f95c8"]]},{"id":"1de82c08.890944","type":"change","z":"ec77e20d.6c3df","name":"youtube_views","rules":[{"t":"set","p":"topic","pt":"msg","to":"youtube_views","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":340,"wires":[["274df9b.2bba406","a8f4b2fc.a925f"]]},{"id":"274df9b.2bba406","type":"Cache out","z":"ec77e20d.6c3df","name":"","cache":"4258a859.949268","keyType":"msg","keyProperty":"topic","valueType":"msg","valueProperty":"payload","ttlType":"msg","ttlProperty":"","useString":false,"x":670,"y":320,"wires":[]},{"id":"5ed3d20e.e72a7c","type":"change","z":"ec77e20d.6c3df","name":"subscribers","rules":[{"t":"set","p":"topic","pt":"msg","to":"subscribers","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":520,"wires":[["2071ebc3.4ab874"]]},{"id":"1e770c36.a6ce94","type":"change","z":"ec77e20d.6c3df","name":"youtube_views","rules":[{"t":"set","p":"topic","pt":"msg","to":"youtube_views","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":560,"wires":[["2071ebc3.4ab874"]]},{"id":"7fba15a5.10d64c","type":"mqtt out","z":"ec77e20d.6c3df","name":"HA subs sensor","topic":"youtube/automarcio/subscribers","qos":"","retain":"","broker":"e1a868b9.a931c8","x":700,"y":280,"wires":[]},{"id":"a8f4b2fc.a925f","type":"mqtt out","z":"ec77e20d.6c3df","name":"HA views sensor","topic":"youtube/automarcio/views","qos":"","retain":"","broker":"e1a868b9.a931c8","x":700,"y":360,"wires":[]},{"id":"b3e60101.ae266","type":"inject","z":"ec77e20d.6c3df","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"pages\":[{\"1\":{\"text\":\"Date()\",\"size\":10},\"2\":{\"text\":\"mg/dL\",\"size\":24},\"3\":{\"text\":\"test\",\"size\":24}}]}","payloadType":"json","x":890,"y":440,"wires":[["4828a8b0.06b998"]]},{"id":"f6f1bafb.d3d1c8","type":"inject","z":"ec77e20d.6c3df","name":"align right","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"true","payload":"true","payloadType":"bool","x":180,"y":740,"wires":[["14e03173.6d62ff","b109dd2.f7be02"]]},{"id":"14e03173.6d62ff","type":"mqtt out","z":"ec77e20d.6c3df","name":"Display 1","topic":"display/wemos/1/align_right","qos":"1","retain":"true","broker":"e1a868b9.a931c8","x":340,"y":740,"wires":[]},{"id":"b109dd2.f7be02","type":"mqtt out","z":"ec77e20d.6c3df","name":"Display 0","topic":"display/wemos/0/align_right","qos":"","retain":"true","broker":"e1a868b9.a931c8","x":340,"y":700,"wires":[]},{"id":"4b0b20aa.abfcc","type":"inject","z":"ec77e20d.6c3df","name":"align left","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":180,"y":700,"wires":[["14e03173.6d62ff","b109dd2.f7be02"]]},{"id":"c5f8af81.c812c","type":"function","z":"ec77e20d.6c3df","name":"to HA sensor","func":"msg.payload = parseFloat(msg.payload.replace(',','.'))\nmsg.topic = \"home/info/dolar\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":220,"wires":[["b868d32b.0e0ae"]]},{"id":"b868d32b.0e0ae","type":"mqtt out","z":"ec77e20d.6c3df","name":"publish","topic":"","qos":"","retain":"","broker":"e1a868b9.a931c8","x":660,"y":220,"wires":[]},{"id":"b728e4dc.f14ce8","type":"subflow:3e727e47.c13612","z":"ec77e20d.6c3df","name":"","x":330,"y":260,"wires":[["9698f9f0.873e38","c5f8af81.c812c","e104b0c3.0d5db"]]},{"id":"f21beb05.dca538","type":"server-state-changed","z":"ec77e20d.6c3df","name":"Glucose","server":"5deef908.183d48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.glucose_value","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":300,"y":120,"wires":[["85f7aa86.7bc148"]]},{"id":"85f7aa86.7bc148","type":"function","z":"ec77e20d.6c3df","name":"parse","func":"let glucose = msg.payload\nlet direction = msg.data.new_state.attributes.direction\n\nreturn [{\n    \"topic\": \"glucose_value\",\n    \"payload\": glucose\n}, {\n    \"topic\": \"glucose_direction\",\n    \"payload\": direction\n}]","outputs":2,"noerr":0,"initialize":"","finalize":"","x":430,"y":120,"wires":[["dec0c829.dd7a28","4a45036c.85775c"],["dec0c829.dd7a28"]],"outputLabels":["Glucose Value","Direction"]},{"id":"fdc252a3.25326","type":"function","z":"ec77e20d.6c3df","name":"","func":"return {};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":295,"y":480,"wires":[["c83dc847.def508","68eb86eb.1b09e8","d6842ba4.f06768","5ed3d20e.e72a7c","1e770c36.a6ce94"]],"icon":"node-red/arrow-in.svg","l":false},{"id":"f5adb431.ed3f38","type":"link in","z":"ec77e20d.6c3df","name":"","links":["4a45036c.85775c","e104b0c3.0d5db","cf19350.53f95c8"],"x":95,"y":500,"wires":[["3641bc63.3aa694"]]},{"id":"3641bc63.3aa694","type":"delay","z":"ec77e20d.6c3df","name":"throttle","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":190,"y":500,"wires":[["fdc252a3.25326"]]},{"id":"4a45036c.85775c","type":"link out","z":"ec77e20d.6c3df","name":"","links":["f5adb431.ed3f38"],"x":535,"y":80,"wires":[]},{"id":"e104b0c3.0d5db","type":"link out","z":"ec77e20d.6c3df","name":"","links":["f5adb431.ed3f38"],"x":555,"y":260,"wires":[]},{"id":"cf19350.53f95c8","type":"link out","z":"ec77e20d.6c3df","name":"","links":["f5adb431.ed3f38"],"x":755,"y":320,"wires":[]},{"id":"2aceb9e1.a3f1f6","type":"comment","z":"ec77e20d.6c3df","name":"Pulling","info":"","x":150,"y":260,"wires":[]},{"id":"3b487533.aba44a","type":"comment","z":"ec77e20d.6c3df","name":"HA Sensors","info":"","x":330,"y":80,"wires":[]},{"id":"db182db9.f7d18","type":"comment","z":"ec77e20d.6c3df","name":"Parse to Display Msg","info":"","x":160,"y":420,"wires":[]},{"id":"b7661c31.ca318","type":"comment","z":"ec77e20d.6c3df","name":"Display Control","info":"","x":160,"y":660,"wires":[]},{"id":"e1a868b9.a931c8","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.133","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4258a859.949268","type":"Cache","z":"","name":"Display","defaultTtl":"3600","checkPeriod":""},{"id":"5deef908.183d48","type":"server","z":"","name":"Home Assistant","legacy":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment