<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="A web interface for Home Assistant with WebSocket"> <title>Home Assistant with WebSocket</title> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet"> <script src='http://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js'></script> <script type="text/javascript"> $(document).ready(function() { function msg(str) { $('#msg').prepend('<p>' + str + '</p>'); }; ws = new WebSocket('ws://localhost:8123/api/websocket'); ws.addEventListener('open', function (event) { ws.send('{"id": 1, "type": "subscribe_events", "event_type": "state_changed"}\n'); }); ws.onmessage = function(event) { msg(event.data); }; ws.onclose = function() {msg('Socket closed');}; ws.onopen = function() {msg('Connected...');}; }); </script> </head> <body> <div class="container"> <div class="page-header"> <h1>Connection to Home Assistant over WebSocket</h1> </div> <div class="container-fluid" style="margin-top: 20px;"> <div class="panel panel-default"> <div class="panel-body"> <div id="msg"></div> </div> </div> </div> </div> </body> </html>