# Inventory script for OpenHAB

**URL:** <https://community.openhab.org/t/inventory-script-for-openhab/171004>\
**Category:** Off-Topic\
**Created:** [November 17, 2026, 10:35am UTC](https://community.openhab.org/t/inventory-script-for-openhab/171004 "2026-11-17T10:35:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arohleder](https://community.openhab.org/user_avatar/community.openhab.org/arohleder/32/195387_2.png) [@arohleder](https://community.openhab.org/u/arohleder)\
**Post date:** [November 17, 2026, 10:35am UTC](https://community.openhab.org/t/inventory-script-for-openhab/171004/1 "2026-11-17T10:35:04Z")

</div>

Hallo,

hatte was von nem Inventurscript für Homeassistant gelesen. Hab dank KI mal sowas für Openhab in PHP gebaut. Vielleicht kanns ja einer gebrauchen:

\<?php // ========================================================================= // KONFIGURATION // ========================================================================= $openhabUrl = 'http://192.168.1.100:8080'; // Deine openHAB URL (ohne Schrägstrich am Ende) $apiToken = 'oh.Inventur.DEINAPISCHLÜSSEL'; // Dein openHAB API Token (aus den Benutzereinstellungen) // ========================================================================= // OPENHAB REST API // ========================================================================= function fetchOpenhabThings($url, $token) { $ch = curl\_init(); curl\_setopt\_array($ch, \[CURLOPT\_URL =\> rtrim($url, '/') . '/rest/things', CURLOPT\_RETURNTRANSFER =\> true, CURLOPT\_TIMEOUT =\> 10, CURLOPT\_HTTPHEADER =\> array\_filter(\[ 'Accept: application/json', !empty($token) ? 'Authorization: Bearer ' . $token : null \]) \]); $response = curl\_exec($ch); $httpCode = curl\_getinfo($ch, CURLINFO\_HTTP\_CODE); $error = curl\_error($ch); curl\_close($ch); if ($error) { return \['error' =\> 'cURL Fehler: ' . $error\]; } if ($httpCode !== 200) { return \['error' =\> 'API Fehler: HTTP ' . $httpCode . ' - Bitte URL und API-Token prüfen.' \]; } $data = json\_decode($response, true); if (!is\_array($data)) { return \['error' =\> 'Ungültige Antwort der openHAB API.'\]; } return \['data' =\> $data\]; } // ========================================================================= // DATEN ABRUFEN // ========================================================================= $result = fetchOpenhabThings($openhabUrl, $apiToken); $things = $result\['data'\] ?? \[\]; $errorMsg = $result\['error'\] ?? null; // ========================================================================= // INVENTAR AUFBEREITEN // ========================================================================= $inventory = \[\]; foreach ($things as $thing) { $uidParts = explode(':', $thing\['UID'\] ?? ''); $binding = $uidParts\[0\] ?? 'unbekannt'; $props = $thing\['properties'\] ?? \[\]; $inventory\[\] = \['label' =\> $thing\['label'\] ?? 'Ohne Namen', 'status' =\> $thing\['statusInfo'\]\['status'\] ?? 'UNKNOWN', 'location' =\> $thing\['location'\] ?? '-', 'binding' =\> $binding, 'vendor' =\> $props\['vendor'\] ?? $props\['manufacturer'\] ?? '-', 'model' =\> $props\['modelId'\] ?? $props\['model'\] ?? $props\['hardwareVersion'\] ?? '-', 'firmware' =\> $props\['firmwareVersion'\] ?? $props\['swVersion'\] ?? '-', 'uid' =\> $thing\['UID'\] ?? '' \]; } // ========================================================================= // STATUS-ZÄHLER // ========================================================================= $total = count($inventory); $online = 0; $offline = 0; $other = 0; foreach ($inventory as $item) { if ($item\['status'\] === 'ONLINE') { $online++; } elseif ($item\['status'\] === 'OFFLINE') { $offline++; } else { $other++; } } // HTML-Ausgabe sicher behandeln function e($value) { return htmlspecialchars( (string)$value, ENT\_QUOTES | ENT\_SUBSTITUTE, 'UTF-8' ); } ?\>

\<meta name=“viewport”

```
  content="width=device-width, initial-scale=1.0">

```

openHAB Geräteinventur /\* ========================================================= DESIGN VARIABLEN ========================================================= \*/ :root { color-scheme: dark; --bg: #111827; --container: #1f2937; --surface: #273449; --surface-hover: #334155; --text: #e5e7eb; --heading: #f8fafc; --muted: #9ca3af; --border: #374151; --input: #111827; --accent: #38bdf8; --shadow: rgba(0,0,0,.25); } body.light { color-scheme: light; --bg: #f1f5f9; --container: #ffffff; --surface: #f8fafc; --surface-hover: #e2e8f0; --text: #334155; --heading: #1e293b; --muted: #64748b; --border: #e2e8f0; --input: #ffffff; --accent: #0284c7; --shadow: rgba(0,0,0,.08); } /\* ========================================================= GRUNDLAYOUT ========================================================= \*/ \* { box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 20px; background: var(--bg); color: var(--text); transition: \*background\* .2s, color .2s; } .container { max-width: 1500px; margin: 0 auto; background: var(--container); padding: 22px; border-radius: 12px; box-shadow: 0 2px 12px var(--shadow); } /\* ========================================================= KOPFZEILE ========================================================= \*/ .header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; } h1 { margin: 0; font-size: 1.5rem; color: var(--heading); } .subtitle { color: var(--muted); font-size: .85rem; margin-top: 5px; } .theme-toggle { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 10px 15px; border-radius: 8px; cursor: pointer; font-size: .9rem; transition: .2s; } .theme-toggle:hover { background: var(--surface-hover); border-color: var(--accent); } /\* ========================================================= STATISTIK ========================================================= \*/ .stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; } .stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 15px; } .stat-label { color: var(--muted); font-size: .8rem; margin-bottom: 7px; } .stat-number { font-size: 1.55rem; font-weight: 700; color: var(--heading); } .stat-online .stat-number { color: #4ade80; } .stat-offline .stat-number { color: #f87171; } .stat-other .stat-number { color: #fbbf24; } /\* ========================================================= SUCHLEISTE ========================================================= \*/ .toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 15px; } .search-box { position: relative; flex: 1; min-width: 220px; } input\[type="text"\] { width: 100%; padding: 11px 13px; background: var(--input); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; } input\[type="text"\]:focus { outline: none; border-color: var(--accent); } input::placeholder { color: var(--muted); } .device-count { color: var(--muted); font-size: .9rem; white-space: nowrap; } /\* ========================================================= DESKTOP TABELLE ========================================================= \*/ .table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: 9px; } table { width: 100%; border-collapse: collapse; font-size: .88rem; white-space: nowrap; } th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); } th { background: var(--surface); color: var(--heading); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; } th:hover { background: var(--surface-hover); } th::after { content: ' ⇅'; color: var(--muted); font-size: .8em; } tbody tr:hover { background: var(--surface); } tbody tr:last-child td { border-bottom: none; } /\* ========================================================= STATUS BADGES ========================================================= \*/ .badge { padding: 4px 9px; border-radius: 20px; font-size: .73rem; font-weight: 700; display: inline-block; white-space: nowrap; } .status-ONLINE { background: #14532d; color: #86efac; } .status-OFFLINE { background: #7f1d1d; color: #fecaca; } .status-UNINITIALIZED, .status-UNKNOWN { background: #713f12; color: #fde68a; } .status-REMOVING, .status-INITIALIZING { background: #1e3a8a; color: #bfdbfe; } /\* Hellmodus \*/ body.light .status-ONLINE { background: #dcfce7; color: #166534; } body.light .status-OFFLINE { background: #fee2e2; color: #991b1b; } body.light .status-UNINITIALIZED, body.light .status-UNKNOWN { background: #fef3c7; color: #92400e; } body.light .status-REMOVING, body.light .status-INITIALIZING { background: #dbeafe; color: #1e40af; } /\* ========================================================= UID ========================================================= \*/ .uid { font-family: monospace; font-size: .78rem; color: var(--muted); } /\* ========================================================= MOBILE KARTEN ========================================================= \*/ .mobile-devices { display: none; gap: 11px; } .device-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; } .device-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; } .device-name { color: var(--heading); font-size: 1rem; font-weight: 650; overflow-wrap: anywhere; } .device-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 10px; } .device-field { min-width: 0; } .device-field.full { grid-column: 1 / -1; } .device-label { display: block; color: var(--muted); font-size: .72rem; margin-bottom: 4px; } .device-value { display: block; font-size: .86rem; overflow-wrap: anywhere; } .device-uid { font-family: monospace; font-size: .72rem; color: var(--muted); word-break: break-all; } /\* ========================================================= FEHLER ========================================================= \*/ .error { background: #7f1d1d; color: #fecaca; padding: 14px; border-radius: 8px; margin-bottom: 15px; } body.light .error { background: #fee2e2; color: #991b1b; } .empty-result { display: none; text-align: center; color: var(--muted); padding: 25px; } /\* ========================================================= RESPONSIVE ========================================================= \*/ @media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } } @media (max-width: 700px) { body { margin: 0; padding: 8px; } .container { padding: 13px; border-radius: 10px; } h1 { font-size: 1.2rem; } .header { margin-bottom: 17px; } .theme-toggle { padding: 10px 12px; } .stats-grid { gap: 8px; margin-bottom: 17px; } .stat-card { padding: 11px; } .stat-number { font-size: 1.35rem; } .toolbar { flex-direction: column; align-items: stretch; } .search-box { min-width: 100%; } input\[type="text"\] { padding: 13px; font-size: 16px; } .table-wrapper { display: none; } .mobile-devices { display: grid; } .device-count { padding: 0 2px; } } @media (max-width: 360px) { .device-info { grid-template-columns: 1fr; } .device-field.full { grid-column: auto; } }

```
<!-- =====================================================

     KOPFZEILE

     ===================================================== -->

<div class="header">

    <div>

        <h1>openHAB Geräteinventur</h1>

        <div class="subtitle">

            Übersicht aller Things und Bindings

        </div>

    </div>

    <button class="theme-toggle"

            id="themeToggle"

            onclick="toggleTheme()">

        ☀️ Hellmodus

    </button>

</div>

<?php if ($errorMsg): ?>

    <div class="error">

        <?= e($errorMsg) ?>

    </div>

<?php else: ?>

    <!-- =================================================

         STATISTIK

         ================================================= -->

    <div class="stats-grid">

        <div class="stat-card">

            <div class="stat-label">

                Gesamtgeräte

            </div>

            <div class="stat-number">

                <?= $total ?>

            </div>

        </div>

        <div class="stat-card stat-online">

            <div class="stat-label">

                Online

            </div>

            <div class="stat-number">

                <?= $online ?>

            </div>

        </div>

        <div class="stat-card stat-offline">

            <div class="stat-label">

                Offline

            </div>

            <div class="stat-number">

                <?= $offline ?>

            </div>

        </div>

        <div class="stat-card stat-other">

            <div class="stat-label">

                Sonstiger Status

            </div>

            <div class="stat-number">

                <?= $other ?>

            </div>

        </div>

    </div>

    <!-- =================================================

         SUCHE

         ================================================= -->

    <div class="toolbar">

        <div class="search-box">

            <input

                type="text"

                id="searchInput"

                placeholder="🔍 Name, Raum, Binding, Modell, UID ..."

                oninput="filterTable()"

                autocomplete="off"

            >

        </div>

        <div class="device-count" id="deviceCount">

            <?= $total ?> Geräte

        </div>

    </div>

    <!-- =================================================

         DESKTOP TABELLE

         ================================================= -->

    <div class="table-wrapper">

        <table id="inventoryTable">

            <thead>

                <tr>

                    <th onclick="sortTable(0)">

                        Gerätename

                    </th>

                    <th onclick="sortTable(1)">

                        Status

                    </th>

                    <th onclick="sortTable(2)">

                        Raum / Ort

                    </th>

                    <th onclick="sortTable(3)">

                        Binding

                    </th>

                    <th onclick="sortTable(4)">

                        Hersteller

                    </th>

                    <th onclick="sortTable(5)">

                        Modell

                    </th>

                    <th onclick="sortTable(6)">

                        Firmware

                    </th>

                    <th onclick="sortTable(7)">

                        Thing-UID

                    </th>

                </tr>

            </thead>

            <tbody>

                <?php foreach ($inventory as $item): ?>

                    <tr>

                        <td>

                            <strong><?= e($item\['label'\]) ?></strong>

                        </td>

                        <td>

                            <span class="badge status-<?= e($item\['status'\]) ?>">

                                <?= e($item\['status'\]) ?>

                            </span>

                        </td>

                        <td><?= e($item\['location'\]) ?></td>

                        <td><?= e($item\['binding'\]) ?></td>

                        <td><?= e($item\['vendor'\]) ?></td>

                        <td><?= e($item\['model'\]) ?></td>

                        <td><?= e($item\['firmware'\]) ?></td>

                        <td class="uid"><?= e($item\['uid'\]) ?></td>

                    </tr>

                <?php endforeach; ?>

            </tbody>

        </table>

    </div>

    <!-- =================================================

         MOBILE KARTENANSICHT

         ================================================= -->

    <div class="mobile-devices" id="mobileDevices">

        <?php foreach ($inventory as $item): ?>

            <div class="device-card">

                <div class="device-header">

                    <div class="device-name">

                        <?= e($item\['label'\]) ?>

                    </div>

                    <span class="badge status-<?= e($item\['status'\]) ?>">

                        <?= e($item\['status'\]) ?>

                    </span>

                </div>

                <div class="device-info">

                    <div class="device-field">

                        <span class="device-label">

                            Raum / Ort

                        </span>

                        <span class="device-value">

                            <?= e($item\['location'\]) ?>

                        </span>

                    </div>

                    <div class="device-field">

                        <span class="device-label">

                            Binding

                        </span>

                        <span class="device-value">

                            <?= e($item\['binding'\]) ?>

                        </span>

                    </div>

                    <div class="device-field">

                        <span class="device-label">

                            Hersteller

                        </span>

                        <span class="device-value">

                            <?= e($item\['vendor'\]) ?>

                        </span>

                    </div>

                    <div class="device-field">

                        <span class="device-label">

                            Modell

                        </span>

                        <span class="device-value">

                            <?= e($item\['model'\]) ?>

                        </span>

                    </div>

                    <div class="device-field">

                        <span class="device-label">

                            Firmware

                        </span>

                        <span class="device-value">

                            <?= e($item\['firmware'\]) ?>

                        </span>

                    </div>

                    <div class="device-field full">

                        <span class="device-label">

                            Thing-UID

                        </span>

                        <span class="device-uid">

                            <?= e($item\['uid'\]) ?>

                        </span>

                    </div>

                </div>

            </div>

        <?php endforeach; ?>

    </div>

    <div class="empty-result" id="emptyResult">

        Keine passenden Geräte gefunden.

    </div>

<?php endif; ?>

```

---

<div class="post-metadata">

**Author:** ![hmerk](https://community.openhab.org/user_avatar/community.openhab.org/hmerk/32/56432_2.png) [@hmerk](https://community.openhab.org/u/hmerk)\
**Post date:** [November 17, 2026, 10:36am UTC](https://community.openhab.org/t/inventory-script-for-openhab/171004/2 "2026-11-17T10:36:44Z")

</div>

English please, this is an international community!

---

<div class="post-metadata">

**Author:** ![arohleder](https://community.openhab.org/user_avatar/community.openhab.org/arohleder/32/195387_2.png) [@arohleder](https://community.openhab.org/u/arohleder)\
**Post date:** [November 17, 2026, 10:39am UTC](https://community.openhab.org/t/inventory-script-for-openhab/171004/3 "2026-11-17T10:39:14Z")

</div>

Hi everyone, I recently read about an inventory script for Home Assistant. With the help of AI, I built something similar for openHAB in PHP. Maybe someone else will find it useful:
