import { Auth, createConnection, subscribeEntities, createLongLivedTokenAuth, } from "home-assistant-js-websocket"; const auth = createLongLivedTokenAuth( "http://172.16.206.123:8123", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5MGYyNDk3MDVkMTQ0ZTNjODQ0MDZlMWFkMjQ5NTgwZSIsImlhdCI6MTc0NzExNzM0NiwiZXhwIjoyMDYyNDc3MzQ2fQ.zbbyX-RsgtNV8TOIboc0Kk1YZvWMi5LQMwrf9rkv_SM", ); const connection = await createConnection({ auth }); subscribeEntities(connection, (entities) => { const fatherSleep = getTimeAsleep(parseFloat(entities["sensor.pixel_9_pro_xl_sleep_segment"]?.state || "0")); }); const getTimeAsleep = (ms: number) => { const minutes = ((ms / 1000 / 60) % 60); const hours = ((ms / 1000 / 60 / 60) % 24); return { minutes, hours }; };