Writing Zigbee Drivers - init.lua

Hi All,

I’m embarking on wiriting my own zigbee drivers which i’m well aware is a long road. The only thing i’ve done that remotley resembles programming is basic python & VBA for excel.

I’ve been through a good part of the Lua tutorials and come to the conclusion that it’s very close to Python and other languages regarding things like functions etc, so i’m looking to learn how to build the init.lua file from scratch.

That said, i’ve set up the CLI, got VSCode up and running and created the structure for my new driver… (Zigbee multi-gang dimmer switch)

Could someone point me in the direction of a tutorial for writing the init.lua file, the bulk of the code?

I’ve read the tutorial from ST on here for writing the Zigbee driver but it doesn’t go into any depth regarding the init.lua file.

Any help would be appreciated.


Hi, @barron!
Welcome to the Edge drivers’ journey!

About the Edge development, you can check the Edge reference to understand the structure and see which commands you can use:


And the SmartThings Lua libraries included that are shared in the official SmartThings repo can help you take a reference from the existing default handlers(in the folder: lua_libs-api_v2/st/zigbee or zwave/defaults/capabilityName) of the device events, etc.:

Hi @baron
My own tentative first steps into Edge driver development (in September) was to find an existing Edge driver from the smartthings community set of drivers and then copy and edit.
When I ran into problems, I made a few posts on here and got great advice from the community.
Stick at it; make regular backups; and good luck.

1 Like

Thanks @jaidank

I think that’s where I’m headed. I wanted to learn how to build it up from scratch so I’d know it inside out but maybe that’s unrealistic.

I’ve now gone down the rabbit hole of Zigbee clusters and the ZCL.

Did you find you needed to know what each cluster reference was/is?

Hi @barron,
My own situation was two Z-Wave thermostats that used custom groovy drivers. At the time, I thought they would stop working on Oct 1st (since revised to 1st Jan). The community Z-Wave thermostat Edge driver had lots of sub-drivers and I eventually did a mix/match of the different capabilities I needed. I had trouble with associations but the community put me right. I did not have to deal with clusters.
Once you get to the point of an installed driver that your device can pick up, and you can see logs, then people can help with specifics. The logs can be a bit intense; I tended to cut and paste them into an editor and formatted them for clarity.
I am afraid I am no expert; I just got my thermostats working before the weather got cold (and fuel got even more expensive).
The fact that they now execute locally on the hub is icing on the cake.

This is not a requirement to start working with Edge, this is because there are some default handlers that already translate Zigbee/Z-Wave messages to ST capabilities for you, just in case the device has a manufacturer-specific cluster, you would have to get more technical, but there’s also a sample about that for Zigbee: SampleDrivers/common.lua at main · SmartThingsDevelopers/SampleDrivers · GitHub

Knowing a cluster’s details might help you in terms of troubleshooting or applying a custom configuration (Eg. reporting intervals), otherwise, you won’t need to interact with them directly.

In the tutorials section of the forum, there are some posts regarding the samples of Edge drivers:

That’s exactly the scenario for me @nayelyz.

I have a Moesgo 2 Ganfg dimmer module which apparently uses custom ZCL.

Not quite sure how I’m going to figure out what it uses yet.