Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example using home-assistant-js-websocket with Node
const WebSocket = require('ws');
global.WebSocket = WebSocket;
const HAWS = require("home-assistant-js-websocket");
const getWsUrl = haUrl => `ws://${haUrl}/api/websocket`;
HAWS.createConnection(getWsUrl('localhost:8123')).then(conn => {
HAWS.subscribeEntities(conn, logEntities);
function logEntities(entities) {
Object.keys(entities).forEach(key => console.log(`${key}: ${entities[key].state}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment