sde1000 / python-dali

Library for controlling DALI lighting systems
Other
150 stars 71 forks source link

tridonic: support sending 8-bit backward frames #127

Closed jktjkt closed 1 year ago

jktjkt commented 1 year ago

I have no idea if this actually reaches the physical DALI bus, but I've checked that the bus watcher picks up the traffic. So, this can be already used to persuade some real code that's connected to the real DALI bus that a sensor "sent us something".

I have some internal code that switches my DALI lights on and off based on a DALI movement sensor. With this patch in place, I can simulate this movement, and my light went on, as if someone really walked in our hallway:

from dali.device.occupancy import OccupancyEvent
x = OccupancyEvent(short_address=45, instance_number=0,
  data=OccupancyEvent.EventData(movement=True, occupied=True))
await dev.send(x)

Caveat: the usual bits about addressing of event messages apply (I tried to write this up at electronics stackexchange). In this library it's done via DeviceInstanceTypeMapper, so in this example code it was important to ensure that there's really a physical control device on the bus at address A² = 45 which really has an instance no. = 0 which reports that it implements part 303, occupancy sensor. The other way would be faking that, of course. The root cause is that these 8-bit frames are too short to encode all the event info, and something has to perform this discovery up front, or has the knowledge of "hey, A² X, instance Y is a movement sensor" that's provided out-of-band.

Bug: https://github.com/sde1000/python-dali/discussions/126

jktjkt commented 1 year ago

I can confirm that this indeed hits the bus (tested by Lunatone DALI-2 CS set as an application controller).