---
title: "Resi DALI"
description: "Ściemniaj 64 gear DALI i 16 grup przez Modbus RTU na bramie RESI-DALI-SIO/ETH. Szablon runtime TapHome ze sterowaniem per gear i grupą."
url: "https://taphome.com/pl/compatibility/resi-dali-dali/"
language: pl
lastmod: 2026-11-15
generator: hugo
ai:
  topics: ["modbus-rtu","lighting","dali","dali-1.0","rs485","din-rail","gateway","dimming","broadcast"]
  questions: ["Jak ściemniam pojedyncze lampy DALI z TapHome przez bramę RESI-DALI-SIO?","Jak steruję grupami DALI przez szablon runtime Resi DALI?","Jaka jest różnica między szablonami Resi DALI i Resi Dali - Konfiguracja?","Jak TapHome wykrywa awarię lampy i awarię zasilania na gear-u DALI?","Jak dodaję lub usuwam gear DALI z grupy z TapHome?","Jak podłączam RESI-DALI-SIO do zasilacza RESI-DALI-PS i magistrali DALI?"]
---

# Resi DALI

Komunikacja: Modbus RTU

- [Strona produktu RESI-DALI-SIO/ETH/PS](https://www.resi.cc/prestashop/en/home/1-resi-dali-sioethps.html)
- [RESI Informatik & Automation](https://www.resi.cc)

## Poradnik integracji

Szablon **Resi DALI** jest runtime'owym odpowiednikiem operacyjnym narzędzia uruchomieniowego *Resi Dali - Konfiguracja*. Łączy TapHome z w pełni zaadresowaną magistralą oświetleniową DALI przez bramę Modbus-DALI RESI-DALI-SIO lub RESI-DALI-ETH i udostępnia codzienne sterowanie dla **maksymalnie 64 indywidualnie zaadresowanych urządzeń sterujących DALI (gears)** (krótkie adresy 0–63) i **16 grup broadcast DALI** (0–15), plus status DALI per gear, diagnostykę awarii urządzenia sterującego i awarii lampy.

Komunikacja z bramą używa Modbus RTU przy 9600 baud 8N1. Zapisy jasności idą do `H:510 LAMP LEVEL` (per gear) i `H:520 GROUP LEVEL` (per grupa); polecenia konfiguracyjne i zapytania per gear są tunelowane przez `H:511 LAMP COMMAND` / `H:512 LAMP COMMAND + REPEAT`, podczas gdy rejestr bramy `H:550 DALI STATUS` jest pollowany pod kątem gotowości odpowiedzi.

> [!NOTE]
> Ten szablon zakłada, że **krótkie adresy DALI są już zaprogramowane** na magistrali. Jeśli gear-y nie mają jeszcze adresu, użyj najpierw szablonu **Resi Dali - Konfiguracja** (lub bezpłatnego narzędzia producenta MODBUSConfigurator / DCA), aby uruchomić kreatora losowego adresowania DALI 2.0 — patrz [*Relacja z szablonem konfiguracyjnym*](https://taphome.com/pl/compatibility/resi-dali-dali/#relacja-z-szablonem-konfiguracyjnym) poniżej.

## Połączenie sprzętowe

RESI-DALI-SIO (RS-485) i RESI-DALI-ETH (Ethernet) to bramy master na szynę DIN, które znajdują się między hostem szeregowym/Ethernet a magistralą oświetleniową DALI. SIO jest w obudowie CEM17 (17,5 × 90 × 56,4 mm), a ETH w szerszej obudowie CEM35 (35,8 × 90 × 56,4 mm), aby pomieścić złącze RJ45. Żadna z bram nie zasila samodzielnie magistrali DALI — towarzyszący zasilacz magistrali DALI (RESI-DALI-PS lub dowolny zgodny zasilacz DALI 200 mA) jest obowiązkowy.

### Podłączenie RESI-DALI-SIO (RS-485)

![Schemat połączeń RESI-DALI-SIO — zewnętrzny zasilacz DALI (góra) i połączony z RESI-DALI-PS (dół)](https://taphome.com/images/compatibility/resi-dali-dali/wiring-sio_hu_1af043ee91b2b0ed.jpg)

Zaciski po lewej stronie RESI-DALI-SIO (od góry → na dół): `GND`, `+12..48V=`, `RS485 DATA+ (A+)`, `RS485 DATA- (B-)`, `RS485 GND`, `RS232 TX`, `RS232 RX`, `RS232 GND`. Zaciski magistrali DALI po przeciwnej stronie to **`D+ / N/C / D-`** (3-pinowy blok USLIM, środkowy pin `N/C` pozostaje niepodłączony).

Do instalacji TapHome użyj interfejsu RS-485:

- `RS485 DATA+ (A+)` → A+/D+ na magistrali RS-485 TapHome
- `RS485 DATA- (B-)` → B-/D- na magistrali RS-485 TapHome
- `RS485 GND` → GND na zasilaczu TapHome (zalecane dla stabilnej komunikacji)
- `+12..48V=` / `GND` → zasilanie pierwotne 12–48 V DC

### Podłączenie RESI-DALI-ETH (Ethernet)

![Schemat połączeń RESI-DALI-ETH — zewnętrzny zasilacz DALI (góra) i połączony z RESI-DALI-PS (dół)](https://taphome.com/images/compatibility/resi-dali-dali/wiring-eth_hu_4bf0a5e8d8724d0b.jpg)

Wariant Ethernet ma te same zaciski magistrali DALI (`D+ / N/C / D-`) i wejścia zasilania pierwotnego (`GND`, `+12..48V=`), plus pojedyncze złącze RJ45 dla Ethernetu 10/100 Mbit. Fabryczne ustawienia IP to **192.168.0.191 / 255.255.255.0 / 192.168.0.1** z Modbus Unit ID 255; wbudowane UI webowe używa danych logowania `RESI` / `RESI`.

Ponieważ jest to szablon Modbus RTU, TapHome nie komunikuje się z RESI-DALI-ETH przez natywny Modbus/TCP. Użyj go zamiast tego w **przezroczystym trybie RTU-over-Ethernet**, lub umieść SIO za mostem szeregowy-IP (Moxa NPort, USR-TCP232) — patrz *Konfiguracja → Konfiguracja RTU-over-TCP* poniżej.

### Zasilacz magistrali DALI (RESI-DALI-PS)

![RESI-DALI-PS — zasilanie magistrali DALI samodzielnie (góra) i połączone z bramą SIO/ETH (dół)](https://taphome.com/images/compatibility/resi-dali-dali/wiring-dali-ps_hu_bea720a419338afa.jpg)

RESI-DALI-PS dostarcza do **200 mA** na magistrali DALI (prąd zwarciowy ~225 mA, napięcie magistrali typowo 14–18 V) i obsługuje do 64 statecznikow DALI 1.0 lub urządzeń sterujących DALI 2.0 na pojedynczej linii. Strona pierwotna akceptuje to samo zasilanie 12–48 V DC, co jednostka SIO/ETH. Brama i zasilacz podłączają się do tej samej pary `D+` / `D-` — zasilacz energizuje magistralę, podczas gdy brama czyta i zapisuje ramki DALI.

Trzy diody LED na zasilaczu pomagają w diagnostyce awarii: **POWER** (pierwotne 12–48 V OK, świeci stale podczas normalnej pracy), **DALI** (krótko miga podczas ruchu na magistrali DALI), **ERR** (świeci stale przy awarii zasilacza, zwarciu DALI lub przeciążeniu magistrali — musi być wyłączona podczas normalnej pracy).

### Topologia magistrali DALI

Linia DALI ma kilka twardych ograniczeń, które bezpośrednio wpływają na stabilność runtime:

| Przekrój przewodnika | Maks. długość kabla DALI |
|---------------------|-------------------------|
| 1,5 mm² | 300 m |
| 1,0 mm² | 238 m |
| 0,75 mm² | 174 m |
| 0,5 mm² | 116 m |

Limit wynika z maksymalnie dopuszczalnego **spadku napięcia 2 V** na kablu DALI. Pozostałe zasady:

- Maksymalnie 64 stateczniki DALI 1.0 **i** do 64 urządzeń sterujących DALI 2.0 na magistralę (oddzielne przestrzenie krótkich adresów).
- Tylko topologia drzewa — żadnych pierścieni, żadnych pętli.
- Rzeczywista liczba gear-ów zależy także od znamionowego prądu zasilacza (typowo 200 mA na RESI-DALI-PS; licz ~2 mA na gear plus rezerwa).

> [!WARNING]
> **RESI-DALI-PS (lub równoważny zasilacz DALI) jest obowiązkowy.** Bez niego brama nie może zasilać magistrali, a każdy odczyt per gear zakończy się timeoutem *"Gear not responding!"*. Jeśli na długiej linii dodawany jest drugi zasilacz, wstaw dławik DALI lub podziel magistralę na galwanicznie oddzielone segmenty.

## Konfiguracja

### Aktywacja komunikacji Modbus

Parametry szeregowe hosta na RESI-DALI-SIO są wybierane 4-pozycyjnym przełącznikiem DIP na module. Szablon TapHome jest na stałe ustawiony na **9600 baud 8N1**, więc przełączniki DIP muszą się zgadzać.

| DIP1 | DIP2 | Baud rate |
|------|------|-----------|
| **OFF** | **OFF** | **9600 bd (wymagane przez TapHome)** |
| ON | OFF | 19200 bd |
| OFF | ON | 38400 bd |
| ON | ON | Używa baud rate zaprogramowanego w FLASH (fabryczne 57600 bd) |

| DIP4 | Źródło Modbus Unit ID |
|------|----------------------|
| **OFF** | Rejestr FLASH `H:65221` jest honorowany — wymagane, jeśli podczas uruchomienia zaprogramowano niestandardowy Slave ID |
| ON | Sprzętowy fallback — Unit ID jest wymuszony na `255`, wartość FLASH jest ignorowana |

`DIP3` to bit zarezerwowany dla produktu; pozostaw go w pozycji fabrycznej. Parzystość jest stała na `None`, a bit stopu na 1 (format ramki 8N1) dla wybranych powyżej kombinacji baud rate DIP1/DIP2.

**Terminacja RS-485:** zakończ magistralę rezystorem 120 Ω na obu końcach. TapHome Core zapewnia jedną terminację na swoich zaciskach BUS; jeśli brama RESI jest ostatnim urządzeniem na linii, dodaj dyskretny rezystor 120 Ω między `A+` / `B-` na jej zaciskach RS-485.

### Slave ID

Domyślny fabryczny Modbus Unit ID to **255** (rejestr FLASH `H:65221` czyta `0xFFFF`, co brama klampuje na 255). Szablon udostępnia atrybut serwisowy na poziomie modułu **Slave ID**, który odczytuje ten rejestr, dzięki czemu skonfigurowany adres można zweryfikować po imporcie.

Zmiana Slave ID jest sprawą uruchomienia obsługiwaną przez bratni szablon *Resi Dali - Konfiguracja* — ten szablon runtime celowo nie zapisuje do `H:65221` ani nie wyzwala resetu programowego, dzięki czemu może pozostać aktywny w projekcie bez ryzyka przypadkowej rekonfiguracji bramy.

### Konfiguracja RTU-over-TCP

Ponieważ szablon używa połączenia Modbus RTU, oferowany jest również parametr importu `IpAddress` dla instalacji, w których TapHome dociera do bramy przez **most szeregowy-IP** (Moxa NPort, USR-TCP232) lub przez **RESI-DALI-ETH w przezroczystym trybie RTU-over-Ethernet**. W takim przypadku skieruj `IpAddress` na IP mostu / jednostki ETH i zachowaj wszystkie inne ustawienia identyczne z wariantem RS-485. Dla czystego Modbus/TCP bardziej naturalny byłby szablon oparty na TCP — ten szablon Modbus RTU oczekuje konkretnie ramkowego ruchu RTU.

> [!WARNING]
> **Tylko jeden master Modbus naraz.** Ani DALI, ani Modbus RTU nie arbitrują między równoczesnymi masterami. Jeśli PLC, BMS lub narzędzie PC (na przykład MODBUSConfigurator) również polluje bramę, zapytania gear będą kolidować, a TapHome będzie zgłaszać sporadyczne błędy *"Gear not responding!"*.

## Relacja z szablonem konfiguracyjnym

Ta sama definicja `Dali.xml` jest dostarczana z bramą RESI jako **dwa komplementarne szablony TapHome**, które działają w różnych fazach cyklu życia tego samego sprzętu:

| Szablon | Faza | Co robi | Kiedy używać |
|---------|------|---------|--------------|
| **Resi Dali - Konfiguracja** (`resi-dali-daliconfig`) | Jednorazowe uruchomienie | Kreator losowego adresowania DALI 2.0, sondowanie device-type per adres, testy zdrowia broadcast ON/OFF, **Resetuj krótkie adresy / Delete short address / Change short address**, **Set Slave ID**, **Reset Gateway** | Nowa instalacja: przypisz krótkie adresy 0–63 urządzeniom sterującym, sprawdź, które adresy są zajęte |
| **Resi DALI** (`resi-dali-dali`, ten szablon) | Codzienne sterowanie runtime | Ściemnianie per gear (64 gear-y), ściemnianie grupowe (16 grup), diagnostyka DALI 1.0 per gear, zarządzanie członkostwem grup | Po uruchomieniu: sterowanie oświetleniem dla użytkownika końcowego |

**Typowy przebieg projektu:**

1. Podłącz i zasil magistralę DALI (RESI-DALI-PS) i bramę.
2. Zaimportuj szablon **Resi Dali - Konfiguracja**, uruchom akcję modułu *Resetuj krótkie adresy* (*Confirm* = *Yes*), a następnie wybierz *Start* w kreatorze *Find New Devices* — sam przechodzi przez *Skanuj krótki adres* → *Set SEARCHADDR* → *Sprawdź* → *PROGRAM SHORT ADDRESS*, aż zatrzyma się na *Zakończ*; potem zamknij sesję przez *TERMINATE*. Zweryfikuj przez *Gear 0..63* i *Turn On / Off All Lamps*.
3. Usuń moduł **Resi Dali - Konfiguracja** z projektu.
4. Zaimportuj szablon **Resi DALI** (ten) do sterowania runtime. Zmapuj urządzenia *Gear N* i *Group N* na sceny, harmonogramy i reguły TapHome.

Oba szablony mogą również tymczasowo współistnieć — np. przy dodawaniu nowego gear-a do działającej instalacji — ale tylko jeden powinien wysyłać ruch Modbus jednocześnie. Szablon runtime celowo pomija akcje rekonfiguracji bramy (Reset Gateway, Set Slave ID, broadcast ALL LEVEL), dzięki czemu może pozostać w projekcie bez ryzyka nadpisania ustawień uruchomienia.

> [!TIP]
> Bezpłatne narzędzie DCA producenta **MODBUSConfigurator** (Windows, dostępne ze strony RESI) można również użyć do uruchomienia zamiast szablonu TapHome *Resi Dali - Konfiguracja*. Szablon runtime *Resi DALI* działa tak samo, niezależnie od tego, którego narzędzia użyto do przypisania krótkich adresów.

## Możliwości urządzenia

Szablon udostępnia 80 urządzeń DALI w TapHome, zorganizowanych w dwóch równoległych grupach: 64 ściemniacze *Gear* (jeden na każdy krótki adres DALI) i 16 ściemniaczy *Group* (jeden na każdą grupę DALI). Jeden atrybut serwisowy na poziomie modułu uzupełnia obraz.

### Ściemnianie per gear — Gear 0 … Gear 63

Każde z 64 urządzeń serwisowych **Gear 0**, **Gear 1**, … **Gear 63** to ściemniacz TapHome, który celuje w pojedyncze urządzenie sterujące DALI pod odpowiadającym krótkim adresem. Zapisy jasności idą do `H:510 LAMP LEVEL` (TapHome 0–100 % jest skalowane liniowo do zakresu DALI arc power, ograniczonego przez własne `MIN LEVEL` i `MAX LEVEL` gear-a); rzeczywisty poziom jest odczytywany z `H:511` przez polecenie DALI `QUERY ACTUAL LEVEL` (`0xA0`) i przeskalowywany z powrotem do 0–100 %.

Gdy szablon importuje gear, skrypt init najpierw sonduje gear za pomocą `QUERY STATUS` (`0x90`); każdy bajt odpowiedzi dowodzi, że gear jest obecny, i jest zapisywany jako jego status. Odpowiedź `0x8000` „brak odpowiedzi" oznacza gear jako *nieodpowiadający* (na losowe 1–60 s) i emituje **„Gear not responding!"** w logu TapHome. Jeśli gear odpowie, skrypt init następnie czyta `QUERY MIN LEVEL` (`0xA2`) i `QUERY MAX LEVEL` (`0xA1`) i zapisuje wyniki w stanie wewnętrznym dla okresowego readscriptu.

Każde zapytanie jest zabezpieczone przed nieaktualnymi i uszkodzonymi odpowiedziami: przed każdym zapytaniem szablon odczytuje nieodczytaną odpowiedź pozostawioną w `H:511`, aby nie została uznana za odpowiedź na nowe zapytanie. Odpowiedź poziomu, która nie jest prawidłowym poziomem (`0xFF`, `0x20FF` kolizja na magistrali, `0x8000` brak odpowiedzi) lub mieści się między 1 a `MIN LEVEL` gear-a, jest odrzucana i zachowywany jest ostatni poziom, a zmieniony poziom jest akceptowany dopiero po drugim identycznym odczycie. Atrybuty serwisowe poziomu pokazują `--` zamiast nieprawidłowej wartości.

Każdy gear udostępnia 12 atrybutów serwisowych, które na żądanie czytają polecenia zapytań DALI 1.0 / 2.0:

| Atrybut serwisowy | Polecenie DALI | Zgłasza |
|------------------|---------------|---------|
| **Short Address** | (wewnętrzny) | Krótki adres (0–63), na który celuje to urządzenie — ustalony w czasie importu szablonu |
| **Device Type** | `QUERY DEVICE TYPE` (`0x99`) | `DT{n}` (np. `DT0` fluorescencyjny, `DT6` LED, `DT8` kolor / tunable white) lub `--` gdy brak odpowiedzi. Gear z kilkoma typami urządzenia odpowiada `0xFF` (MASK); szablon wtedy wylicza je poleceniem `QUERY NEXT DEVICE TYPE` (`0xA7`), np. `DT6, DT8`, lub pokazuje `MASK`, gdy nie zostanie zwrócony żaden typ |
| **Physical Min Level** | `QUERY PHYSICAL MIN LEVEL` (`0x9A`) | Wymuszony sprzętowo minimalny poziom ściemniania w % |
| **Max Level** | `QUERY MAX LEVEL` (`0xA1`) | Skonfigurowana górna granica używana przy skalowaniu 0–100 % na DALI arc power |
| **Min Level** | `QUERY MIN LEVEL` (`0xA2`) | Skonfigurowana dolna granica używana przy skalowaniu 0–100 % na DALI arc power |
| **Power Up Level** | `QUERY POWER ON LEVEL` (`0xA3`) | Jasność przywrócona po ponownym zasileniu magistrali DALI |
| **System Failure Level** | `QUERY SYSTEM FAILURE LEVEL` (`0xA4`) | Jasność przyjęta, gdy magistrala traci komunikację na >500 ms |
| **Groups** | `QUERY GROUPS 0-7` (`0xC0`) + `QUERY GROUPS 8-15` (`0xC1`) | Lista grup DALI (oddzielona przecinkami), do których należy gear (`None` lub np. `0,3,7`) |
| **DALI Status** | `QUERY STATUS` (`0x90`) | Zdekodowany bajt statusu z jego surową wartością: `OK`, gdy żaden bit nie jest ustawiony, w przeciwnym razie ustawione flagi — `gear failure`, `lamp failure`, `lamp on`, `limit error`, `fade running`, `reset state`, `missing short address`, `power cycle` — np. `lamp on (0x04)`. Awaria obecna od pierwszej odpowiedzi gear-a jest oznaczona `not raised: … reported since start` |
| **Fade** | `QUERY FADE TIME/FADE RATE` (`0xA5`) + `QUERY EXTENDED FADE TIME` (`0xA8`) | `fade time {n} ({t} s), fade rate {n}`; czas przejścia `off`, gdy wynosi 0, lub `extended 0x..`, gdy gear zamiast tego używa rozszerzonego czasu przejścia |
| **DALI Version** | `QUERY VERSION NUMBER` (`0x97`) | `DALI-1` lub `DALI-2 {major}.{minor}`, a za nim surowa wartość w nawiasach |
| **Bus statistics** | (wewnętrzne liczniki) | Liczniki od startu: zapytania, odczytane nieaktualne odpowiedzi, brak odpowiedzi, kolizje, odrzucone poziomy |

Okresowy readscript na każdym gear-ze czyta aktualny poziom arc (`0xA0`) i odpytuje `QUERY STATUS` (`0x90`) co najmniej raz na 60 cykli odczytu. Bit 0 bajtu statusu wywołuje **„Control gear failure!"**, a bit 1 **„Lamp failure!"** — wystawione jako ostrzeżenia/błędy TapHome, dzięki czemu uszkodzona świetlówka lub wyzwolony sterownik LED pojawia się w logu aktywności bez ręcznego pollowania. Zmieniony bit awarii jest przyjmowany dopiero po drugim identycznym odczycie, a o utraconą odpowiedź szablon pyta jeszcze raz, zanim zgłosi gear jako **„Gear not responding!"**. Bity awarii, które gear zgłasza w swojej pierwszej odpowiedzi, są traktowane jako jego stan trwały: są pokazywane w **DALI Status**, ale nie są wywoływane, dopóki bit się nie wyzeruje — późniejsza awaria jest wtedy znów wywoływana. Awaria zasilania nie jest wywoływana jako błąd; bit statusu pojawia się w **DALI Status** jako `power cycle`.

### Akcje konfiguracyjne per gear

Pięć akcji serwisowych na każdym urządzeniu *Gear N* zapisuje polecenia konfiguracyjne DALI (auto-powtarzane w 100 ms przez `H:512 LAMP COMMAND + REPEAT`, jak wymagają polecenia DALI nieulotne):

- **Add to Group** (parametr `Group ID` 0–15) — wysyła `ADD TO GROUP` (`0x60+grp`), więc gear dołącza do wybranej grupy DALI i będzie posłusznie wykonywać następne zapisy broadcast grupy.
- **Remove from Group** (parametr `Group ID` 0–15) — wysyła `REMOVE FROM GROUP` (`0x70+grp`).
- **Reset to Default Settings** — wysyła DALI `RESET` (`0x20`); przywraca wszystkie parametry NVM gear-a (max/min/power-on/system-failure level, członkostwo w grupach, sceny) do fabrycznych domyślnych.
- **Set Startup Levels** — przechwytuje aktualne arc power i zapisuje je jako Power On Level *i* System Failure Level w kolejności: `STORE ACTUAL LEVEL IN DTR` (`0x21`) → `STORE DTR AS POWER ON LEVEL` (`0x2C`) → `STORE DTR AS SYSTEM FAILURE LEVEL` (`0x2D`), każdy z 10 ms odstępem.
- **Disable fading** (bez parametrów) — ładuje `0` do rejestru transferu danych DALI (`0xA300` zapisane do `H:541`) i zapisuje je w gear-ze jako czas przejścia (`0x2E`) i rozszerzony czas przejścia (`0x30`), każdy z 100 ms odstępem, więc zmiany poziomu działają bez płynnego przejścia. Aktualne wartości pokazuje atrybut **Fade**.

### Ściemnianie grupowe — Group 0 … Group 15

Każde z 16 urządzeń serwisowych **Group 0**, **Group 1**, … **Group 15** to ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a należącego do tej grupy DALI, używając `H:520 GROUP LEVEL` (TapHome 0–100 % jest mnożone przez `0xFE` → DALI arc power 0–254). DALI nie pozwala bramie *odczytać* poziomu grupy — magistrala niesie tylko zapis broadcast — więc TapHome przechowuje ostatnio zapisaną wartość jako „aktualny" poziom. Na urządzeniach grupy nie ma skryptów init ani read.

Każde urządzenie *Group N* udostępnia dwie akcje serwisowe do masowego zarządzania członkostwem:

- **Add All Lamps to Group** — broadcastuje `ADD TO GROUP` (`0x60+grp`) przez `H:532 ALL COMMAND + REPEAT`. **Każdy gear na magistrali** dołącza do grupy niezależnie od swojego aktualnego krótkiego adresu.
- **Remove All Lamps from Group** — broadcastuje `REMOVE FROM GROUP` (`0x70+grp`). Każdy gear opuszcza grupę.

> [!TIP]
> Użyj ściemniania grupowego dla „świateł kuchennych", „downlightów salonu" lub dowolnej strefy, w której wiele gear-ów ma śledzić pojedynczy ściemniacz. Zapisy grupowe są znacznie wydajniejsze niż równoległe sterowanie pojedynczymi gear-ami — pojedyncza transakcja Modbus dociera do maks. 64 gear-ów jednocześnie.

### Diagnostyka na poziomie modułu

Moduł udostępnia pojedynczy atrybut serwisowy:

- **Slave ID** — czyta Modbus Unit ID przechowywane w rejestrze FLASH `H:65221`. Aktywne tylko gdy `DIP4 = OFF`; przy `DIP4 = ON` brama wymusza adres 255 niezależnie od wartości FLASH. Użyj do weryfikacji adresu bramy przed dodaniem kolejnych urządzeń, zwłaszcza po rundzie uruchomienia, która zapisała niestandardowy ID.

## Rozwiązywanie problemów

### „Gear not responding!" na znanym zaadresowanym gear-ze

1. Potwierdź napięcie magistrali DALI na gear-ze: 11,5–22,5 V (typowo 14–16 V). Niższe odczyty zwykle wskazują na zwarcie lub magistralę, która jest zbyt długa dla przekroju kabla (patrz *Topologia magistrali DALI*).
2. Sprawdź diodę **ERR** na RESI-DALI-PS — jeśli świeci, magistrala jest w zwarciu, przeciążona lub zasilacz sam jest uszkodzony.
3. Uruchom ponownie sondowanie *Gear N* w bratnim szablonie *Resi Dali - Konfiguracja* — szablon runtime ponawia próbę dopiero po losowej przerwie do 60 s, szablon konfiguracyjny daje natychmiastowe pass/fail per adres.
4. Zweryfikuj, czy gear w ogóle ma krótki adres. Jeśli został wymieniony lub zresetowany fabrycznie na magistrali, będzie nieadresowany i musi zostać ponownie uruchomiony przez *Resi Dali - Konfiguracja*.

### Ściemnianie grupowe nie ma efektu

1. Potwierdź, że co najmniej jeden gear jest członkiem grupy — otwórz *Gear N → Groups* na każdym podejrzanym członku i sprawdź, czy ID grupy pojawia się na liście oddzielonej przecinkami.
2. Jeśli brakuje członkostwa, wyzwól akcję **Add to Group** na każdym gear-ze indywidualnie, lub użyj **Add All Lamps to Group** na urządzeniu grupy dla broadcastu po całej magistrali.
3. Pamiętaj, że **Group N** jest tylko-do-zapisu — suwak ściemniacza w TapHome przechowuje ostatnio zapisaną wartość, ale nie odzwierciedla rzeczywistego stanu magistrali. Jeśli gear-y są wyłączone, polecenie poziomu grupy nie ma na nie efektu.

### Awaria lampy / awaria zasilania nie są zgłaszane

1. Otwórz atrybut **DALI Status** gear-a. Jeśli kończy się na `not raised: … reported since start`, awaria była obecna już w pierwszej odpowiedzi gear-a i jest traktowana jako jego stan trwały — jest pokazywana, ale nie jest wywoływana, dopóki bit raz się nie wyzeruje.
2. Awaria zasilania w ogóle nie jest wywoływana jako błąd; bit statusu jest pokazywany w **DALI Status** jako `power cycle`.
3. Nowa awaria pojawia się dopiero po odpytaniu statusu (co najmniej raz na 60 cykli odczytu) i dwukrotnym identycznym odczycie, więc krótkie migotanie bitu awarii nie jest zgłaszane.

### Sporadyczne błędy Modbus po uruchomieniu

1. Upewnij się, że żaden inny master Modbus (MODBUSConfigurator, PLC, BMS) nie polluje bramy równolegle. DALI i Modbus nie arbitrują między masterami. Atrybut **Bus statistics** na każdym gear-ze zlicza od startu odczytane nieaktualne odpowiedzi, brakujące odpowiedzi, kolizje i odrzucone poziomy — stale rosnące liczniki wskazują na równoległy ruch na bramie lub na magistrali DALI.
2. Zweryfikuj, że `RS485 GND` jest połączony między bramą a wspólną masą zasilacza TapHome — brakująca GND to najczęstsza awaria RS-485 na długich liniach.
3. Dla RTU-over-TCP przez most szeregowy potwierdź, że most działa w trybie RTU framed (nie raw TCP socket) i że odstęp między znakami po stronie szeregowej respektuje czasowanie 9600 baud 8N1.
4. Jeśli objawy pojawiły się po zmianie Slave ID przez szablon *Resi Dali - Konfiguracja*, ponownie zaimportuj ten szablon runtime z nowym parametrem importu `SlaveId` — wcześniej zaimportowany moduł nadal polluje pod starym adresem.

## Dostępne urządzenia 80

Te urządzenia pojawią się w TapHome po imporcie.

Resi DALI Moduł

Atrybuty serwisowe

|          |                                                                                                                                                                                         |
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Slave ID | Czyta Modbus Unit ID przechowywane w rejestrze FLASH H:65221 — aktywne tylko gdy DIP4=OFF (fabryczny domyślny 255). Użyj do weryfikacji adresu bramy przed dodaniem kolejnych urządzeń. |

Atrybuty serwisowe

${xml\_slave\_id}

```taphome
modbusr(H,65221,uint16)
```

Gear 0 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 0 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 1 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 1 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 2 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 2 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 3 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 3 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 4 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 4 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 5 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 5 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 6 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 6 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 7 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 7 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 8 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 8 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 9 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 9 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 10 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 10 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 11 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 11 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 12 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 12 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 13 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 13 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 14 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 14 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 15 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 15 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 16 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 16 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 17 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 17 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 18 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 18 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 19 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 19 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 20 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 20 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 21 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 21 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 22 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 22 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 23 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 23 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 24 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 24 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 25 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 25 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 26 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 26 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 27 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 27 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 28 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 28 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 29 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 29 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 30 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 30 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 31 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 31 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 32 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 32 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 33 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 33 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 34 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 34 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 35 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 35 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 36 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 36 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 37 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 37 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 38 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 38 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 39 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 39 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 40 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 40 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 41 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 41 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 42 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 42 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 43 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 43 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 44 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 44 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 45 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 45 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 46 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 46 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 47 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 47 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 48 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 48 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 49 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 49 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 50 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 50 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 51 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 51 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 52 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 52 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 53 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 53 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 54 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 54 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 55 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 55 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 56 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 56 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 57 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 57 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 58 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 58 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 59 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 59 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 60 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 60 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 61 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 61 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 62 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 62 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Gear 63 Ściemniacz Odczyt i zapis

Urządzenie sterujące DALI pod krótkim adresem 63 — ściemniacz TapHome zmapowany na DALI arc power 0–100 % przez H:510 LAMP LEVEL (zapis) i QUERY ACTUAL LEVEL przez H:511 (odczyt), ograniczony własnym MIN / MAX LEVEL gear-a.

Rejestr: H:511 → H:510 UInt16 Jednostka: % numeric

Atrybuty serwisowe

|                       |                                                                                                                                                                                   |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Krótki adres          | Krótki adres DALI (0–63) celowany przez to urządzenie — ustalony w czasie importu szablonu i używany w górnym bajcie każdego zapisu Modbus.                                       |
| Device Type           | Bajt device-type DALI zwrócony przez QUERY DEVICE TYPE (0x99) — zgłasza DT0 (fluorescencyjny), DT6 (sterownik LED), DT8 (kolor / tunable white) itp., lub -- gdy brak odpowiedzi. |
| Physical Min Level    | Wymuszony sprzętowo minimalny poziom ściemniania zgłaszany przez gear — czytany z QUERY PHYSICAL MIN LEVEL (0x9A), w procentach.                                                  |
| Max Level             | Skonfigurowany DALI MAX LEVEL — czytany z QUERY MAX LEVEL (0xA1); używany jako górna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Min Level             | Skonfigurowany DALI MIN LEVEL — czytany z QUERY MIN LEVEL (0xA2); używany jako dolna granica przy skalowaniu TapHome 0–100 % na DALI arc power.                                   |
| Power Up Level        | Jasność przywrócona po odzyskaniu zasilania magistrali DALI — czytana z QUERY POWER ON LEVEL (0xA3).                                                                              |
| System Failure Level  | Jasność przyjęta, gdy magistrala DALI traci komunikację na więcej niż 500 ms — czytana z QUERY SYSTEM FAILURE LEVEL (0xA4).                                                       |
| Grupy                 | Lista grup DALI (0–15) oddzielona przecinkami, do których należy gear — dekodowana z QUERY GROUPS 0-7 (0xC0) i QUERY GROUPS 8-15 (0xC1); pokazuje None lub np. 0,3,7.             |
| Support Lamp Failure  | Czy lampa / sterownik obsługuje wykrywanie awarii lampy — Yes / No / --. Bramkuje błąd Lamp failure! w okresowym readscript.                                                      |
| Support Power Failure | Czy lampa / sterownik obsługuje wykrywanie awarii zasilania — Yes / No / --. Bramkuje błąd Power failure! w okresowym readscript.                                                 |
| DALI Version          |                                                                                                                                                                                   |
| Bus statistics        |                                                                                                                                                                                   |

Akcje serwisowe

|                           |                                                                                                                                                                                                                        |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add to Group              | Dodaje ten gear do grupy DALI (0–15) przez ADD TO GROUP (0x60+grp) — auto-powtarzane w 100 ms, jak wymagają polecenia konfiguracyjne DALI.                                                                             |
| Remove from Group         | Usuwa ten gear z grupy DALI (0–15) przez REMOVE FROM GROUP (0x70+grp).                                                                                                                                                 |
| Reset to Default Settings | Wysyła DALI RESET (0x20) — przywraca każdy parametr NVM gear-a (poziomy max / min / power-on / system-failure, członkostwo w grupach, sceny) do fabrycznych domyślnych.                                                |
| Set Startup Levels        | Przechwytuje aktualne arc power i zapisuje je jako Power On Level i System Failure Level — sekwencja STORE ACTUAL LEVEL IN DTR (0x21) → STORE DTR AS POWER ON LEVEL (0x2C) → STORE DTR AS SYSTEM FAILURE LEVEL (0x2D). |
| Disable fading            |                                                                                                                                                                                                                        |

Odczyt (moduł)

```taphome
var x := 0; var rx := 0; var y := 0;
if Status > 0
    Status := Status - 1;
    adderror(3, "Gear not responding!");
    return(0);
end

# checkStatus: ReadLevel resets it while the gear answers; statusPoll: QUERY STATUS at least once per 60 runs
checkStatus := checkStatus - 1;
statusPoll := statusPoll - 1;
if checkStatus < 1 or statusPoll < 1
    # an unread answer left in the gateway would be taken for this query: read it away and count it
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    # a single lost answer happens on DALI: ask once more before declaring the gear missing
    if x = 0x8000
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    end
    if x <= 0xFF
        # a changed failure bit must be read twice the same before it is taken
        if statusSeen = 1 and getbits(x, 0, 2) != getbits(gearStatus, 0, 2)
            y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
            modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
            if y != x
                cntBad := cntBad + 1;
                x := gearStatus;
            end
        end
        if statusSeen = 0
            ignGear := getbit(x, 0);
            ignLamp := getbit(x, 1);
            statusSeen := 1;
        end
        # a bit that clears ends its ignore, so a later failure is raised
        if (getbit(x, 0) = 0, ignGear := 0);
        if (getbit(x, 1) = 0, ignLamp := 0);
        gearStatus := x;
        checkStatus := 60;
        statusPoll := 60;
    else
        if x = 0x8000
            Status := RANDINT(10, 60);
            adderror(3, "Gear not responding!");
            return(0);
        end
    end
end

# messages last one run only, so they are raised from the stored status on every run
if ((getbit(gearStatus, 0) = 1) and (ignGear = 0), adderror(1, "Control gear failure!"));
if ((getbit(gearStatus, 1) = 1) and (ignLamp = 0), adderror(2, "Lamp failure!"));
```

Inicjalizacja

```taphome
var x := 0; var rx := 0;
# QUERY STATUS 0x90: every reply byte proves the gear is present; 0x8000 = no answer, 0x20FF = bus collision
# an unread answer left in the gateway would be taken for this query: read it away and count it
x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
x := modbusr(SH, 511, uint16);
cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
statusSeen := 0;
if x <= 0xFF
    # failure bits a gear reports from its first answer are its permanent state, not an event: shown, not raised
    gearStatus := x;
    ignGear := getbit(x, 0);
    ignLamp := getbit(x, 1);
    statusSeen := 1;
    Status := 0;
else
    Status := RANDINT(1, 60);
end

if Status = 0
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, minLevel := x);

    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x <= 0xFE, maxLevel := x);
end
```

Odczyt poziomu

```taphome
var x := 0; var rx := 0; var y := 0;
if Status = 0
    if minLevel = 0
        # an unread answer left in the gateway would be taken for this query: read it away and count it
        x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        x := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
        if (x <= 0xFE, minLevel := x);
    end
    x := modbusr(SH, 511, uint16); if (x != 0x8000, cntStale := cntStale + 1);
    modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    cntQ := cntQ + 1; if (x = 0x8000, cntNone := cntNone + 1); if (x = 0x20FF, cntColl := cntColl + 1);
    if (x != 0x8000 or rx, checkStatus := 60);
    # 0xFF = MASK, 0x20FF = collision, 0x8000 = no answer: keep the last level instead of a phantom value
    if x > 0xFE
        return(Le);
    end
    # an actual level is 0 or between the gear's min and max: anything else is not this gear's answer
    if x > 0 and x < minLevel
        cntBad := cntBad + 1;
        return(Le);
    end
    # a changed level must be read twice the same before it is taken
    if x != lastRaw
        y := modbusr(SH, 511, uint16); if (y != 0x8000, cntStale := cntStale + 1);
        modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA0);
        sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        y := modbusr(SH, 511, uint16);
        cntQ := cntQ + 1; if (y = 0x8000, cntNone := cntNone + 1); if (y = 0x20FF, cntColl := cntColl + 1);
        if y != x
            cntBad := cntBad + 1;
            return(Le);
        end
        lastRaw := x;
    end
    return(if(x = 0, 0, linear(x, minLevel, 0.01, maxLevel, 1)));
else
    return(NaN);
end
```

Zapis poziomu

```taphome
var level := 0;
if(Le > 0, level := round(linear(Le, 0.01, minLevel, 1, maxLevel)));
modbusw(SH, 510, uint16, (ShortAddress << 8) + level );
```

Atrybuty serwisowe

${xml\_short\_address}

```taphome
ShortAddress
```

${xml\_device\_type}

```taphome
var x := 0; var y := 0; var rx := 0; var s := ""; var i := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x99);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    x := modbusr(SH, 511, uint16);
    if (x < 0xFF, return("DT" + x));
    if x = 0xFF
        while i < 8
            modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA7);
            sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
            y := modbusr(SH, 511, uint16);
            if y < 0xFE
                s := if(s = "", "DT" + y, s + ", DT" + y);
                i := i + 1;
            else
                i := 8;
            end
        loop
        return(if(s = "", "MASK", s));
    end
end

return("--")
```

Physical Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x9A);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Max Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA1);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Min Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA2);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

Power Up Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA3);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

System Failure Level

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA4);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if (x <= 0xFE, return(round((x / 0xFE) * 100) + " %"));
end

return("--")
```

${xml\_groups}

```taphome
var x := 0; var rx := 0;
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC0);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g1 := modbusr(SH, 511, uint16);
    if (g1 > 0xFF, return("--")); 

    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xC1);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var g2 := modbusr(SH, 511, uint16);
    if (g2 > 0xFF, return("--")); 

    var ret := "";

    if (getbit(g1, 0), ret := ret + "0");
    if (getbit(g1, 1), if (ret = "", ret := "1", ret := ret + ",1"));
    if (getbit(g1, 2), if (ret = "", ret := "2", ret := ret + ",2"));
    if (getbit(g1, 3), if (ret = "", ret := "3", ret := ret + ",3"));
    if (getbit(g1, 4), if (ret = "", ret := "4", ret := ret + ",4"));
    if (getbit(g1, 5), if (ret = "", ret := "5", ret := ret + ",5"));
    if (getbit(g1, 6), if (ret = "", ret := "6", ret := ret + ",6"));
    if (getbit(g1, 7), if (ret = "", ret := "7", ret := ret + ",7"));
    if (getbit(g2, 0), if (ret = "", ret := "8", ret := ret + ",8"));
    if (getbit(g2, 1), if (ret = "", ret := "9", ret := ret + ",9"));
    if (getbit(g2, 2), if (ret = "", ret := "10", ret := ret + ",10"));
    if (getbit(g2, 3), if (ret = "", ret := "11", ret := ret + ",11"));
    if (getbit(g2, 4), if (ret = "", ret := "12", ret := ret + ",12"));
    if (getbit(g2, 5), if (ret = "", ret := "13", ret := ret + ",13"));
    if (getbit(g2, 6), if (ret = "", ret := "14", ret := ret + ",14"));
    if (getbit(g2, 7), if (ret = "", ret := "15", ret := ret + ",15"));

    if (ret = "", return("None"), return(ret));
else
    return("--");
end
```

DALI Status

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x90);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var s := "";
        if (getbit(x, 0), s := if(s = "", "gear failure", s + ", gear failure"));
        if (getbit(x, 1), s := if(s = "", "lamp failure", s + ", lamp failure"));
        if (getbit(x, 2), s := if(s = "", "lamp on", s + ", lamp on"));
        if (getbit(x, 3), s := if(s = "", "limit error", s + ", limit error"));
        if (getbit(x, 4), s := if(s = "", "fade running", s + ", fade running"));
        if (getbit(x, 5), s := if(s = "", "reset state", s + ", reset state"));
        if (getbit(x, 6), s := if(s = "", "missing short address", s + ", missing short address"));
        if (getbit(x, 7), s := if(s = "", "power cycle", s + ", power cycle"));
        var ign := if((ignGear = 1) and (ignLamp = 1), "gear and lamp failure", if(ignGear = 1, "gear failure", if(ignLamp = 1, "lamp failure", "")));
        return(if(s = "", "OK", s) + " (0x" + tostring(x, "X2") + ")" + if(ign = "", "", "; not raised: " + ign + " reported since start"));
    end
end

return("--")
```

Fade

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA5);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        var t := getbits(x, 4, 4);
        var ret := if(t = 0, "off", t + " (" + round(sqrt(power(2, t)) * 5) / 10 + " s)");
        modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0xA8);
    sleep(5); rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
        var e := modbusr(SH, 511, uint16);
        if (t = 0 and e <= 0xFF and e != 0, ret := "extended 0x" + tostring(e, "X2"));
        return("fade time " + ret + ", fade rate " + getbits(x, 0, 4));
    end
end

return("--")
```

DALI Version

```taphome
if Status = 0
    modbusr(SH, 511, uint16); modbusw(SH, 511, uint16, (ShortAddress << 8) + 0x97);
    sleep(5); var rx := getbits(modbusr(SH, 550, uint16), 0, 2); if(rx, 0, sleep(50));
    var x := modbusr(SH, 511, uint16);
    if x <= 0xFF
        return(if(x >= 8, "DALI-2 " + getbits(x, 2, 6) + "." + getbits(x, 0, 2), "DALI-1") + " (" + x + ")");
    end
end

return("--")
```

Bus statistics

```taphome
return("since start: queries " + cntQ + ", stale answers read away " + cntStale + ", no answer " + cntNone + ", collisions " + cntColl + ", rejected levels " + cntBad)
```

Akcje serwisowe

${xml\_add\_to\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x60 + grp);
```

${xml\_remove\_from\_group}

Parametry: Group ID (0–15 grp)

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x70 + grp);
```

${xml\_reset\_to\_default\_settings}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x20);
```

${xml\_set\_startup\_levels}

```taphome
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x21);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2c);
sleep(10);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2d);
```

Disable fading

```taphome
modbusw(SH, 541, uint16, 0xA300);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x2E);
sleep(100);
modbusw(SH, 512, uint16, (ShortAddress << 8) + 0x30);
```

Group 0 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 0 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 0;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 0;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 0;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 1 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 1 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 1;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 1;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 1;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 2 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 2 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 2;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 2;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 2;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 3 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 3 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 3;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 3;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 3;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 4 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 4 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 4;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 4;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 4;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 5 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 5 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 5;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 5;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 5;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 6 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 6 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 6;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 6;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 6;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 7 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 7 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 7;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 7;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 7;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 8 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 8 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 8;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 8;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 8;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 9 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 9 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 9;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 9;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 9;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 10 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 10 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 10;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 10;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 10;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 11 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 11 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 11;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 11;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 11;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 12 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 12 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 12;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 12;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 12;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 13 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 13 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 13;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 13;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 13;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 14 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 14 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 14;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 14;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 14;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

Group 15 Ściemniacz Odczyt i zapis

Grupa broadcast DALI 15 (0–15) — ściemniacz TapHome tylko-do-zapisu, który broadcastuje pojedynczą wartość arc-power do każdego gear-a w tej grupie przez H:520 GROUP LEVEL. Magistrala nie odbija poziomów grup, więc TapHome przechowuje ostatnio zapisaną wartość.

UInt16 Jednostka: % numeric

Akcje serwisowe

|                             |                                                                                                                                                                |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add All Lamps to Group      | Broadcastuje ADD TO GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali dołącza do tej grupy niezależnie od swojego aktualnego krótkiego adresu. |
| Remove All Lamps from Group | Broadcastuje REMOVE FROM GROUP przez H:532 ALL COMMAND + REPEAT — każdy gear na magistrali opuszcza tę grupę.                                                  |

Zapis poziomu

```taphome
var GroupAddress := 15;
modbusw(SH, 520, uint16, (GroupAddress << 8) + (Le * 0xFE));
```

Akcje serwisowe

${xml\_add\_to\_group\_all\_lamps}

```taphome
var GroupAddress := 15;
modbusw(SH, 532, uint16, 0x60 + GroupAddress)
```

${xml\_remove\_from\_group\_all\_lamps}

```taphome
var GroupAddress := 15;
modbusw(SH, 532, uint16, 0x70 + GroupAddress)
```

**Połączenie:** Modbus RTU • 9600 baud• 8N1 • Slave ID: $\[SlaveId]

Możliwe ulepszenia (23)

- H:531 ALL COMMAND (broadcast DALI command) — Single-shot broadcast DALI command (no repeat). Template uses H:532 (ALL COMMAND + REPEAT) for group membership but never exposes plain ALL OFF / ALL ON / ALL ARC POWER as a service action — turn-on/off-all are not present (sibling daliconfig template has them via H:530)
- H:530 ALL LEVEL (broadcast arc power) — Sets brightness for every gear in one Modbus write. Convenient 'turn off all lamps' / 'turn on all lamps' shortcut — implemented in the sibling daliconfig template, missing in this operational template
- H:521 GROUP COMMAND (per-group DALI command) — Per-group DALI command (single-shot). Could expose group-level OFF / RECALL MIN / RECALL MAX / GO TO SCENE as service actions on each Group device, but template only writes H:520 GROUP LEVEL
- H:522 GROUP COMMAND + REPEAT — Per-group DALI configuration command (auto-repeated within 100 ms). Required for STORE DTR AS GROUP SCENE etc. — not exposed as a service action
- H:541 DIRECT 16-BIT FRAME — Raw DALI 1.0 frame send. Used by sibling daliconfig template for the DALI 2.0 random-addressing algorithm; not needed for runtime brightness control
- I:10020-I:10027 DALI 24-BIT FRAME — DALI 2.0 24-bit frames — required for DT8 colour control (XY, colour temperature, RGBW), DALI 2.0 control gear queries, and DALI-2 input devices (push-buttons, presence detectors). Template exposes only DALI 1.0 brightness layer per gear
- I:10030-I:10047 DALI 25-BIT eDALI FRAME — Lunatone-proprietary 25-bit eDALI frames (auto and user redundant-bit variants). Not used by any DALI 1.0 gear
- I:10050-I:10067 DALI 28-BIT / 32-BIT FRAME — Extended DALI 2.0 frames (memory bank access, DALI-2 application controllers). Template scope is single-channel arc power per gear
- H:500 (DSI VALUE) DSI 8-bit value send — Send a raw 8-bit DSI/DALI value with no addressing (bus-level diagnostics). Bypassed by every TapHome script
- C:0 / H:551 DALI Bus Error — 1 = DALI bus fault / short circuit / missing PSU. Useful diagnostic — could be added as a module-level service attribute. Currently bus errors only surface indirectly through 'Gear not responding!' errors emitted by per-gear readscripts
- H:100 DALI PRIORITY SLOT — 0..4 → 12-16 ms forward-frame timing. Default 2 (configuration). Bus-tuning parameter; template runs at default
- H:6000 DIP SWITCH / SOFTWARE RESET — Read returns the 4 DIP switch values; write 1 reboots the gateway. Sibling daliconfig template exposes Reset Gateway / Set Slave ID; this runtime template intentionally does not (commissioning concern)
- H:65222 / H:65224 / H:65225 BAUD\_RATE / PARITY / STOP\_BITS (FLASH) — FLASH-stored serial parameters. Template hard-codes 9600 8N1 in connection\_details, so these are out of scope
- I:0 / I:50-I:53 / scenes DALI 1.0 scenes (recall / store / query) — DALI 1.0 standard supports 16 stored scenes per gear/group recallable via GO TO SCENE (0x10..0x1F) and storable via STORE DTR AS SCENE (0x40..0x4F). Template exposes per-gear ADD/REMOVE FROM GROUP and RESET, but no scene recall/store/remove/query actions
- H:512 (RECALL MAX/MIN/GOTO LAST/UP/DOWN/STEP) DALI 1.0 high-level commands per gear — RECALL MAX LEVEL (0x05), RECALL MIN LEVEL (0x06), UP (0x01), DOWN (0x02), STEP UP (0x03), STEP DOWN (0x04), GO TO LAST ACTIVE LEVEL (0x0A) — useful as service actions for visual feedback / smooth dimming. Not exposed; brightness goes only through linear scaling
- H:512 (STORE DTR AS MAX/MIN/POWER ON/SYSTEM FAILURE LEVEL) Per-gear configuration write commands — STORE DTR AS MAX LEVEL (0x2A), STORE DTR AS MIN LEVEL (0x2B), STORE DTR AS POWER ON LEVEL (0x2C), STORE DTR AS SYSTEM FAILURE LEVEL (0x2D), STORE DTR AS FADE TIME / FADE RATE — template has 'Set Startup Levels' (combines 0x21, 0x2C, 0x2D) but does NOT expose individual writes for max/min/fade-time/fade-rate
- H:511 (QUERY FADE TIME / FADE RATE / RANDOM ADDRESS / EXT VERSION) Additional DALI queries — QUERY FADE TIME / FADE RATE (0xA5), QUERY VERSION NUMBER (0x97), QUERY RANDOM ADDRESS H/M/L (0x98/0xC2/0xC3), QUERY CONTENT DTR/DTR1/DTR2 — not exposed in service attributes, only the 10 attributes listed per gear are populated
- H:511 (QUERY CONTROL GEAR / RESET STATE / LIMIT ERROR / LAMP POWER ON / MISSING SHORT ADDRESS) DALI gear health / topology queries — QUERY CONTROL GEAR (0x90), QUERY RESET STATE (0x95), QUERY LIMIT ERROR (0x94), QUERY LAMP POWER ON (0x93), QUERY MISSING SHORT ADDRESS (0x96, broadcast) — diagnostic queries. Could be useful as module-level diagnostics; template exposes only QUERY STATUS / LAMP FAILURE / POWER FAILURE / DEVICE TYPE / MIN-MAX-PHYSICAL MIN-POWER UP-SYSTEM FAILURE LEVEL / GROUPS
- H:511 (READ MEMORY LOCATION 0xC5) DALI memory bank read — READ MEMORY LOCATION (0xC5) is required to read DALI 2.0 memory banks (Bank 0 device GTIN, FW version, serial number; Bank 1 for emergency lighting). Not used
- ASCII protocol commands Parallel ASCII text protocol — RESI gateway also exposes a CR-terminated text protocol (#LARC, #GARC, #AARC, #LGS, #LCMD, #LCMDA, #DALI CMDxx etc.). Template uses Modbus exclusively — ASCII would only matter for diagnostics/terminal access
- DT6 fade time / fade rate / DAPC sequence Smooth dimming primitives — DAPC (Direct Arc Power Control) sequence allows fast continuous level updates for smooth dimming. Each gear has stored fade time / fade rate that affect transitions. Template writes raw arc power without configuring fade behaviour
- DT8 colour control (XY, colour temperature, RGBW) DALI DT8 tunable white / RGB / RGBW — DT8 colour control gears (tunable white CCT, XY colour, RGBW) require DALI 2.0 24-bit frames sent via H:541 / I:10020. Template exposes plain ModbusDimmer per gear — for DT8 lamps use a dedicated DT8 template
- DT1 emergency lighting DALI DT1 self-contained emergency lights — Emergency-luminaire device type with periodic self-tests (function/duration test) and battery state queries. Out of scope — template is general-purpose dimming

## Parametry importu

Te wartości podajesz podczas importu pliku XML.

| Pytanie w aplikacji | Domyślnie     |
|---------------------|---------------|
| Slave ID            | `255`         |
| Adres IP            | `192.168.1.0` |

## Źródła

- RESI-DALI-SIO/ETH Modbus & ASCII protocol reference
  
  [www.resi.cc](https://www.resi.cc/resi/docs/RESI-L-DALI-SIO,ETH-MODBUS+ASCII-EN.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/resi-dali-dali/manufacturer/RESI-L-DALI-SIO,ETH-MODBUS+ASCII-EN.pdf)
- RESI-xxx-SIO, RESI-xxx-ETH hardware & software manual (DALI chapter)
  
  [www.resi.cc](https://www.resi.cc/resi/docs/RESI-M-xxx-SIO-ETH-EN.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/resi-dali-dali/manufacturer/RESI-M-xxx-SIO-ETH-EN.pdf)
- RESI-DALI-SIO datasheet (GW-28)
  
  [www.resi.cc](https://www.resi.cc/resi/catalog/files/RESI-CATALOG-GATEWAYS-EN-Pages/RESI-CATALOG-GATEWAYS-EN-GW-28-RESI-DALI-SIO.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/resi-dali-dali/manufacturer/RESI-CATALOG-GATEWAYS-EN-GW-28-RESI-DALI-SIO.pdf)
- RESI-DALI-ETH datasheet (GW-29)
  
  [www.resi.cc](https://www.resi.cc/resi/catalog/files/RESI-CATALOG-GATEWAYS-EN-Pages/RESI-CATALOG-GATEWAYS-EN-GW-29-RESI-DALI-ETH.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/resi-dali-dali/manufacturer/RESI-CATALOG-GATEWAYS-EN-GW-29-RESI-DALI-ETH.pdf)
- RESI-DALI-PS datasheet (GW-30)
  
  [www.resi.cc](https://www.resi.cc/resi/catalog/files/RESI-CATALOG-GATEWAYS-EN-Pages/RESI-CATALOG-GATEWAYS-EN-GW-30-RESI-DALI-PS.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/resi-dali-dali/manufacturer/RESI-CATALOG-GATEWAYS-EN-GW-30-RESI-DALI-PS.pdf)
- RESI-DALI-SIO,ETH,PS product page
  
  [www.resi.cc](https://www.resi.cc/prestashop/en/home/1-resi-dali-sioethps.html) 2026-04-25

Dokumenty producentów są © ich właścicieli. Udostępniamy je w formie opublikowanej przez producenta, wyłącznie w celach informacyjnych.

## Powiązana dokumentacja

- [Modbus Integration](https://taphome.com/pl/compatibility/modbus-guide/)
- [Modbus](https://taphome.com/pl/docs/integration/modbus/)
- [Prosta konfiguracja za pomocą szablonów](https://taphome.com/pl/docs/integration/modbus/templates/)
- [Skrypty Modbus i prefetch](https://taphome.com/pl/docs/script/modbus-scripts/)
- [Funkcje Modbus](https://taphome.com/pl/docs/script/modbus/)
- [Typy danych Modbus](https://taphome.com/pl/docs/script/modbus-data-types/)

## Rozwiązywanie problemów

Częste problemy związane z tym tematem:

- [Światła DALI włączają się same](https://taphome.com/pl/troubleshooting/wiring/dali-lights-switch-on-by-themselves/) — Światła DALI za bramką DALI bez żadnego polecenia włączają się na minimum lub zmieniają jasność, zwykle za każdym razem te same kilka świateł. Magistrala jest na chwilę zakłócana — przez bramkę, zwarcie na jednej gałęzi lub spadek napięcia.

[Zobacz wszystkie artykuły rozwiązywania problemów](https://taphome.com/pl/troubleshooting/)

