Zigbee Switch Configurable Firmware (+Router)

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

Fig.1 The configuration window

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

  1. The firmware creates a separate endpoint (1..5) for every configured output and/or input (max 5 endpoints).
  2. 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.
  3. 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.
  4. You may control the output state via the “ZCL_CLUSTER_ID_GEN_ON_OFF” cluster and the “ON_OFF” attribute.
  5. 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.

Download

Download firmware


Comments
Harvey Specter
Posted at 20:37 August 3, 2019
Mülly
Reply
Author

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

    Harvey Specter
    Posted at 07:05 August 4, 2019
    Owner
    Reply
    Author

    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).

      Harvey Specter
      Posted at 08:13 August 19, 2019
      Mülly
      Reply
      Author

      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

Harvey Specter
Posted at 14:47 August 4, 2019
Guest0007
Reply
Author

it’s really cool! I would like to try it to work with my zigbee2mqtt. Will it work with zigbee2mqtt?

    Harvey Specter
    Posted at 03:38 August 5, 2019
    Owner
    Reply
    Author

    Yes, but you should use the ‘dev’ branch.

Harvey Specter
Posted at 20:58 August 5, 2019
Olili
Reply
Author

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?

    Harvey Specter
    Posted at 03:46 August 6, 2019
    Owner
    Reply
    Author

    Could you please upload a screenshot with your firmware settings somewhere? What do you expect to get? What did you get in Z2M?

      Harvey Specter
      Posted at 09:06 August 10, 2019
      Olili
      Reply
      Author

      As written at z2m issue tracker – Logs and datasheet are available at niklas.ml/issue.zip.

      Any track in between?

      O

        Harvey Specter
        Posted at 04:59 August 11, 2019
        Owner
        Reply
        Author

        Sorry, I was busy at work. I’ll look at this in the next few days.

          Harvey Specter
          Posted at 04:42 August 14, 2019
          Owner
          Author

          Hi @Olli.

          I’ve fixed this bug in the firmware. Please, re-download the ZIP archive.

      Harvey Specter
      Posted at 06:42 August 14, 2019
      Olili
      Reply
      Author

      corrected version is working. Many thanks for your great work!

        Harvey Specter
        Posted at 06:54 August 14, 2019
        Owner
        Reply
        Author

        You are welcome 🙂

Harvey Specter
Posted at 23:46 August 7, 2019
MrAlester
Reply
Author

Great project! Could you please update it to allow to select the CC2530 as an End Device instead of Router? Please!

    Harvey Specter
    Posted at 04:10 August 8, 2019
    Owner
    Reply
    Author

    Could you please explain your request? When do you need EndDevice only, and you cannot replace it with a router?

      Harvey Specter
      Posted at 23:04 August 10, 2019
      MrAlester
      Reply
      Author

      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!!

        Harvey Specter
        Posted at 05:03 August 11, 2019
        Owner
        Reply
        Author

        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.

          Harvey Specter
          Posted at 03:32 August 12, 2019
          MrAlester
          Author

          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.

Harvey Specter
Posted at 16:23 August 21, 2019
Olili
Reply
Author

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

    Harvey Specter
    Posted at 03:41 August 22, 2019
    Owner
    Reply
    Author

    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.

      Harvey Specter
      Posted at 05:39 August 22, 2019
      Olili
      Reply
      Author

      Many Thx in advance.
      I offer my validation support as soon as you have something available.

Harvey Specter
Posted at 12:22 September 11, 2019
Jaime Vaz
Reply
Author

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

    Harvey Specter
    Posted at 13:45 September 11, 2019
    Owner
    Reply
    Author

    Hi!

    This feature is already in my to-do list. But I cannot say when I’ll add it.

Harvey Specter
Posted at 16:45 September 19, 2019
fabiancrg
Reply
Author

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 ?

    Harvey Specter
    Posted at 03:38 September 20, 2019
    Owner
    Reply
    Author

    Here is the example from Z2M converters:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
                value = parseInt(value);
                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,
                    }]);
                }
Harvey Specter
Posted at 13:05 September 25, 2019
xjin
Reply
Author

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.

    Harvey Specter
    Posted at 04:01 September 26, 2019
    Owner
    Reply
    Author

    СС2530 does not have a hardware watchdog timer. It is not possible to implement.

      Harvey Specter
      Posted at 05:40 September 26, 2019
      xjin
      Reply
      Author

      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).

        Harvey Specter
        Posted at 11:45 September 26, 2019
        Owner
        Reply
        Author

        Ok. I’ll look at that a bit more in the next version.

Harvey Specter
Posted at 11:10 September 26, 2019
Jörg
Reply
Author

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

    Harvey Specter
    Posted at 11:44 September 26, 2019
    Owner
    Reply
    Author

    Invert: it is in my “to-do” list.
    Sources: sorry, but it is not available.

Harvey Specter
Posted at 22:52 October 2, 2019
Massimo Trojani
Reply
Author

Hi, is there a domoticz plugins for ptvo.switch?
tnx

    Harvey Specter
    Posted at 03:53 October 3, 2019
    Owner
    Reply
    Author

    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.

Harvey Specter
Posted at 23:11 October 9, 2019
Dmitry
Reply
Author

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.

    Harvey Specter
    Posted at 06:44 October 13, 2019
    Owner
    Reply
    Author

    Please, look at the README.TXT in the archive with the firmware.

Leave a Reply to Olili
Cancel Reply

Navigation