{"id":15722958,"url":"https://github.com/ayapejian/node-home-assistant","last_synced_at":"2025-05-13T03:59:24.558Z","repository":{"id":151912902,"uuid":"87652277","full_name":"AYapejian/node-home-assistant","owner":"AYapejian","description":"Home Assistant library for node with command line interface","archived":false,"fork":false,"pushed_at":"2019-01-23T07:24:36.000Z","size":140,"stargazers_count":4,"open_issues_count":2,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-13T03:59:17.176Z","etag":null,"topics":["api-client","cli-utilities","command-line-tool","event-emitter","home-assistant","home-automation"],"latest_commit_sha":null,"homepage":"","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/AYapejian.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-08T17:42:46.000Z","updated_at":"2019-01-23T07:24:35.000Z","dependencies_parsed_at":"2023-05-15T17:30:29.176Z","dependency_job_id":null,"html_url":"https://github.com/AYapejian/node-home-assistant","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYapejian%2Fnode-home-assistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYapejian%2Fnode-home-assistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYapejian%2Fnode-home-assistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYapejian%2Fnode-home-assistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AYapejian","download_url":"https://codeload.github.com/AYapejian/node-home-assistant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253870859,"owners_count":21976612,"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":["api-client","cli-utilities","command-line-tool","event-emitter","home-assistant","home-automation"],"created_at":"2024-10-03T22:09:50.091Z","updated_at":"2025-05-13T03:59:24.541Z","avatar_url":"https://github.com/AYapejian.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Home Assistant\n\nHome Assistant utility library and command line interface\n\nNOTE: This is a work in progress ymmv.  Currently it's working in my very limited testing and uses the Server Sent Events interface Home Assistant surfaces along with the REST api.\n\n## Command Line\n### Install\n\n1. Install the module `npm install -g node-home-assistant`\n2. Add an environment variable with your Home Assistant URL and Password exported as `HA_URL` and `HA_PASSWORD`\n3. Run `ha history` as a quick test\n4. See other commands and examples by running `ha` with no other options\n5. The command line tool surfaces a lot of the defaults and configuration via environment variables, checkout `config.js` for a listing\n\n### Command line help output\n\n```shell\n$ ha\n\nUsage: ha [cmd]\n\nOptions:\n  -V, --version                                 output the version number\n  -v, --version                                 get version\n  -d, --debug                                   output debug messages\n  -u, --url \u003curl\u003e                               home assistant url\n  -p, --password \u003cpassword\u003e                     home assistant password\n  -h, --help                                    output usage information\n\nCommands:\n  history [options]                             Get history, defaults to all history from past hour\n  states [options]                              Get list of all known states, returns only the list of entity_ids with states\n  entities [options]                            Get list of all known entities, returns only the list of entity_ids\n  dashboard [options]                           Display a dashboard that is updated with state data as events occur\n  service \u003cdomain\u003e \u003cservice\u003e [data]             Calls home assistant service with data provided, outputs the response body from home assistant\n  show [options] \u003centity|entities\u003e [entity_id]  Get all details of one or more home assistant entities, returns only JSON object. If no entity is found JSON object will be empty, no error will be thrown\n  *\n\n  Examples:\n\n    * History:\n      $ ha history --pretty --relative-dates\n      $ ha history --entity_id binary_sensor.motion_office_motion\n      $ ha history --include office --exclude group --pretty\n      $ ha history --include '(office|livingroom)' --exclude '(sensor|group)' --pretty\n      $ ha history --from \"3 days ago\" --to \"2 days ago\"\n      $ ha history -i '(office|bedroom)' -e '(^sensor|device_tracker|group)' -f '1 day ago' --pretty\n    * States:\n      $ ha states\n      $ ha states --pretty --relative-dates\n      $ ha states -i '^sensor' -e '_motion$|transmission|pihole'\n    * Entities:\n      $ ha entities\n      $ ha entities --pretty\n      $ ha entities --include '^sensor' --exclude '_motion$|transmission|pihole'\n    * Entity Details:\n      $ ha show entities\n      $ ha show entities group.all_switches\n      $ ha show entities --include sensor\n    * Calling Services\n      $ ha service light turn_on '{ \"entity_id\": \"light.garage_hue_room\" }'\n      $ ha service light turn_off '{ \"entity_id\": \"light.garage_hue_room\" }'\n      $ ha service light turn_off\n    * Dashboard:\n        $ ha dashboard\n        $ ha dashboard --include '^sensor' --exclude '_motion$|transmission|pihole'\n```\n\n## Use as a library in your own project\n1. Install module locally `npm install --save node-home-assistant`\n2. Check out the `_examples` directory in this project which shows some usage of the API and Events listener interfaces\n3. Quick example below:\n\n```javascript\nconst HomeAssistant = require('node-home-assistant');\n\nconst config = {\n    baseUrl: 'http://localhost:8123',\n    apiPass: 'supersecretpassword'\n};\n\nconst homeAssistant = new HomeAssistant(config, { startListening: true });\n\n// Call a service with domain, service, data\nhomeAssistant.api.callService('light', 'turn_off', { entity_id: 'light.office_hue_room' })\n    .then(res =\u003e console.log('Light switched off', res))\n    .catch(e =\u003e console.log(e));\n\n// Events by event_type as sent by home assistant ('state_changed' and 'service_executed' from home assistant below)\nhomeAssistant.events.on('ha_events:state_changed', (evt) =\u003e console.log(`(ha_events:state_changed) ${JSON.stringify(evt)}`));\n```\n\n## TODO\n- [x] CLI option to call service\n- [ ] More tests\n- [ ] Finish CLI Dashboard\n- [ ] Update API to use new home assistant authentication methods\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayapejian%2Fnode-home-assistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayapejian%2Fnode-home-assistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayapejian%2Fnode-home-assistant/lists"}