Reviving an old iPad Air 1 (iOS 12.5.8, 1GB RAM) as a wall dashboard using a custom lightweight HTML/JS WebSockets client

Reviving an old iPad Air 1 (iOS 12.5.8, 1GB RAM) as a wall dashboard using a custom lightweight HTML/JS WebSockets client

Hi everyone in the Home Assistant community,

Like many of you, I hit a hard wall when trying to use old tablets as dedicated wall panels. With modern versions of Home Assistant, the official frontend (Lovelace and its modern Lit/Polymer dependencies) has simply become too heavy for the old WebKit engine in iOS 12, leading to constant freezes and Out-Of-Memory (OOM) crashes/reboots.

Instead of throwing away my first-generation iPad Air, I decided to build from scratch an ultra-lightweight Single Page Application (SPA) using vanilla HTML5, CSS3, and JavaScript that communicates directly with Home Assistant via WebSockets.

What does this custom dashboard include?

  • Mushroom-inspired UI: Clean cards, interactive chips, and a design tailored for fixed touchscreens.
  • Media player & cameras: Local media server control and camera streams with built-in error handling.
  • Weather, maps, and tasks: Integration with to-do lists, calendar events via WebSockets, and Leaflet maps for device trackers.
  • Advanced memory management: Specifically engineered to prevent memory leaks in iOS 12.

How is it structured technically? (Key highlights)

1. Native WebSockets Connection without loading Lovelace

Instead of loading the entire Home Assistant graphical framework, the script opens a direct socket with the core and handles states reactively:

function connectWS() {
    if (!HA_TOKEN || !HA_URL) return;

    var wsProtocol = HA_URL.indexOf('https') === 0 ? 'wss:' : 'ws:';
    var cleanHost = HA_URL.replace(/^https?:\/\//, '');
    var wsUrl = wsProtocol + '//' + cleanHost + '/api/websocket';

    ws = new WebSocket(wsUrl);

    ws.onmessage = function (event) {
        var data = JSON.parse(event.data);
        if (data.type === 'auth_required') {
            ws.send(JSON.stringify({ type: 'auth', access_token: HA_TOKEN }));
        } else if (data.type === 'auth_ok') {
            sendWS({ type: 'get_states' });
            sendWS({ type: 'subscribe_events', event_type: 'state_changed' });
        }
    };
}

2. Preventing freezes from mass events (requestAnimationFrame)

Home Assistant can fire dozens of state_changed events simultaneously on startup or view changes. To prevent the iPad’s main thread from collapsing, UI updates are queued and processed in a single batch during the next screen refresh cycle using requestAnimationFrame:

var pendingEntityUpdates = {};
var rafScheduled = false;

function queueEntityUpdate(ent) {
    pendingEntityUpdates[ent.entity_id] = ent;
    if (!rafScheduled) {
        rafScheduled = true;
        requestAnimationFrame(function() {
            rafScheduled = false;
            var entitiesToUpdate = pendingEntityUpdates;
            pendingEntityUpdates = {};
            for (var id in entitiesToUpdate) {
                if (entitiesToUpdate.hasOwnProperty(id)) {
                    updateEntityUI(entitiesToUpdate[id]);
                }
            }
        });
    }
}

3. Zero memory leaks on legacy WebKit

Older browsers on iOS easily leak memory if you continuously reload images or camera feeds. To fix this, strict buffer clearing and preloaders are implemented:

var imgPreloader = new Image();
imgPreloader.onload = function () {
    for (var i = 0; i < ids.length; i++) {
        var imgEl = document.getElementById(ids[i]);
        if (imgEl) imgEl.src = url;
    }
    imgPreloader.onload = imgPreloader.onerror = null;
    imgPreloader = null;
};
imgPreloader.onerror = function () {
    imgPreloader.onload = imgPreloader.onerror = null;
};
imgPreloader.src = url;

Additionally, when switching tabs in the sidebar, images on inactive views are cleared (src = '') to instantly release the iPad GPU’s memory.

4. DOM Caching for CPU optimization

To avoid repetitive and expensive calls to document.getElementById(), a local caching dictionary is used:

var domCache = {};
function getCachedElement(id) {
    if (!domCache[id]) {
        domCache[id] = document.getElementById(id);
    }
    return domCache[id];
}

Conclusion

If you have an old iPad sitting in a drawer because it can no longer handle modern home automation apps or heavy web interfaces, building a lightweight SPA based on pure WebSockets is the best alternative to breathe new life into it as a wall control panel. It runs incredibly smooth!

Apple hates you! You could just buy new apple products instead! :face_with_steam_from_nose:

More information please. Is there a sample project (on GitHub?) where we can see how to get this working from top to bottom… for some uninitiated like me…?

I mean, I like the ideas but to get the above to work as in a finished dashboard is beyond me.

Please please please.

Hi k8gg! I’m really glad to see some interest in reviving these old iPads! There’s a lot of people, like me, with an old ipad ready to be use in something like a dashboard.

To be fully transparent, there isn’t a magical automated website where you can just upload your Home Assistant configuration and download a ready-to-use ipad.html (I really hope it could be possible!). The main reason is that every Home Assistant setup is entirely unique—your entity IDs (light.living_room, sensor.temperature), custom floorplans, and dashboard cards are completely different from mine. If I shared my exact file with you, nothing would work out of the box.

However, you don’t need to know how to code to build your own! Since I built mine with the help of AI, you can do the exact same thing by guiding an AI model (like ChatGPT or Claude) step-by-step. Here is a practical roadmap and some code examples you can use to build your own lightweight dashboard from scratch.


Step 1: Ask the AI for a Lightweight HTML Shell & CSS Grid

Start by telling the AI to create a single-file page optimized for Safari on iOS 12, avoiding heavy frameworks, Polymer, or complex dependencies.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>iPad Dashboard</title>
    <style>
        body { background: #121212; color: #fff; font-family: sans-serif; display: grid; grid-template-columns: 80px 1fr; height: 100vh; margin: 0; overflow: hidden; }
        .sidebar { background: #1e1e1e; display: flex; flex-direction: column; align-items: center; padding-top: 20px; }
        .main-content { padding: 20px; overflow-y: auto; }
        .card { background: rgba(255, 255, 255, 0.05); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
    </style>
</head>
<body>
    <div class="sidebar"></div>
    <div class="main-content">
        <div class="card">
            <h2>Living Room Temperature</h2>
            <p id="state-sensor">Loading...</p>
        </div>
    </div>
</body>
</html>

Step 2: Establish a Direct WebSocket Connection

Instead of loading Lovelace, ask the AI to implement a direct WebSocket connection using your Long-Lived Access Token to communicate with Home Assistant.

var HA_URL = 'http://YOUR_HA_IP:8123';
var HA_TOKEN = 'YOUR_LONG_LIVED_ACCESS_TOKEN';
var ws;

function connectWS() {
    var wsProtocol = HA_URL.indexOf('https') === 0 ? 'wss:' : 'ws:';
    var cleanHost = HA_URL.replace(/^https?:\/\//, '');
    ws = new WebSocket(wsProtocol + '//' + cleanHost + '/api/websocket');

    ws.onmessage = function (event) {
        var data = JSON.parse(event.data);
        if (data.type === 'auth_required') {
            ws.send(JSON.stringify({ type: 'auth', access_token: HA_TOKEN }));
        } else if (data.type === 'auth_ok') {
            console.log('Connected to HA via WebSocket!');
            // Request initial states and subscribe to changes
            ws.send(JSON.stringify({ id: 1, type: 'get_states' }));
            ws.send(JSON.stringify({ id: 2, type: 'subscribe_events', event_type: 'state_changed' }));
        } else if (data.type === 'event') {
            // Handle real-time state changes here
            var newSt = data.event.data.new_state;
            if (newSt && newSt.entity_id === 'sensor.my_temperature') {
                document.getElementById('state-sensor').innerText = newSt.state + ' °C';
            }
        }
    };
}
document.addEventListener('DOMContentLoaded', connectWS);

Step 3: Handle UI Performance & Memory Management (Crucial for iOS 12!)

Old iPads have only 1GB of RAM and old WebKit engines. If you don’t batch UI updates or if you leak memory, Safari will crash with Out-Of-Memory (OOM) errors. Ask the AI to use requestAnimationFrame for UI updates:

var pendingUpdates = {};
var rafScheduled = false;

function queueEntityUpdate(entity) {
    pendingUpdates[entity.entity_id] = entity;
    if (!rafScheduled) {
        rafScheduled = true;
        requestAnimationFrame(function() {
            rafScheduled = false;
            for (var id in pendingUpdates) {
                var ent = pendingUpdates[id];
                // Update your HTML elements safely here
                if (id === 'sensor.my_temperature') {
                    document.getElementById('state-sensor').innerText = ent.state + ' °C';
                }
            }
            pendingUpdates = {};
        });
    }
}

Final Tip: Build it Section by Section

Don’t ask the AI to build everything at once. Go component by component:

  1. “Write a lightweight JavaScript function to toggle a specific switch entity when clicked.”
  2. “Add a simple media player card structure using REST/WebSocket calls.”
  3. “Create a camera stream element with error handling and retry limits.”

By taking it step-by-step and feeding the AI your specific entity IDs and layouts, you can easily build a gorgeous, buttery-smooth custom dashboard tailored precisely to your home!


iPad.html version


Real HA app