{"id":15486613,"url":"https://github.com/ycardon/switch-api","last_synced_at":"2025-04-22T16:48:31.689Z","repository":{"id":57376124,"uuid":"92320565","full_name":"ycardon/switch-api","owner":"ycardon","description":"REST server for switching stuff on macOS via home-assistant.io","archived":false,"fork":false,"pushed_at":"2022-04-21T19:58:10.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T07:15:52.832Z","etag":null,"topics":["display","home-assistant","macos-sierra","nodejs","rest-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ycardon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-24T17:52:24.000Z","updated_at":"2024-03-19T16:23:28.000Z","dependencies_parsed_at":"2022-09-26T16:50:59.655Z","dependency_job_id":null,"html_url":"https://github.com/ycardon/switch-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycardon%2Fswitch-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycardon%2Fswitch-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycardon%2Fswitch-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ycardon%2Fswitch-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ycardon","download_url":"https://codeload.github.com/ycardon/switch-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249279384,"owners_count":21242910,"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":["display","home-assistant","macos-sierra","nodejs","rest-api"],"created_at":"2024-10-02T06:09:12.317Z","updated_at":"2025-04-16T21:31:27.573Z","avatar_url":"https://github.com/ycardon.png","language":"JavaScript","readme":"# switch-api\n\nSimple http server that triggers system commands on predefined URLs\n- written in Node.js with minimum dependencies\n- support Apple intel platform only, for Apple ARM64 please check the [switch-api-rs](https://github.com/ycardon/switch-api-rs) project \n- used in conjunction with \u003chttps://home-assistant.io/components/switch.rest/\u003e\n- \u003chttp://pm2.keymetrics.io\u003e for automatic startup\n\n[![Known Vulnerabilities](https://snyk.io/test/github/ycardon/switch-api/badge.svg)](https://snyk.io/test/github/ycardon/switch-api)\n\n## usage and integration inside home-assistant\n\n### control mac display (on macOS Mojave)\n\n- `GET /display` : get current screen state (sleeping or not)\n- `POST /display body=ON|OFF` : switch screeen state\n\n```yaml\nswitch:\n  - platform: rest\n    name: Macbook Display\n    resource: 'http://mymac:8182/display'\n```\n\n### get battery power status (on macOS Mojave)\n\n- `GET /power`\n\n```yaml\nsensor:\n  - platform: rest\n    name: Macbook battery\n    resource: 'http://mymac:8182/power'\n    json_attributes:\n      - isOnAC\n      - isOnBattery\n      - isCharged\n      - chargingStatus\n      - chargePercent\n      - remainingChargeTime\n      - message\n    value_template: '{{ value_json.chargePercent }}'\n    unit_of_measurement: '%'\n```\n\n### get cpu average, defaults to last 5mn\n\n- `GET /cpu`\n  - `/cpu?avg=1` **last mn**\n  - `/cpu?avg=5` **last 5mn**\n  - `/cpu?avg=15` **last 15mn**\n\n```yaml\nsensor:\n  - platform: rest\n    name: Macbook CPU\n    resource: 'http://mymac:8182/cpu'\n    value_template: '{{ value | round(1) }}'\n    unit_of_measurement: '%'\n```\n\n## run in verbose mode\n\n`node app.js --verbose`\n```console\nSat Dec 21 2019 09:01:49 GMT-0600 (Central Standard Time) - switch-api server started on http://localhost:8182\nSat Dec 21 2019 09:02:03 GMT-0600 (Central Standard Time) - GET /cpu\nSat Dec 21 2019 09:02:17 GMT-0600 (Central Standard Time) - GET /display\n```\n\n## useful commands\n\n- sleep display: `pmset displaysleepnow`\n- wake display: `caffeinate -u -t 1`\n- test state : `pmset -g powerstate IODisplayWrangler | tail -1 | cut -c29` result \u003c4 are sleeping\n- battery power status : `pmset -g batt` (and a painful parsing)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fycardon%2Fswitch-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fycardon%2Fswitch-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fycardon%2Fswitch-api/lists"}