Skip to content

Instantly share code, notes, and snippets.

@bogdanbujdea
Last active September 13, 2022 21:01
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 bogdanbujdea/5367baa7be75d82efa8ced29fd883355 to your computer and use it in GitHub Desktop.
Save bogdanbujdea/5367baa7be75d82efa8ced29fd883355 to your computer and use it in GitHub Desktop.
Retrieve RescueTime productivity score
[{"id":"2d66941a7a549e66","type":"inject","z":"f2ad30b932f27004","name":"Every 1 minutes","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":110,"y":200,"wires":[["31e295f42e3e8f58"]]},{"id":"31e295f42e3e8f58","type":"credentials","z":"f2ad30b932f27004","name":"Set cookie","props":[{"value":"rescueTimeCookie","type":"msg"}],"x":330,"y":200,"wires":[["28ea02f9b5ab7705"]]},{"id":"28ea02f9b5ab7705","type":"function","z":"f2ad30b932f27004","name":"Prepare RescueTime Request","func":"msg.url = \"https://www.rescuetime.com/widget_window/productivity\";\nmsg.headers = {};\nmsg.method = \"GET\";\nmsg.headers[\"Cookie\"] = msg.rescueTimeCookie;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":200,"wires":[["93e5e34a7e137d05"]]},{"id":"93e5e34a7e137d05","type":"http request","z":"f2ad30b932f27004","name":"Request","method":"use","ret":"txt","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":true,"authType":"","senderr":false,"headers":[],"x":840,"y":200,"wires":[["728ba09b32781ace"]]},{"id":"728ba09b32781ace","type":"function","z":"f2ad30b932f27004","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.start = start;\nmsg.productivity = parseInt(attr.replace(/\\\"/g, \"\").trim());\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":200,"wires":[["d3a41760b43f299b"]]},{"id":"d3a41760b43f299b","type":"api-call-service","z":"f2ad30b932f27004","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":"payload","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":200,"wires":[[]]},{"id":"8501408e.93b69","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment