Skip to main content

aiodynet

An asyncio client for the Signify Dynalite DyNet lighting control bus, through a DyNet TCP gateway (for example a PDEG).

aiodynet only reads and writes the bus. It has no idea what your site looks like: there are no devices, rooms, names or templates here, only the areas, channels, presets and levels that travel on the wire. That makes it a small, predictable base for higher-level code such as the Home Assistant dynalite integration.

  • Typed, immutable messages that validate themselves, so an out-of-range value fails where you wrote it, not on the bus
  • One connection object with a clear lifecycle: connect, reconnect on its own, close cleanly
  • Writes are paced, because gateways drop packets that arrive too quickly
  • No dependencies outside the standard library. Fully typed (py.typed) and checked with mypy --strict
  • A fake gateway in aiodynet.testing for testing your own code without hardware

Requires Python 3.13 or newer.

Quick start

import asyncio

from aiodynet import DynetClient, Level, PresetSelect, Received, SetChannelLevel


def show(received: Received) -> None:
    print(received.raw.hex(), received.message)


async def main() -> None:
    async with DynetClient("192.0.2.10", 50000) as client:
        client.subscribe(show)

        # Recall preset 1 in area 12 over two seconds
        await client.send(PresetSelect(area=12, preset=1, fade=2))

        # Fade channel 3 of area 12 to 40 %
        await client.send(
            SetChannelLevel(area=12, channel=3, level=Level.from_percent(40), fade=1)
        )

        await asyncio.sleep(60)  # watch the bus for a minute


asyncio.run(main())

Concepts

Packets

A Packet is one 8-byte DyNet 1 frame. You rarely build one by hand, but it is always available: every received message comes with the exact packet, and send accepts packets as well as messages.

from aiodynet import Packet

Packet.from_hex("1c 0c 64 00 00 00 ff")  # checksum added for you
Packet.from_hex("1c0c64000000ff75")  # checksum checked
Packet.from_bytes(raw_8_bytes)  # raises InvalidPacketError if bad

DyNet 2 frames

Gateways also send variable-length DyNet 2 frames on the same TCP stream: a greeting after every new connection, and device sign-on replies. Each starts with 0xAC, is (byte 1 + 1) * 4 bytes long and ends in a two-byte Fletcher-16 checksum (taken mod 256). A Dynet2Frame holds one raw:

from aiodynet import Dynet2Frame

frame = Dynet2Frame.from_hex("ac 02 80 da 00 01 b3 00 2a 0a")  # checksum added
frame.body  # the bytes between the length byte and the checksum

Frames are handled like packets everywhere. PacketFramer.feed yields both in the order they arrived, DynetClient.subscribe callbacks get both, and decode takes either. A frame decodes to a Dynet2Message:

Message Frame Meaning
Dynet2SignonReply reply (0x81), type 0x01 A device's address, firmware version and maximum packet sizes, in answer to RequestSignon. A 44-byte form also carries an IPv6 address
Dynet2RequestSerialNumber request (0x80), type 0x0A Ask a device for its serial number. System Builder sends these
Dynet2SerialNumberReply reply (0x81), type 0x0A A device's serial number
UnknownDynet2Message anything else Passed through unchanged, frame included

send takes DyNet 2 messages and raw Dynet2Frames as well. A real gateway passes a frame from one client on to its other clients, and answers some itself: it replies to its own "Request Who are you" (type 0x0C), for example. Whether it also puts client frames on the RS-485 bus hasn't been checked.

await client.send(
    Dynet2Frame.from_hex("ac 04 82 dc 00 5a aa 55 55 00 0c 00 00 00 00 00 00 00")
)

To find out what a device is, ask it to sign on:

reply = await client.query(RequestSignon(device_code=0xB3, box=42))
print(f"v{reply.firmware_version}, packets up to {reply.max_rx_size} bytes")

Messages

Each message class maps to exactly one wire form. Fields are keyword-only and checked when the object is built. Channels and presets are numbered from 1, as in the DyNet tools and on keypads.

Message Opcode(s) Meaning
PresetSelect 0x00–0x03, 0x0A–0x0D Select preset 1–2048 in an area, with a fade of up to 1310.7 s
LinearPresetSelect 0x65 Select preset 1–256 using the one-byte form some controllers send
PresetReport 0x62 An area reports its current preset
RequestPreset 0x63 Ask an area for its current preset
SetChannelLevel 0x80–0x83 Fade one channel (1–1024) to a level, with a fade of up to 5.1 s
ChannelLevelReport 0x60 A channel reports its target and actual level
RequestChannelLevel 0x61 Ask a channel for its level
FadeChannelToPreset 0x6B Fade one channel, or every channel, to a preset's level
AreaCommand 0x05, 0x06, 0x08, 0x15, 0x16, 0x66 Area commands with no data: step the area level down or up, program the current preset, disable or enable panels, save the current preset (AreaCommandType)
AreaOff, ResetPreset, Panic, Unpanic 0x04, 0x0F, 0x17, 0x18 Area commands with a preset-style fade
AreaToLevel 0x79 Fade every channel in an area to one level
ChannelOff, ChannelOn 0x74, 0x75 Fade a channel, or every channel, to off or full
StopFade 0x76 Stop a channel, or every channel, mid-fade
FadeChannelToLevel 0x71–0x73 The newer channel-level opcodes; scale names which one
RestoreSavedPreset 0x67 Return to the preset saved with SAVE_CURRENT_PRESET
ProgramLevelsToPreset 0x09 Store an area's current levels as a given preset (overwrites it)
MotionActivitySync 0x2E A motion sensor sharing its activity timer
AreaCascadingSync 0x2F An area's cascading timer keeping linked areas in step
HoldTimerAllPresets 0x30 Suspend or resume the hold timer for every preset (state kept raw)
OccupancyDetectionAllPresets 0x31 Suspend or resume occupancy detection for every preset
SuspendOccupancyDetection, ResumeOccupancyDetection 0x3A, 0x3B The same for the current preset only
SetUserPreference, RequestUserPreference, UserPreferenceReport 0x48–0x4A Device-specific 16-bit preference values. For preference 0x0C, UserPreferenceReport.temperature gives °C
RequestPresetLevel, PresetLevelReport 0x91, 0x92 The level a channel has stored for a preset
DeviceIdentify physical 0x00 A device saying what it is, with its firmware version
DeviceStatusReport physical 0x41 A device status report; the data bytes are kept raw
ClockTime, ClockDate physical 0x50, 0x53 A device setting or broadcasting the time and date
RequestFirmwareVersion physical 0x80 Ask a device for its firmware version. It answers with a DeviceIdentify
RequestSignon physical 0x40, sub-opcode 0x0A Ask a device to sign on. It answers with a DyNet 2 Dynet2SignonReply
UnknownMessage anything else Passed through unchanged, packet included

Where an opcode can address one channel or the whole area, channel=None means every channel. Fields whose unit the opcode list doesn't pin down are kept raw and named *_raw (for example fade_raw, time_raw), rather than guessed. Area links (0x20–0x23) are left undecoded because the opcode list doesn't say which bit is which area.

PresetSelect, LinearPresetSelect and PresetReport share the base class AreaPresetMessage, so isinstance(message, AreaPresetMessage) catches "this area is now at preset N" however it was sent.

decode(packet) returns the union type AnyMessage, so a match statement ending in assert_never is checked for exhaustiveness by mypy.

Levels

DyNet levels run backwards on the wire (0x01 is 100 %, 0xFF is off). Level keeps the raw byte, so it always round-trips, and converts for you:

Level.from_percent(40)
Level.from_fraction(0.4)
Level(0x80)  # the raw byte
Level.OFF, Level.FULL
level.percent, level.fraction, level.is_off

Messages accept only Level, never a bare number, so a percentage can't be sent as a raw byte by mistake.

Fades

Fades are seconds as float, rounded to the nearest 20 ms step. A fade that a message can't carry raises ValueError rather than being wrapped or clamped: SetChannelLevel holds up to MAX_CHANNEL_FADE (5.1 s) and preset messages up to MAX_PRESET_FADE (1310.7 s).

The client

client = DynetClient(host, port)
await client.connect()  # raises DynetConnectionError if unreachable
...
await client.close()  # always safe, any number of times

or async with DynetClient(host, port) as client:.

  • Connecting. connect makes one attempt and raises if it fails, which suits "not ready yet, try later" handling. After a successful connect the client reconnects on its own after any drop, waiting 1 s at first and up to 60 s between attempts, until you call close.
  • Receiving. subscribe(callback) calls callback(received) in the event loop for every packet and DyNet 2 frame, where received.raw is the Packet or Dynet2Frame as received and received.message its decoded meaning. It returns an unsubscribe function. A callback that raises is logged and doesn't affect the others.
  • Noise. subscribe_noise(callback) calls callback(data) with each run of bytes that wasn't part of any packet or frame, in stream order, including a partial packet cut off by a dropped connection. It's for tools that keep a full record of the stream.
  • Connection changes. subscribe_connection(callback) reports drops (False) and reconnects (True). client.connected gives the current state.
  • Sending. await send(message_or_packet) returns once the packet has been written. Packets and DyNet 2 frames go out one at a time, 0.2 s apart by default (send_interval). If the client isn't connected, or the connection drops before the packet is written, send raises NotConnectedError. Nothing is kept to send later, so a command can't fire long after it was asked for.
  • Queries. await query(RequestPreset(area=12)) sends the request and returns the matching PresetReport, or raises TimeoutError. Likewise a RequestChannelLevel returns a ChannelLevelReport, and a RequestSignon to one device returns its Dynet2SignonReply.
  • Closing. close cancels everything the client started and closes the socket. No callbacks run after it begins.
  • Dead gateways. TCP keepalive is enabled (30 s idle, then 3 probes 10 s apart where the OS supports it), so a gateway that vanishes on a quiet bus is still noticed.

check_connection(host, port) opens and closes a TCP connection without sending anything. It's meant for validating a host and port in a setup flow.

Testing your code

aiodynet.testing.FakeGateway is a real TCP server on localhost that records what clients send and sends whatever you tell it to:

from aiodynet import DynetClient, PresetReport, RequestPreset
from aiodynet.testing import FakeGateway


def site(packet):
    if packet == RequestPreset(area=1).to_packet():
        return [PresetReport(area=1, preset=4)]
    return []


async def test_area_one_is_off():
    async with FakeGateway(replies=site) as gateway:
        async with DynetClient(gateway.host, gateway.port) as client:
            report = await client.query(RequestPreset(area=1))
    assert report.preset == 4

How well each claim is verified

DyNet documentation is thin, so this is the evidence for each encoding:

Encoding Source
Packet layout, checksum DyNet 1 opcode list; every packet in the test fixtures
PresetSelect (banks, fade in 20 ms steps, low byte then high byte) Opcode list, plus byte-for-byte match with the packets dynalite-devices 0.1.47 sends
SetChannelLevel (bank byte offset by one, fade in 20 ms steps) Byte-for-byte match with dynalite-devices 0.1.47
RequestPreset, RequestChannelLevel Byte-for-byte match with dynalite-devices 0.1.47
PresetReport, LinearPresetSelect, ChannelLevelReport, FadeChannelToPreset Opcode list, plus the meaning dynalite-devices 0.1.47 takes from them. Not yet checked against captured traffic
FadeChannelToPreset fade unit Unknown, so it's kept as a raw byte
MotionActivitySync, UserPreferenceReport, ClockTime, ClockDate Opcode list, plus packets captured on a real site (tests/fixtures/site-capture.jsonl). The clock bytes are BCD, and the date packs the day of the week into the top three bits of the month byte; both inferred from that capture
All other extended messages Byte layout from the opcode list only
AreaCascadingSync, OccupancyDetectionAllPresets (0x01 = resume), DeviceIdentify (version as hex digits), DeviceStatusReport, UserPreferenceReport.temperature (whole degrees + hundredths) Opcode list, plus real packets decoded by the official DyNet network monitor. Negative temperatures haven't been seen, so they come back as None
HoldTimerAllPresets, SuspendOccupancyDetection, ResumeOccupancyDetection, ProgramLevelsToPreset Opcode list only
RequestFirmwareVersion Opcode list, plus requests sent to 45 devices at one site. Each answered with a DeviceIdentify from its own address, with the version the site's System Builder job records
Dynet2SignonReply One frame from a real D5Sen, decoded field by field by the official DyNet network monitor. Telling a sign-on apart from other 0x81 replies by byte 9 = 0x01 rests on that frame plus one non-sign-on reply. At one site the request got no replies when sent to all devices, only when addressed to a single device. The 44-byte form comes from one frame, sent by a DALI controller that is also an Ethernet bridge: its 16 extra address bytes were that device's IPv6 address. Its source was the all-devices address, so query can't match it to the request
Dynet2RequestSerialNumber, Dynet2SerialNumberReply Requests from System Builder and the replies to them, captured at one site. The serial numbers in 44 replies were checked against that site's System Builder job: 42 matched, and the other two devices had been replaced since the job was last updated. Byte 10 of the reply and its three trailing zero bytes are kept raw
DyNet 2 framing: 0xAC, length, Fletcher-16 mod 256 trailer Three frames captured from a real gateway; all three verify and end exactly where the next DyNet 1 packet starts. Recheck the checksum on any new kind of frame

The dynalite-devices comparison was made black-box: by driving its public API against a fake gateway and recording the bytes, without reading its source. Those vectors are in tests/test_messages.py.

Porting from dynalite-devices

aiodynet replaces the bus layer of dynalite-devices. The mapping of areas and channels to entities, and naming, stay in the integration. To keep existing installs behaving the same:

  • Brightness. dynalite-devices sends HA brightness b (0–255) as the raw level max(1, 255 - b), and reads it back as 255 - raw. Use Level(max(1, 255 - b)) and 255 - level.raw, not from_fraction, to keep the same bytes.
  • Channel fades longer than 5.1 s were clamped to 5.1 s. aiodynet raises instead, so clamp with min(fade, MAX_CHANNEL_FADE) first.
  • Preset fades longer than 1310.7 s crashed dynalite-devices while it built the packet. aiodynet raises a clear ValueError at the call.
  • Pacing. dynalite-devices spaced writes 0.2 s apart. That's the default here too.
  • Queued writes. dynalite-devices queued writes while disconnected. aiodynet raises NotConnectedError instead. Decide in the integration whether to surface it or retry.

Development

uv sync
uv run pytest --cov      # 100 % branch coverage is enforced
uv run ruff check && uv run ruff format --check
uv run mypy

To cut a release, see RELEASING.md.

Licence

MIT. Not affiliated with or endorsed by Signify.

Metadata

Release files for aiodynet 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiodynet 0.3.0
File Size Uploaded Provenance Actions
aiodynet-0.3.0.tar.gz 56.4 kB Without provenance Details for aiodynet-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiodynet 0.3.0
File Interpreter ABI Platform Actions
aiodynet-0.3.0-py3-none-any.whl Python 3 none any Details for aiodynet-0.3.0-py3-none-any.whl

Total release size: 96.3 kB

Release files / aiodynet-0.3.0.tar.gz

Download URL aiodynet-0.3.0.tar.gz
Size 56.4 kB
Tags Source
SHA-256 checksum
How to use checksums
20ebf1f1b34cab770da187278a65c06e8bd0671d48d44943ffc6cbacb17725e5
BLAKE2b-256 checksum
How to use checksums
d797ef24f0bcd5b881f37fc6f3a57e4b959f91f1b5822eb24daf889b4f09fee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aiodynet-0.3.0-py3-none-any.whl

Download URL aiodynet-0.3.0-py3-none-any.whl
Size 39.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
805d05d8c94d27c21a31a02797926274bc3be94aa357d41cc4d1a9a7307c5e05
BLAKE2b-256 checksum
How to use checksums
80dd7ccbe4192a058fc0269482fd997ee2ee69bd91c9c4cf51d49b1efb386021
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for aiodynet 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page