Hello
I’m having difficulty getting a node.js app to connect to Home Assistant via the Websocket API. Home assistant is running on an Odroid, Home Assistant OS 7.5 core version 2022.3.5.
I’m attempting to connect using a long-lived token. No matter what I’ve tried, I’m getting error 4 ERR_HASS_HOST_REQUIRED.
My code looks like this (this code verbatim has worked for me in the past, as recent as August of last year, but on a different Home Assistant install):
const hass = require('home-assistant-js-websocket');
const HASS_URL = 'http://192.168.1.15:8213';
const HASS_ACCESS_TOKEN = 'long-lived token string';
let hassSocket;
async function hassInit() {
const hassAuth = new hass.Auth({
hassUrl: HASS_URL,
access_token: HASS_ACCESS_TOKEN,
expires: new Date(new Date().getTime() + 1e11),
clientId: '',
expires_in: new Date(new Date().getTime() + 1e11),
refresh_token: ''
});
console.log(`Connecting to Home Assitant at ${HASS_URL}`);
hassSocket = await hass.createConnection({ hassAuth }).catch( (err) => {
console.log("Home assistent connection error " + err);
switch (err) {
case hass.ERR_CANNOT_CONNECT:
console.log("Cannot connect to Home Asisstant");
break;
case hass.ERR_INVALID_AUTH:
console.log("Invalid authorization");
break;
case hass.ERR_CONNECTION_LOST:
console.log("Connection Lost");
break;
case hass.ERR_HASS_HOST_REQUIRED:
console.log("HASS Host Required");
break;
case hass.ERR_INVALID_HTTPS_TO_HTTP:
console.log("Invalid HTTPS to HTTP");
break;
default:
console.log("Unknown error");
}
exit();
});
}
Any ideas what I’m doing wrong?