Created
August 1, 2017 15:50
-
-
Save balloob/3db74043ae97102eddcd11182cf3a876 to your computer and use it in GitHub Desktop.
Example using home-assistant-js-websocket with Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); | |
console.log('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment