Metadata-Version: 2.5
Name: dynalite-eeprom
Version: 0.3.0
Summary: Unofficial decoder for the memory of Signify Dynalite DyNet devices: panel buttons, channels, sensors and tasks
Project-URL: Homepage, https://github.com/sdunster/dynalite-eeprom
Project-URL: Issues, https://github.com/sdunster/dynalite-eeprom/issues
Author-email: Sam Dunster <me@sdunster.com>
License-Expression: MIT
License-File: LICENSE
Keywords: dynalite,dynet,eeprom,lighting,signify
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.13
Requires-Dist: pyyaml>=6.0
Description-Content-Type: text/markdown

# dynalite-eeprom

Decode memory dumps of Signify Dynalite DyNet devices: what each panel button
does, which areas relay channels and sensors act on, button labels, device
names, and tasks.

An unofficial tool, not affiliated with or endorsed by Signify.

It reads and writes files only, and never talks to a bus. Make the dumps with
[dynet-cli](https://github.com/sdunster/dynet-cli)'s `dynet dump -o`, which
reads a device's whole EEPROM over the gateway.

The layout was worked out from one site's devices, matched against System
Builder's export of the same site. Every decoded field matched that export
(168 panel buttons, 36 relay channels, 12 sensors), but other models and
firmware may differ. Anything not decoded is left out or kept as raw bytes,
never guessed.

## Install

```console
$ pipx install dynalite-eeprom      # or: uv tool install dynalite-eeprom
```

It needs Python 3.13 or later. To read and write devices, also install
[dynet-cli](https://github.com/sdunster/dynet-cli) (`dynet dump`,
`dynet write`).

## Use

```console
$ dynet dump 0xfd:51 -o rumpus.bin
$ dynalite-eeprom rumpus.bin
device 0xfd box 51 'Rumpus': model 864, firmware 3.23, PCB 2.3, 64 KiB read
programmed: no stamp
button 1 (Medium):
  on press:
    0x21b6  recall preset 2 on area 8 all channels, fade 1 s, join 0xff
    0x21c2  end
button 3 (Curtains):
  on press:
    0x21d0  if [40 1a 10 55] goto 0x21e5
    0x21d8  recall preset 1 on area 144 all channels, fade 0 s, join 0xff
    0x21e4  end
    0x21e5  recall preset 4 on area 144 all channels, fade 0 s, join 0xff
    0x21f1  end
…
```

`--json` prints the same as JSON, with raw bytes as hex. Several files can be
given at once.

From Python:

```python
from dynalite_eeprom import Image, Panel, decode, describe

memory = decode(Image.from_file("rumpus.bin"))
if isinstance(memory, Panel):
    for button in memory.buttons:
        for event in button.events:
            for instruction in event.program:
                print(button.number, event.name, describe(instruction, memory.channels))
```

## Configuration as YAML

`export` writes everything the decoder understands about a device as a YAML
document. Edit it, then `compile` it against the dump it came from to get the
new memory image and the bytes that changed:

```console
$ dynalite-eeprom export hall.bin -o hall.yaml
$ $EDITOR hall.yaml                      # motion_led: false
$ dynalite-eeprom compile hall.yaml --base hall.bin -o hall-new.bin
0x001a: 00 03 95 f5 cf
0x0223: f8
```

The document shows the whole device, but only some settings can be written
so far (the comment at its top lists them; see Editing below). Compiling
checks itself: it exports the new image again and refuses unless that gives
back your document, naming each setting it can't write yet:

```console
$ dynalite-eeprom compile hall.yaml --base hall.bin -o hall-new.bin
dynalite-eeprom: can't write these (yet): name, sensor.presets[2].on_motion[0]
```

When anything changes, compiling sets the programming stamp to now, as System
Builder does on each write (`--keep-stamp` leaves it).

### Programs and button functions

Programs (button events, tasks, sensor actions) are written in System
Builder's task syntax where it has one, with labels for branch targets:

```yaml
events:
  hold:
  - LDA ^26[LC14]  // area 2
  - BNE L1
  - RampToLevel(LC=14, L=100%, T=5)  // area 2
  - Null
  - 'L1: LDA ^42[LC14]  // area 2'
  ...
tasks:
- number: 1
  program:
  - Preset(A=19, P=3, F=1.5)
  - Delay(2.5)
  - 'Null'
```

The text is lossless: `dynalite_eeprom.syntax.assemble` turns it back into
exactly the bytes it came from. Instructions that act on the panel's own
logical channels have no text form in System Builder, so they're this
package's own: `RecallPreset(LC=…)`, `RampToLevel`, `StopFade`,
`PresetToArea(A=…)` (System Builder's "Preset To Area" action), and port
reads such as `LDA ^26[LC14]`. Bytes the disassembler doesn't know are kept
as `Raw(…)`.

A button set up with one of System Builder's button functions is shown as
that function instead of its programs:

```yaml
function: {name: TogglePreset, area: 144, on_preset: 1, off_preset: 4, fade: 0, lc: 16}
```

Known functions: `RecallUserPreset`, `TogglePreset`, `OneTouchRampOnly` and
`LocalTaskControl`. A function is only shown when expanding it gives back
exactly the button's programs. At the test site that's every button System
Builder's export gives one of these functions (154 buttons), with the
export's settings.

Panel buttons are writable: give each a `function`, or `events` with a
program per event (press, short press, hold, release), and set `flags`.
Compiling lays the programs out the way System Builder does (see
`dynalite_eeprom.link`): back to back after the button table, in button and
event order, with the pointers and section sizes rewritten, and the section
padded to 16 bytes. Unchanged buttons give back the identical bytes (every
panel at the test site), so a write changes only what differs, plus any
programs that move. A program that branches to a fixed address instead of a
label, or holds `Raw(…)` bytes, can't be moved.

A button's target is writable: the `area` (and `channel`, if not all
channels) in its `function`, or at the button's own level for a button with
programs (which reach it as `LC<n>`). Each button has its own channel
record, and System Builder keeps a second copy of it (button n uses records
13 + n and 109 + n on every panel at the test site); compiling writes both,
and refuses on a panel where they don't pair. `channels` doesn't list those
records, since the buttons show them.

Indicators follow the buttons. When a button's `function` changes (or a
button with programs is given one), compiling gives its indicator what
System Builder gives that function: the mode (0x30 recall preset, 0x70
toggle, 0x4f one-touch ramp, 0xff task) and the preset it follows (the
preset, or the off preset for a toggle or ramp). Every function button at
the test site matches, apart from an option byte on two toggles. A button
given `events` keeps its indicator. A toggle or ramp also gets its off
preset in both of its channel records (byte 13), as System Builder writes
it: the panel uses it to know the area is off, and without it a toggle
only ever sends the off preset. An indicator's `mode` and `preset` can
also be edited in `panel.indicators`, and an edit there wins.

Panel tasks are writable too: `panel.tasks` lists each task's number (1-64)
and program, and unlisted tasks are left empty. They're laid out as System
Builder does: the startup program, then tasks 1-64 back to back, with the
64-entry table it creates the first time a panel gets a task.

Names are writable too: the device's `name`, each button's `label` and each
task's `name`. `text` holds the device's other `key=value` strings (such as
relay controllers' area names), which can be changed, added or removed.
`null` leaves a name as it is; `""` empties it. The strings are stored
sorted, as System Builder does, and anything after them in the text section
moves along unchanged. A gateway's text is never rewritten: its section
holds more than names.

Relay controllers' outputs are writable: each output's `area` and logical
`channel`, written in place in its channel record (the record's other
bytes, such as System Builder's "duplicate" flag, stay as they are). Area
names are the `A<area>` keys in `text`. Listeners and sensor programs are
still read-only. Like the
dumps, the documents describe a real site: keep them out of public places.

## Editing

`encode` writes edited fields back into the image they were decoded from,
and `changes` lists the byte ranges that differ, which is all a write to the
device needs to send:

```python
from dynalite_eeprom import Image, Sensor, changes, decode, encode

image = Image.from_file("hall.bin")
memory = decode(image)
assert isinstance(memory, Sensor)
memory.motion_led = False
for change in changes(image, encode(memory, image)):
    print(f"0x{change.address:04x}: {change.data.hex(' ')}")  # 0x0223: f8
```

Nothing is rebuilt from scratch: bytes the decoder doesn't understand stay
as read. `encode` decodes its result and raises `EncodeError` unless that
gives back exactly the edited memory, so an edit to a field it can't write
yet is refused rather than lost. Writable so far: the programming stamp on
every device; relay controller outputs' area and logical channel; panel
buttons (through the YAML configuration); panel indicators' mode, option
byte and preset; and on sensors
the motion LED, the no-motion timeouts (global and per preset), the action
delay, the resend inhibit period, and the light detector's settings and band
limits. Unchanged memory encodes to the
identical bytes for every device at the test site.

This package doesn't write to devices. Check the result before sending it,
and keep the dump it came from so the device can be restored.

## What it decodes

| Device | Decoded |
|---|---|
| All but the DALI controller | Header (device code, box, firmware, model ID, PCB version), the time System Builder last wrote it, the section directory, name and other `key=value` text |
| Antumbra panels (0xfd) | Each button's programs per event, with logical channels resolved to areas; button labels; indicator mode and preset; local tasks |
| Relay controllers (0x4c) | Each output's area and logical channel, with area names |
| Sensors (0xb3) | Motion area, no-motion timeout, motion LED, light detector band count |
| PDEG gateways (0xdc) | Tasks, with their names |
| DALI controllers (0x64), others | Header only: their layout is different |

Button programs are a small bytecode: recall preset, ramp to level, stop
fade, conditional jump, run local task and send packet. Conditions aren't
decoded yet, and are shown as raw bytes. The four event slots are labelled
press, short press, hold and release; that's inferred from which buttons use
them, and not confirmed.

## The memory layout

Panels, sensors, relay controllers and PDEGs share one container format:

- **Header:** a 10-byte header at 0x00.
- **Programming stamp:** at 0x1A, `00` then seconds since 2025-01-01 UTC.
- **Section directory:** 24 16-bit pointers at 0x20.
- **Sections:** each starts with a type byte and its own 16-bit size.

The workspace notes this was written from (`EEPROM-FINDINGS.md`) cover the
details, the evidence and what's still unknown.

## Credentials

A PDEG's text section also holds XML and strings that look like keys or
credentials. dynalite-eeprom only decodes the first text sub-section, which
holds the `key=value` strings. For the others it shows the address and size,
never their contents. Treat the dump files themselves as sensitive.

## Development

```sh
uv sync
uv run pytest --cov
uv run ruff check && uv run ruff format --check && uv run mypy
```

The tests build synthetic memory images (`tests/builder.py`), so no real
site's data is in the repository. To check against real dumps, point
`DYNALITE_EEPROM_SITE` at a folder with the `*.bin` files (named like
`fd-023-pantry.bin`) and System Builder's `*Devices.xml` export:

```sh
DYNALITE_EEPROM_SITE=~/site uv run pytest tests/test_site.py
```

## Licence

MIT
