[ { "id": "a30965b0.6937c", "type": "tab", "label": "Smart Chair", "disabled": false, "info": "" }, { "id": "f6f80572.cdb7a8", "type": "notify", "z": "a30965b0.6937c", "title": "Alert", "name": "Pop-up Alert on Windows", "x": 756.7666015625, "y": 278.1499938964844, "wires": [] }, { "id": "f8961de8.2e5a9", "type": "inject", "z": "a30965b0.6937c", "name": "Trigger", "topic": "", "payload": "", "payloadType": "date", "repeat": "15", "crontab": "", "once": true, "x": 131, "y": 52.883331298828125, "wires": [ [ "2036fe15.18302a" ] ] }, { "id": "920bf59a.1347a", "type": "debug", "z": "a30965b0.6937c", "name": "Debug", "active": true, "console": "false", "complete": "payload", "x": 697.88330078125, "y": 136.88333129882812, "wires": [] }, { "id": "d456433b.5b5be", "type": "function", "z": "a30965b0.6937c", "name": "process_data", "func": "const threshold = 380; // Put your sensor threshold here\nconst waitingTime = 3600*1000; // Waiting time in milliseconds, 1 hr = 3600 seconds\nconst nCount = 5; // Number of times a low threshold need to be detected\n// nCount * triggerTime(set in the first node) = Time you need to be away from the chair for the chair to \n// recognize that you have been away for a certain amount of time and not cheat by standing up and sitting down. \n\nvar data_in = parseInt(msg.payload.value);\n\nvar currDate = new Date();\nvar currTime = currDate.getTime();\n\nvar count = context.get('count') || 0;\n\nvar prevDate = context.get('prevDate')||new Date();\ncontext.set('prevDate', prevDate);\nvar prevTime = prevDate.getTime();\n\n\nif(data_in <= threshold)\n{\n\tcount = count + 1; \n\tcontext.set('count', count);\n\tif(count == 5)\n\t{\n\t\tprevDate = new Date();\n\t\tcontext.set('prevDate', prevDate);\n\t\tprevTime = prevDate.getTime();\n\t\t\n\t\tcount = 0; \n\t\tcontext.set('count', count);\n\t}\n}\n\nelse if((currTime >= (prevTime + waitingTime)) && (data_in > threshold))\n{\n\treturn {payload : \"You have been sitting here for \"+ parseInt((currTime-prevTime)/60000) + \" mins. Take a Break! Get up and Walk!!!\"}; \n}\n\nelse \n{\n\tcount = 0; \n\tcontext.set('count', count);\n}\n", "outputs": 1, "noerr": 0, "x": 515.0000305175781, "y": 205, "wires": [ [ "920bf59a.1347a", "f6f80572.cdb7a8" ] ] }, { "id": "3a7ba531.8b5cd2", "type": "http request", "z": "a30965b0.6937c", "name": "get_bolt_data", "method": "GET", "ret": "obj", "url": "http://cloud.boltiot.com/remote/{{api_key}}/analogRead?pin=A0&deviceName={{deviceName}}", "tls": "", "x": 310.0000305175781, "y": 205, "wires": [ [ "d456433b.5b5be" ] ] }, { "id": "2036fe15.18302a", "type": "function", "z": "a30965b0.6937c", "name": "set_bolt_params", "func": "msg.api_key = '28i25578-w414-2345-8159-dehfaa04db49'; // Replace with your Bolt API Key\nmsg.deviceName = 'BOLT78482955'; // Replace with your Bolt Device Name\n\nreturn msg;", "outputs": 1, "noerr": 0, "x": 208, "y": 132, "wires": [ [ "3a7ba531.8b5cd2" ] ] } ]