Display txt file content in frontend

This is (potentially) brilliant. Thank you.

html isn’t my strong suit but I think I have trimmed it down to just output the txt file line by line with no extra formatting.

However, I’m getting 404 file not found?
(bluetooth_devices.txt is just a random file I’m using for testing)

Am I missing something obvious?

image


  - type: iframe
    url: /packages/Logging/my-log.html
    aspect_ratio: 100%
    title: Log File
<html>
    <meta http-equiv="refresh" content="60" />
    <head>
        <title>Log File</title>
        
        <script>

            // Read the logfile
            // - Returns up to "NumberOfEntries" lines
            // - Entries are returned in order determined by "Direction" parameter

            function GetTextfileLines(FileUrl, NumberOfEntries, Direction) {

                let xmlHttp = new XMLHttpRequest();
                xmlHttp.open( "GET", FileUrl, false );
                xmlHttp.send( null );
                let Lines = xmlHttp.responseText.split("\n");

                let LineCount = Lines.length;
                let LastLineIdx = LineCount -2;   // Last entry is displayed first. The last line of the file is blank, so subtract 2 to get last line index
                let FirstLineIdx =  Math.max(2, LineCount-NumberOfEntries-1);  // ...count backwards but stop before the header lines

                let FileString = "";   
                // let FileString = "<table><tr><th>Date</th><th>Event</th></tr>";   // Table with Header Row 
            
                if (Direction > 0) {
                    for (let i = FirstLineIdx; i <= LastLineIdx; i++) {
                        FileString += Lines[i];
                    }
                } else {
                    for (let i = LastLineIdx; i >= FirstLineIdx; i--) {
                        FileString += Lines[i];
                    }
                }

                return FileString;
            }

        </script>
    </head>

    <body>

        <script>

            // Read up to 10 most recent lines from the file
            document.write(GetTextfileLines("bluetooth_devices.txt", 14, 1));

        </script>

    </body>
</html>        

You have to have the file in the /config/www/ folder on your Home Assistant server. Check the gist again and make sure all the files are in the correct places. hth