{"id":17858588,"url":"https://github.com/vzakharchenko/smartthings-phone-presence-sensor","last_synced_at":"2025-07-27T22:33:00.694Z","repository":{"id":50773783,"uuid":"152595945","full_name":"vzakharchenko/smartthings-phone-presence-sensor","owner":"vzakharchenko","description":"Smartthings Presence detection by reading leases on DHCP server","archived":false,"fork":false,"pushed_at":"2022-01-11T09:51:05.000Z","size":7163,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-19T14:58:15.442Z","etag":null,"topics":["asus-routers","dhcp","dhcp-lease","dhcp-lease-data","dhcp-leases","lease","mikrotik","mobile","presence","presence-sensor","router","sensor","smartapp","smartapp-source","smartthings","smartthings-device","smartthings-hub","smartthings-smartapp","tplink","tplink-api"],"latest_commit_sha":null,"homepage":"https://github.com/vzakharchenko/Router-as-Presence-sensor","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vzakharchenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-11T13:25:43.000Z","updated_at":"2023-04-14T04:28:37.000Z","dependencies_parsed_at":"2022-09-18T08:31:10.450Z","dependency_job_id":null,"html_url":"https://github.com/vzakharchenko/smartthings-phone-presence-sensor","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vzakharchenko%2Fsmartthings-phone-presence-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vzakharchenko%2Fsmartthings-phone-presence-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vzakharchenko%2Fsmartthings-phone-presence-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vzakharchenko%2Fsmartthings-phone-presence-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vzakharchenko","download_url":"https://codeload.github.com/vzakharchenko/smartthings-phone-presence-sensor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227518796,"owners_count":17783032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asus-routers","dhcp","dhcp-lease","dhcp-lease-data","dhcp-leases","lease","mikrotik","mobile","presence","presence-sensor","router","sensor","smartapp","smartapp-source","smartthings","smartthings-device","smartthings-hub","smartthings-smartapp","tplink","tplink-api"],"created_at":"2024-10-28T05:22:21.211Z","updated_at":"2024-12-03T03:02:54.616Z","avatar_url":"https://github.com/vzakharchenko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# smartthings router connection\n\n![Docker](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/workflows/ci/badge.svg)  \n![Node.js CI](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/workflows/Node.js%20CI/badge.svg)  \n[![NPM](https://nodei.co/npm/smartthings-phone-presence-sensor.png)](https://npmjs.org/package/smartthings-phone-presence-sensor)  \n[![donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://secure.wayforpay.com/button/b8390c46bf24a)  \n\n## Description\n    With this project you can use your router as a presence detector for your phones.\n    Reads known personal mobile device's MAC address(using DHCP leases) to check each person's presence.\n## Features\n- work without Smartthings hub!\n- [setup outside your network(Change presence status for Location where server is not installed)](https://github.com/vzakharchenko/smartthings-phone-presence-sensor#installation-outside-your-network)\n- Presence sensor based on DHCP lease.\n- can detect mobile phone in sleep state.\n- support mikrotik, asus, tplink.\n  **Supported  [SmartThings](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect)**  ~~and [SmartThings Classic](https://play.google.com/store/apps/details?id=com.smartthings.android) applications~~\n## Supported device list:\n- Asus:\n\n    Firmware version should be later than 3.0.0.4.380:\n    - All 802.11ax line up\n    - All ROG Rapture line up\n    - Blue Cave\n    - BRT-AC828\n    - RT-AC5300\n    - RT-AC3100\n    - RT-AC88U\n    - RT-AC3200\n    - RT-AC2900\n    - RT-AC87U/R\n    - RT-AC86U\n    - RT-AC85U\n    - RT-AC85P\n    - RT-AC65P\n    - RT-AC57U\n    - RT-AC68U/R/P/W/UF\n    - RT-AC65U\n    - RT-AC1900\n    - RT-AC1900P/U\n    - RT-AC1750\n    - RT-AC1750 B1\n    - RT-AC66U/R/W\n    - RT-AC66U B1\n    - RT-AC66U+\n    - RT-AC1300UHP\n    - RT-AC1200\n    - RT-AC1200G/HP/G+\n    - RT-AC58U\n    - RT-AC57U\n    - RT-AC56U/R/S\n    - RT-AC55U\n    - RT-AC55UHP\n    - RT-AC53U\n    - RT-AC53\n    - RT-AC52U\n    - RT-AC52U B1\n    - RT-AC51U\n    - RT-AC51U+\n    - RT-ACRH17\n    - RT-ACRH13\n    - RT-N66U/R/W\n    - RT-N18U\n    - RT-N16\n    - RT-N14UHP\n    - RT-N12E B1/C1\n    - RT-N12HP B1\n    - RT-N12VP B1\n    - RT-N12+\n    - RT-N12+ B1\n    - RT-N12D1\n    - DSL-AC68U/R\n- TpLink:\n    tested on TP-LINK Touch P5\n- Mikrotik:\n - all devices\n\n## Docker Installation\n- prepare installation\n```\nsudo apt-get -y install  curl\nsudo apt-get -y remove docker docker.io containerd runc\ncurl -sSL https://get.docker.com | sudo bash\nsudo groupadd docker\nsudo usermod -aG docker $USER\n```\n- Configuration inside Docker container\n```\ndocker run -d --name=smartthings-phone-presence-sensor  -p 5000:5000 --restart=always vassio/smartthings-phone-presence-sensor:latest\n```\n- Configuration outside Docker container\n```\nmkdir -p /opt/config/router\necho \"{}\"\u003e/opt/config/router/routerConfig.json\ndocker run -d --name=smartthings-phone-presence-sensor  -p 5000:5000 -v /opt/config/router/routerConfig.json:/opt/config/routerConfig.json --restart=always vassio/smartthings-phone-presence-sensor:latest\n```\n- Configuration outside Docker container with keycloak.json\n```\nmkdir -p /opt/config/router\necho \"{}\"\u003e/opt/config/router/routerConfig.json\ndocker run -d --name=smartthings-phone-presence-sensor  -p 5000:5000 -v /opt/config/router/routerConfig.json:/opt/config/routerConfig.json -v /opt/config/router/keycloak.json:/opt/config/router/keycloak.json --restart=always vassio/smartthings-phone-presence-sensor:latest\n```\n## Installation Steps:\n1. Install server\n- using npm manager:\n```bash\nsudo npm i pm2 -g\nsudo env PATH=$PATH:/usr/bin pm2 startup systemd -u ${currentUser} --hp ${HOME}\nsudo npm i smartthings-phone-presence-sensor -g\nsudo pm2 start `npm root -g`/smartthings-phone-presence-sensor/RouterSmartAppServer.js\nsudo pm2 save\n```\n- [Docker Installation](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/blob/master/README.md#docker-installation)\n- [Manual Server Installation Steps](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/#manual-server-installation-steps)\n2. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n3. open router Setting tab  ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/routerSetting.png?raw=true)\n4. select router type: asus or tplink or mikrotik\n5. set ip(hostname) of router  web admin UI\n6. set port of router  web admin UI (microtik rest API sevice). Default is 80 (microtik: 8728)\n7. set login and password of router  web admin UI\n8. [install SmartApp Source](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/#install-smartapp-source)\n9. [Create new device handler](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/#install-device-handler)\n10. [Add new SmartApp to SmartThings](https://github.com/vzakharchenko/smartthings-phone-presence-sensor#add-a-new-smartapp-to-smartthings)\n11.  [Assign Phone Mac address to  SmartThing Device](https://github.com/vzakharchenko/smartthings-phone-presence-sensor#assign-phone-mac-address-to--smartthing-device)\n12. add more devices if necessary, for this repeat steps 7-10 to do this\n13. now you can use Smartthings Device for automation\n\n\n## Installation Outside your network:\n\nChange presence status for Location where server is not accessible.\nExample:\n - Location 1 has server\n - Location 2 does not have server\n I would like to change my presence status to Leave for location 2 if my phone is in location 1.\n \n1. Install server\n- using npm manager:\n```bash\nsudo wget -qO- https://getpm2.com/install.sh | bash\nsudo env PATH=$PATH:/usr/bin pm2 startup systemd -u ${currentUser} --hp ${HOME}\nsudo npm i smartthings-phone-presence-sensor -g\nsudo pm2 start `npm root -g`/smartthings-phone-presence-sensor/RouterSmartAppServer.js\nsudo pm2 save\n```\n- [Docker Installation](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/blob/master/README.md#docker-installation)\n- [Manual Server Installation Steps](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/#manual-server-installation-steps)\n2. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n3. open router Setting tab  ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/routerSetting.png?raw=true)\n4. select router type: asus or tplink or mikrotik\n5. set ip(hostname) of router  web admin UI\n6. set port of router  web admin UI (microtik rest API sevice). Default is 80 (microtik: 8728)\n7. set login and password of router  web admin UI\n8. [install SmartApp Source](https://github.com/vzakharchenko/smartthings-phone-presence-sensor/#install-smartapp-source)\n9. [Create new device handler](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/#install-device-handler)\n10. [Add new SmartApp to SmartThings with device name](https://github.com/vzakharchenko/smartthings-phone-presence-sensor#add-a-new-smartapp-to-smartthings-outside-network)\n11.  [Assign Phone Mac address to  SmartThing Device](https://github.com/vzakharchenko/smartthings-phone-presense-sensor#assign-phone-mac-address-to--smartthing-device)\n12. add more devices if necessary, for this repeat steps 7-10 to do this\n13. now you can use Smartthings Device for automation\n\n## Manual Server Installation Steps:\n1. setup linux on RaspberryPi https://ubuntu.com/download/iot/raspberry-pi-2-3\n2. install node.\n```bash\nsudo apt-get install curl\ncurl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -\nsudo apt-get install nodejs\n```\nor\n```bash\nsudo apt-get install snapd\nsudo snap install node --channel=14/stable --classic\n```\n3. install git\n`sudo apt-get install git`\n4. install pm2\n`sudo npm i pm2 -g`\n5. add pm2 to autostart\n```bash\nsudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ${currentUser} --hp ${HOME}\n```\n6. make directory /opt/app\n```bash\n sudo mkdir -p /opt/app\n```\n7. make directory /opt/config\n8. change ownership of /opt/app and /opt/config\n```bash\n sudo chown -R \u003cUSER\u003e:\u003cUSER\u003e /opt/app\nsudo chown -R \u003cUSER\u003e:\u003cUSER\u003e /opt/config\n```\n9. checkout project\n```bash\n cd /opt/app\n git clone https://github.com/vzakharchenko/https://github.com/vzakharchenko/smartthings-phone-presense-sensor router\n```\n10.  copy config `cp -n /opt/app/router/config/config.json /opt/config/routerConfig.json`\n11.  install and build project\n```bash\ncd /opt/app/router\nnpm i\ncd router-ui\nnpm i\nnpm build\ncd ..\n```\n12. add poject to pm2\n```bash\ncd /opt/app/router\npm2 start RouterSmartAppServer.js\npm2 save\n```\n\n## Router setting\n1. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n2. open router Setting tab ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/routerSetting.png?raw=true)\n3. select router type: asus or tplink or mikrotik\n4. set ip(hostname) of router  web admin UI\n5. set port of router  web admin UI (microtik rest API sevice). Default is 80 (microtik: 8728)\n6. set login and password of router\n\n## install SmartApp Source\n1. open https://graph.api.smartthings.com/location/list with your samsung account\n2. select your location ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/Location.png?raw=true)\n3. add new smartapp ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/addNewSmartApp.png?raw=true)\n4. select \"From Code\" insert code from https://github.com/vzakharchenko/smartthings-phone-presence-sensor/blob/master/smartapps/WiFi%20%20Presence.groovy ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/createNewSmartApp.png?raw=true)\n5. open App-Setting ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/selectAppSetting.png?raw=true)\n6. enable oauth in smartapp![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/enableOAuth.png?raw=true)\n7.  save and publish![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/saveAndPublish.png?raw=true)\n\n## install device Handler\n1. open https://graph.api.smartthings.com/location/list with your samsung account\n2. select your location ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/Location.png?raw=true)\n3. goto \"My Device Handlers\" -\u003e \"Create New Device Handler\"![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/newDeviceHandler.png?raw=true)\n4. select \"From Code\" insert code from https://github.com/vzakharchenko/smartthings-phone-presence-sensor/blob/master/smartapps/WiFi%20%20Presence.groovy ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/newDeviceHandler2.png?raw=true)\n\n## Add a new SmartApp to [SmartThings](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect\u0026hl=en\u0026gl=US)\n\n1. install [SmartThings](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect\u0026hl=en\u0026gl=US)\n2. open \"+\"-\u003e\"SmartApps\"![](./img/smartthingsStep1.png?raw=true) ![](./img/smartthingsStep2.png)\n4. add \"WiFi Device Presence\"![](./img/smartthingsStep3.png)\n5. set Server IP, port and Presence Sensor Name and click save ![](./img/smartthingsStep4.png)\n\n## Add a new SmartApp to [SmartThings](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect\u0026hl=en\u0026gl=US) Outside network\nChange presence status for Location where server is not accessible.\nExample:\n - Location 1 has server\n - Location 2 does not have server\n I would like to change my presence status to Leave for location 2 if my phone is in location 1.\n\n1. install [SmartThings](https://play.google.com/store/apps/details?id=com.samsung.android.oneconnect\u0026hl=en\u0026gl=US)\n2. open \"+\"-\u003e\"SmartApps\"![](./img/smartthingsStep1.png?raw=true) ![](./img/smartthingsStep2.png)\n4. add \"WiFi Device Presence\"![](./img/smartthingsStep3.png)\n5. set Presence Sensor Name and click save ![](./img/smartthingsStep6.png)\n6. Manually add Integration between SmartApp and nodejs server\n\n## Assign Phone Mac address to  SmartThing Device\n1. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n2. goto Device Tab\n3. assign network device to Smartthings Device ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/assignMac.png?raw=true)\n\n## Remove Mac address from  SmartThings Device\n1. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n2. goto \"SmartThing Devices\" Tab\n3. click \"unAssign\" ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/unAssign.png?raw=true)\n\n## Manually add Integration between SmartApp and nodejs server\n\n1. get  applicationId and secret from SmartApp\n    - open smartapp on phone: ![](../img/smartthingsStep5.png)\n    or\n    - open smartapp on [smartthing portal](https://graph.api.smartthings.com):   ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/installedSmartapps.png?raw=true)   ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/selectsSmartApp.png?raw=true)   ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/AppIdSecretWeb.png?raw=true)\n2. open link http:/\u003cYOUR_SERVER_IP\u003e:5000\n3. goto \"SmartThing Devices\" Tab\n4. set applicationId and secret from step 1, and click \"add Device\" ![](https://github.com/vzakharchenko/smartthings-phone-presense-sensor/blob/master/img/ManuallyAddDevice.png?raw=true)\n\n## Protect Admin UI using [keycloak SSO](https://www.keycloak.org/) (Optional)\n1. download keycloak.json from the keycloak admin ui [https://www.keycloak.org/docs/latest/securing_apps/](https://www.keycloak.org/docs/latest/securing_apps/).\n2. save keycloak.json to /opt/config/router/keycloak.json or [./config/keycloak.json](/config)\n\nexample of keycloak.json\n```json\n{\n  \"realm\": \"REALM\",\n  \"auth-server-url\": \"https://localhost:8090/auth\",\n  \"ssl-required\": \"external\",\n  \"resource\": \"testClient\",\n  \"credentials\": {\n    \"secret\": \"secret\"\n  },\n  \"confidential-port\": 0\n}\n```\n\n# If you find these useful, please [Donate](https://secure.wayforpay.com/button/b8390c46bf24a)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvzakharchenko%2Fsmartthings-phone-presence-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvzakharchenko%2Fsmartthings-phone-presence-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvzakharchenko%2Fsmartthings-phone-presence-sensor/lists"}