This firmware allows you to create a Zigbee switch device with a flexible configuration of inputs and outputs. I’ve created a base firmware for CC2530, CC2530 + CC2590 , CC2530 + CC2591 and CC2530 + CC2592 chips. The attached configurator for Windows can write your device configuration to the selected base firmware. Then you can save the customized version to a separate HEX file and upload to your device.
Inputs and outputs can work independently. So you may create a switch without a control button, or a simple button only.
The device with this firmware also works as a router.
Note: the firmware is designed for constantly powered devices.
Options

Remember state – The firmware saves the output state to NVRAM and restores it after power off/on.
Link – The input immediately controls the state of the corresponding output. The device sends the on/off state of the output to a coordinator. Otherwise, the input is independent.
Long – The firmware detects and reports to the coordinator a long click (2000 ms).
Double – The firmware detects and reports double click (max 500 ms between clicks).
Triple – The firmware detects and reports triple-click (max 500 ms between clicks).
Zigbee internals
- The firmware creates a separate endpoint (1..5) for every configured output and/or input (max 5 endpoints).
- The firmware reports the state of an independent button via the “ZCL_CLUSTER_ID_GEN_MULTISTATE_INPUT_BASIC” cluster and the “PRESENT_VALUE” attribute. 1 – single click.
2 – double click.
3 – triple-click.
4 – long click. - The firmware does not send a separate report for the linked button. Otherwise, it sends reports about the output state via the “ZCL_CLUSTER_ID_GEN_ON_OFF” cluster and the “ON_OFF” attribute.
- You may control the output state via the “ZCL_CLUSTER_ID_GEN_ON_OFF” cluster and the “ON_OFF” attribute.
- The “ZCL_CLUSTER_ID_GEN_ON_OFF” cluster also accepts the “read”, “configure” and “onOffWithTimedOff” commands: “read” – returns the current state on the specified endpoint.
“configure” – set the periodic reporting interval for the output. The “minReportInt ” attribute specifies the reporting interval in seconds. If “minReportInt ” is 65535, the firmware disables periodic reports. “onOffWithTimedOff” – sets the output state to “HIGH” for “onTime” milliseconds, and automatically resets to “LOW”.
Updates
2019-08-14: Fixed bug with 3rd and 4th inputs.
2019-06-27: First release.
Mülly
Hello ptvo,
this looks really great and is exactly what I was looking for. I got a couple of “Z-Control” experimental boards (http://www.z-control.de/p/62/starter-kit-i-zsk101) which are based on CC2531. Therefore I’m wondering, if your code will also work for CC2531-based boards?
Btw: the package mentioned above is really wonderful: you not only get a CC2531 MCU but also some sort of CCDebug adapter (works with TI’s SmartRFProg), some I2C stuff and a power adapter.
I flashed it with the github coordinator firmware and another one with the router-diag firmware and both work well and communicate.
Thsnks a lot for your work,
Mülly
Owner
Hello Mülly,
Sorry, but I’ve prepared the firmware for the CC2530 chip only because CC2531 is overabundant for DIY projects (USB is useless in most cases).
Mülly
Hello ptvo,
you’re right, its overshoot. However, I can get an USB-dongle for not even EUR 5, and modify it to have some I/O pins (some even have already some sort of I/O header), whereas the cheepest CC2530 I can get without eBay/Alibaba is in the EUR 20-something (X-Bee).
Best regards,
Mülly
Owner
CC2530 with an external antenna
https://aliexpress.com/item/32767470382.html
CC2530 E18
http://aliexpress.com/item/32803052003.html
All items cost < $10.
Guest0007
it’s really cool! I would like to try it to work with my zigbee2mqtt. Will it work with zigbee2mqtt?
Owner
Yes, but you should use the ‘dev’ branch.
Olili
Great! Exactly what I searched for.
I’m using the DIY firmware with E18-MS1 (CC2530+2592). Basically it is working perfectly. But I have problems reading INP3+4.
Some details: different HW assignments tested, Zigbee2MQtt + devices.js/toZigbee.js/fromZigbee.js from dev branch.
Any Ideas?
Owner
Could you please upload a screenshot with your firmware settings somewhere? What do you expect to get? What did you get in Z2M?
Olili
As written at z2m issue tracker – Logs and datasheet are available at niklas.ml/issue.zip.
Any track in between?
O
Owner
Sorry, I was busy at work. I’ll look at this in the next few days.
Owner
Hi @Olli.
I’ve fixed this bug in the firmware. Please, re-download the ZIP archive.
Olili
corrected version is working. Many thanks for your great work!
Owner
You are welcome 🙂
MrAlester
Great project! Could you please update it to allow to select the CC2530 as an End Device instead of Router? Please!
Owner
Could you please explain your request? When do you need EndDevice only, and you cannot replace it with a router?
MrAlester
My house (sadly) doesn´t have the Neutral wire on the wall switches.
I managed to flash a non router firmware to a CC2530 and wire the wall switches to a relay that was connected to it. Everything worked perfect, I could turn the lights using the wall switch or a zigbee message.
It worked great until the battery ran out of juice, it lasted one day. That’s when I realized that I needed to configure the CC2530 as a EndDevice. And since I’m not Z-Stack savy, I couldn’t make it work.
My ideal wiring is:
– CC2530 Router at the Lamp Bulb.
– CC2530 EndDevice at the wall switch powered by batteries.
– Wires permanently connected, that way CC2530 Router is always powered.
That way I can use the wall switches that already are placed in the house (wife’s request). And the EndDevice won’t be permanently activated so the battery last for a long time (Xiaomi Switches have been working for over a year without being replaced).
Thanks!!
Owner
EndDevice with a relay is a bad idea. The consumption of the relay is big and constant. This device will work with a battery for a short time too.
MrAlester
The relay is for the router which goes in the lamp.
The EndDevice is only for replacing the wall switches, which are “asleep” until someone presses them.
I know it’s redundant, but it’s the only zigbee solution I’ve come across for a No-Neutral wire home.
Olili
Dear ptvo,
once again many thanks for fixing the “3rd input issue”.
Nevertheless I have to approach you with another request.
I need to configure the i/o-behavior more accurately, i.e. some inputs need to be 3-state or even pull-down.
Therefore, can you somehow offer me an access to P0INP, P1INP and P2INP – init ?
As a quick workaround I can patch the HEX-File by myself manually, but I need respective location of these init values.
Can you support?
On mid term it would be great to make this configurable by your windows application as well.
Many thx in advance,
Olili
Owner
Hi,
Unfortunately, the firmware sets the P0INP, P1INP, and P2INP values dynamically. You cannot change it in the HEX file directly. I’ll try to add this feature to the next version of the firmware.
Olili
Many Thx in advance.
I offer my validation support as soon as you have something available.
Jaime Vaz
Hi! There is some firmware to create a 4 channel remote using ZigBee witch can be operated using battery? The concept is being always in deep sleep and wake up and send a code when I press a button.
Thanks
Owner
Hi!
This feature is already in my to-do list. But I cannot say when I’ll add it.
fabiancrg
Hi
I am testing this firmware, it’s working pretty well but I cannot find the way to use the read, configure and onOffWithTimedOff.
Which topic and payload do I have to use ?
Owner
Here is the example from Z2M converters:
2
3
4
5
6
7
8
9
10
11
12
13
14
if (!value) {
return;
}
if (key === 'trigger') {
await entity.command('genOnOff', 'onWithTimedOff', {ctrlbits: 0, ontime: value, offwaittime: 0});
} else if (key === 'interval') {
await entity.configureReporting('genOnOff', [{
attribute: 'onOff',
minimumReportInterval: value,
maximumReportInterval: value,
}]);
}
xjin
Hi,
I used you hex file in my switch(cc2530), but i found an issue on my switch, it is a single wire switch, when it powered on first, the power is not stable, the program seems dead, but it can run normal after reset, so i think can i add a watch dog in the program ?
Thanks.
Owner
СС2530 does not have a hardware watchdog timer. It is not possible to implement.
xjin
Hi,
I have checked the datasheet file, cc2530 has a built0in watchdog timer, this is a description in cc2530 datasheet.pdf (page 1 and page 3, page 21,
http://www.ti.com/cn/lit/ds/symlink/cc2530.pdf).
Owner
Ok. I’ll look at that a bit more in the next version.
Jörg
Hi, It work’s fine with conbee and iobroker. I use it as output with a 4 x relais cluster.
Is it possible to invert the on/off state with the software?
If not is possible to download source?
/jörg
Owner
Invert: it is in my “to-do” list.
Sources: sorry, but it is not available.
Massimo Trojani
Hi, is there a domoticz plugins for ptvo.switch?
tnx
Owner
Hi,
I’ve added this device to Zigbee2Mqtt (https://www.zigbee2mqtt.io/). I know you can use Zigbee2Mqtt in Domomticz, but I’m not sure if this device is available there.
Dmitry
Hello ptvo,
Thank you for your effort to create this filmware.
I’am going to order board and try it. But one thing is unclear for me. Could you please post how to pair this board and how to reset it. Thank you.
Owner
Please, look at the README.TXT in the archive with the firmware.
Inverted
Hi, could you share the IAR *.eww files so that we can tune the firmware more specific
Owner
Hi,
I do not share my sources.
Ivan
Hello Ptvo ,
I did set status Leb to pin P10 but not working . Could you please let me know ?
Owner
It is necessary to know something about your schematics.
Fabian
Hi,
Thnak you for this tool, it’s really nice.
But I do have two issues:
1. I configured P14 as an output and each time I power on the board, it’s toggled ON. Other outputs configured on P12, P13, P15 are OK.
2. If I try to join my lab zigbee network using channel 15 it’s working without any issue. But my other zigbee network is using channel 11 and I can’t pair it.
I do see the board restarting a few times (thanks to problem 1) but after a few times it seems it stays down.
Is there a way maybe to select the channel in the tool ?
Thank you,
Fabian
Owner
Hi,
Sorry about my late reply.
1. Some pins have the default state. The firmware can change it only when it starts.
2. The router scans all channels. But the router may try to connect to another opened network.
Filip
Can you please recommend me a board with cc2530 and I/O pins that is as small as possible and can be used as end device / router with some sensor or relay attached to I/O pins?
That would be really useful for wall switches or standing lamp switch – need 1 input and 1 output pins.
I am just starting with zigbee, with a little (really basic) experience in programming and DYI projects. So I want to be able to use your solution to easily program routers/end-devices 🙂
Owner
Hi,
Look at the following store: https://www.aliexpress.com/store/2077046?spm=a2g0o.detail.100005.1.6c3f7fb1DicIgE
But pay your attention to the board size and pin density. It is too hard to solder in-home, but it is possible. I’ve created 2 switches using these modules.
Filip
Thanks for your reply!
Which modules are you referring to? They have only one kind of ones with cc2530 🙁
I was thinking about something like that one: https://www.aliexpress.com/item/32881360125.html or that one: https://www.aliexpress.com/item/4000222196626.html
but I suppose that those don’t have any I/O pins 🙁
For me, personally (I’m not that good at soldering), it would be best to have as tiny module as possible but without sacrificing gold pins. I would like to avoid soldering and have a little bit freedom with connecting sensors.
Another question has come to my mind. What input/output voltage/amperage does this boards accept via I/O pins?
Is it possible that you share your circuit diagrams with us? It would be a much helpful resource for DYI newbies 🙂
Owner
For example, https://www.aliexpress.com/item/32640770110.html
Yellows pads around the board are IO pins (look at the last image).
For beginners: https://www.aliexpress.com/item/33009302278.html
Filip
Sure, that’s what I actually get. Maybe I will risk playing with those tinier boards when I get some general practice. I am already waiting for CC2531 and CC2530 module that you linked 🙂
Filip
Also, many thanks for sharing your projects and writing guides. They are much helpful!
Serg
Hello! Can I use this firmware to monitor input’s binary state?
For example On/Off toggle switch?
Thank you!
Owner
Hi,
Yes, you can. If you need On/Off, then you should define input and link it to a dummy output (any unused pin). Otherwise, the firmware will detect clicks.
Moritz
Hi, this looks really interesting!
Do you know anything about the power consumption or whether it is possible to run this on batteries only?
As I read in some other comment, the router functionality apparently draws a lot of battery life. Is there a version without routing?
Thanks for your reply!
Owner
Hi,
I’m working on the new version with power saving features.
John
Can I direct pulse control of output pins? Need send pulse 300-500ms.
Owner
Hi,
Yes, you can do it using the onOffWithTimedOff command on the “ZCL_CLUSTER_ID_GEN_ON_OFF” cluster.