{"id":14985330,"url":"https://github.com/filp/homeassistant-ws","last_synced_at":"2025-04-10T23:51:12.352Z","repository":{"id":48366937,"uuid":"259143197","full_name":"filp/homeassistant-ws","owner":"filp","description":"Minimalist client library for Homeassistant's Websocket API","archived":false,"fork":false,"pushed_at":"2024-08-24T11:26:47.000Z","size":131,"stargazers_count":16,"open_issues_count":2,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T18:19:30.868Z","etag":null,"topics":["api","homeassistant","node","npm","websocket"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/filp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-04-26T22:06:08.000Z","updated_at":"2025-04-09T10:15:53.000Z","dependencies_parsed_at":"2024-09-24T15:44:17.077Z","dependency_job_id":null,"html_url":"https://github.com/filp/homeassistant-ws","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":"0.38888888888888884","last_synced_commit":"390b93676808e778932fb029f9b98c4e077ea76e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fhomeassistant-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fhomeassistant-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fhomeassistant-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filp%2Fhomeassistant-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filp","download_url":"https://codeload.github.com/filp/homeassistant-ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317707,"owners_count":21083528,"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","homeassistant","node","npm","websocket"],"created_at":"2024-09-24T14:10:43.156Z","updated_at":"2025-04-10T23:51:12.334Z","avatar_url":"https://github.com/filp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# homeassistant-ws\n\n[![npm](https://img.shields.io/npm/v/homeassistant-ws?color=%23ff11dd\u0026style=flat-square)](https://www.npmjs.com/package/homeassistant-ws)\n[![GitHub](https://img.shields.io/github/license/filp/homeassistant-ws?style=flat-square)](https://github.com/filp/homeassistant-ws/blob/master/LICENSE.md)\n\nMinimalist client library for [Homeassistant's Websocket API](https://developers.home-assistant.io/docs/external_api_websocket). Works in node, and also in the browser.\n\n---\n\n## Installation:\n\nUsing `npm`:\n\n```shell\n$ npm i --save homeassistant-ws\n```\n\nImport it in your project:\n\n```js\nimport hass from 'homeassistant-ws';\n\nasync function main() {\n  // Assuming hass running in `localhost`, under the default `8321` port:\n  const client = await hass({\n    token: 'my-secret-token',\n  });\n}\n```\n\nTokens are available from your profile page under the Homeassistant UI. For documentation on the authentication API, see [the official HA documentation](https://developers.home-assistant.io/docs/auth_api/).\n\n## Configuration options\n\nThe following properties (shown with their defaults) can be passed to the constructor. All are **optional**.\n\n```js\nhass({\n  protocol: 'ws',\n  host: 'localhost',\n  port: 8123,\n  path: '/api/websocket',\n\n  // Must be set if HA expects authentication:\n  token: null,\n\n  // Used to serialize outgoing messages:\n  messageSerializer: (outgoingMessage) =\u003e JSON.stringify(outgoingMessage),\n\n  // Used to parse incoming messages. Receives the entire Websocket message object:\n  messageParser: (incomingMessage) =\u003e JSON.parse(incomingMessage.data),\n\n  // Should return a WebSocket instance\n  ws: (opts) =\u003e {\n    return new WebSocket(\n      `${opts.protocol}://${opts.host}:${opts.port}${opts.path}`\n    );\n  },\n});\n```\n\n## Example\n\nThe following example includes all available methods. For more details on available Homeassistant event types, states, etc. see the [official Websocket API](https://developers.home-assistant.io/docs/external_api_websocket)\n\n```js\nimport hass from 'hass';\n\nasync function main() {\n  // Establishes a connection, and authenticates if necessary:\n  const client = await hass({ token: 'my-token' });\n\n  // Get a list of all available states, panels or services:\n  await client.getStates();\n  await client.getServices();\n  await client.getPanels();\n\n  // Get hass configuration:\n  await client.getConfig();\n\n  // Get a Buffer containing the current thumbnail for the given media player\n  await client.getMediaPlayerThumbnail('media_player.my_player');\n  // { content_type: 'image/jpeg', content: Buffer\u003c...\u003e}\n\n  // Get a Buffer containing a thumbnail for the given camera\n  await client.getCameraThumbnail('camera.front_yard');\n  // { content_type: 'image/jpeg', content: Buffer\u003c...\u003e}\n\n  // Call a service, by its domain and name. The third argument is optional.\n  await client.callService('lights', 'turn_on', {\n    entity_id: 'light.my_light',\n  });\n\n  // Listen for all HASS events - the 'message' event is a homeassistant-ws event triggered for\n  // all messages received through the websocket connection with HASS:\n  //\n  // See https://developers.home-assistant.io/docs/api/websocket/ for details on HASS events:\n  client.on('message', (rawMessageData) =\u003e {\n    console.log(rawMessageData);\n  });\n\n  // Listen only for state changes:\n  client.on('state_changed', (stateChangedEvent) =\u003e {\n    console.log(stateChangedEvent.data.new_state.state);\n  });\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilp%2Fhomeassistant-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilp%2Fhomeassistant-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilp%2Fhomeassistant-ws/lists"}