Created
January 13, 2021 15:48
-
-
Save bogdanbujdea/ed4f360756db45830b0dd1b1f4741cef to your computer and use it in GitHub Desktop.
RescueTime flow for Node-Red
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [{"id":"b6e164fe.1d31e8","type":"subflow","name":"Galaxy S9 notification","info":"","category":"","in":[{"x":100,"y":80,"wires":[{"id":"af896d84.97285"}]}],"out":[{"x":600,"y":80,"wires":[{"id":"fe75d18.e659d3","port":0}]}],"env":[{"name":"message","type":"str","value":""},{"name":"title","type":"str","value":""}],"color":"#A5C13D","icon":"font-awesome/fa-mobile-phone"},{"id":"fe75d18.e659d3","type":"api-call-service","z":"b6e164fe.1d31e8","name":"Send notification","server":"8501408e.93b69","version":1,"debugenabled":true,"service_domain":"notify","service":"mobile_app_galaxy_s9","entityId":"","data":"msg.data","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":430,"y":80,"wires":[[]]},{"id":"af896d84.97285","type":"function","z":"b6e164fe.1d31e8","name":"","func":"var message = env.get(\"message\") || msg.message || global.get('GalaxyS9Message');\nvar title = env.get(\"title\") || msg.title || global.get('GalaxyS9Title');\n\nmsg.data = {\n message,\n title\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":80,"wires":[["fe75d18.e659d3","67780e1d.47e76"]]},{"id":"67780e1d.47e76","type":"debug","z":"b6e164fe.1d31e8","name":"Notification data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":140,"wires":[]},{"id":"c28ba6b7.4557d8","type":"subflow","name":"Logbook","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"5593757e.842a8c"}]}],"out":[{"x":320,"y":80,"wires":[{"id":"5593757e.842a8c","port":0}]}],"env":[{"name":"name","type":"str","value":""},{"name":"message","type":"str","value":""},{"name":"domain","type":"str","value":""},{"name":"entity_id","type":"str","value":""}],"color":"#8A84FF","icon":"font-awesome/fa-book"},{"id":"5593757e.842a8c","type":"api-call-service","z":"c28ba6b7.4557d8","name":"Logbook","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"logbook","service":"log","entityId":"","data":"{\t \"name\":$env('name'),\t \"domain\":\"switch\",\t \"message\":$env('message'),\t \"entity_id\": $env('entity_id')\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":200,"y":80,"wires":[[]]},{"id":"e352e71e.cc0298","type":"subflow","name":"Handle productivity score change","info":"","category":"","in":[{"x":20,"y":200,"wires":[{"id":"e9e0e622.0d46b8"},{"id":"af9f6ef5.75e0c"}]}],"out":[{"x":1160,"y":180,"wires":[{"id":"c469ded7.924e7","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"e9e0e622.0d46b8","type":"switch","z":"e352e71e.cc0298","name":"Productivity check","property":"scoreState","propertyType":"msg","rules":[{"t":"eq","v":"up","vt":"str"},{"t":"eq","v":"same","vt":"str"},{"t":"eq","v":"down","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":170,"y":200,"wires":[["35f0b042.97b87","6810eac4.83d424"],[],["fa233ee0.b93fa","a9d16f6.ff0a59"]]},{"id":"d534e249.3b253","type":"api-call-service","z":"e352e71e.cc0298","name":"Red light","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_lightstrip","data":"{\"color_name\": \"red\", \"transition\":2}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":280,"wires":[["37f30777.054ca8"]]},{"id":"a57b8e6d.88adf","type":"api-call-service","z":"e352e71e.cc0298","name":"Green light","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_lightstrip","data":"{\"color_name\": \"green\", \"transition\":2}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":630,"y":120,"wires":[["37f30777.054ca8"]]},{"id":"35f0b042.97b87","type":"subflow:c28ba6b7.4557d8","z":"e352e71e.cc0298","name":"Productivity increase","env":[{"name":"name","value":"Productivity","type":"str"},{"name":"message","value":"Productivity increasing","type":"str"},{"name":"domain","value":"input_number","type":"str"},{"name":"entity_id","value":"input_number.productivity_score","type":"str"}],"x":420,"y":60,"wires":[[]]},{"id":"af9f6ef5.75e0c","type":"api-call-service","z":"e352e71e.cc0298","name":"Set productivity score","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.productivity_score","data":"{\"value\": msg.productivity}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":180,"y":40,"wires":[[]]},{"id":"fa233ee0.b93fa","type":"subflow:c28ba6b7.4557d8","z":"e352e71e.cc0298","name":"Productivity decrease","env":[{"name":"name","value":"Productivity","type":"str"},{"name":"message","value":"Productivity decreasing","type":"str"},{"name":"domain","value":"input_number","type":"str"},{"name":"entity_id","value":"input_number.productivity_score","type":"str"}],"x":420,"y":340,"wires":[["b313424a.09e77"]]},{"id":"c469ded7.924e7","type":"api-call-service","z":"e352e71e.cc0298","name":"Reset office light","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_lightstrip","data":"{\"color_name\": \"white\", \"transition\":5}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":180,"wires":[[]]},{"id":"37f30777.054ca8","type":"delay","z":"e352e71e.cc0298","name":"Delay 5 seconds","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":830,"y":200,"wires":[["c469ded7.924e7"]]},{"id":"6810eac4.83d424","type":"api-current-state","z":"e352e71e.cc0298","name":"I am in the office","server":"8501408e.93b69","version":1,"outputs":2,"halt_if":"Office","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bogdan_location_dropdown","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":160,"wires":[["a57b8e6d.88adf"],[]]},{"id":"a9d16f6.ff0a59","type":"api-current-state","z":"e352e71e.cc0298","name":"I am in the office","server":"8501408e.93b69","version":1,"outputs":2,"halt_if":"Office","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bogdan_location_dropdown","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":240,"wires":[["d534e249.3b253"],[]]},{"id":"92242e86.2f281","type":"subflow:b6e164fe.1d31e8","z":"e352e71e.cc0298","name":"Notify that productivity decreases","env":[],"x":920,"y":340,"wires":[[]]},{"id":"b313424a.09e77","type":"change","z":"e352e71e.cc0298","name":"Set notification data","rules":[{"t":"set","p":"message","pt":"msg","to":"msg.notification","tot":"jsonata"},{"t":"set","p":"title","pt":"msg","to":"msg.notificationTitle","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":340,"wires":[["92242e86.2f281"]]},{"id":"8501408e.93b69","type":"server","name":"Home Assistant"},{"id":"f82613b5.868cb","type":"subflow:e352e71e.cc0298","z":"9bed5193.e06f9","name":"Handle productivity score change","env":[],"x":1080,"y":40,"wires":[[]]},{"id":"7fab4ef5.5f952","type":"function","z":"9bed5193.e06f9","name":"Find productivity score","func":"const globalHomeAssistant = global.get('homeassistant');\nvar html = msg.payload;\nvar attributeName = \"efficiency_percent\";\nvar start = html.indexOf(attributeName);\nvar attr = html.substr(start + attributeName.length + 2, 5);\nmsg = {};\nmsg.attr = attr;\nmsg.start = start;\nmsg.productivity = parseInt(attr.replace(/\\\"/g, \"\").trim());\nvar previousScore = parseInt(globalHomeAssistant.homeAssistant.states[\"sensor.productivity_score\"].state);\nmsg.previousScore = previousScore;\nif(msg.previousScore < msg.productivity){\n msg.scoreState = \"up\";\n}\nelse if(msg.previousScore > msg.productivity){\n var diff = msg.previousScore - msg.productivity;\n msg.notification = \"Your productivity score went down \";\n msg.notification += diff;\n if(diff == 1){\n msg.notification += \" point\";\n }\n else msg.notification += \" points\";\n msg.notification += \" to \" + msg.productivity + \" percent\";\n msg.scoreState = \"down\";\n msg.notificationTitle = \"Productivity going down: \" + msg.productivity + \"%\";\n}\nelse msg.scoreState = \"same\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":40,"wires":[["f82613b5.868cb"]]},{"id":"5d321576.6c160c","type":"http request","z":"9bed5193.e06f9","name":"Request","method":"use","ret":"txt","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","authType":"","x":600,"y":40,"wires":[["7fab4ef5.5f952"]]},{"id":"bf203bd3.928bd8","type":"function","z":"9bed5193.e06f9","name":"Prepare RescueTime Request","func":"var date = new Date();\nvar day = date.getDate();\nvar month = date.getMonth() + 1;\nvar year = date.getFullYear();\n\nmsg.url = \"https://www.rescuetime.com/widget_window/productivity\";\nmsg.headers = {};\nmsg.method = \"GET\";\nmsg.headers[\"Cookie\"] = \"\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":40,"wires":[["5d321576.6c160c"]]},{"id":"58f6f949.7cf218","type":"inject","z":"9bed5193.e06f9","name":"Every 1 minutes","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":130,"y":40,"wires":[["bf203bd3.928bd8"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment