Wednesday, April 15, 2026

My First 'Real' Zigbee Sensor

I've made a lot of sensor devices that reported using Digi XBees. The little RF devices work quite well and set up a self healing mesh network that really does what is needed. These came before Zigbee and the devices we see now for home automation. It was the beginning of the Internet of Things (IOT), but it wasn't actually on the internet. Most of this blog is about developing these devices to serve some purpose: reporting data about or controlling something around the house. Bringing industrial controls home for a common person. 

Zigbee devices started appearing, using the same techniques I was familiar with but with a documented protocol that could make different manufacturers devices work together. However, the first implementations were crippled by the manufacturers such that anyone buying them would be stuck using a single manufacturer's equipment. Much like pool controllers that are locked into a particular manufacturer. The Iris devices promoted and sold by Lowe's were such devices. Myself and others broke into the protocols of the Iris devices and built our own controllers eliminating being locked down like that. 

That philosophy, thankfully, died in favor of a huge number of real Zigbee devices. Zigbee 2 MQTT was the crowning touch to this; it allowed any manufacturer's offering to connect and translated the protocol into MQTT topics that anyone could use to control their own house.

But, you can look up the history of IOT if you want to know more, this is about creating my first device that used the Zigbee protocol. In my last post I described how I implemented a swimming pool controller using commercially available Zigbee devices, but left something out: measuring the air temperature at the pool controller, and a contact sensor for a float in my septic tank on the same side of the house.

The ESP32C6 had been announced that supported native Zigbee and Matter. Then Seeed Studio announced a tiny Xiao device that packaged the C6 as a component similar in size to a Digi XBee. This little thing was exactly what was needed for me to get my feet wet creating a sensor to measure temperature and check the status of that float. So, I ordered one (actually a couple).

Taken right from their web site

This thing is a little bit bigger than my thumbnail.

It comes in a cool container


Yes, it's that tiny, and subsequently a bit hard to deal with, so I ordered the expansion board to play with it. 

Taken right from their web site

This was big enough to handle and work with. It has plugs for adding sensors and powering them as well as that cute little display for debugging or showing off. Plus, there were instructions on using the latest Arduino IDE to develop software for it. I'm very familiar with the Arduino IDE since I've been using it as long as it has existed. That was a real plus in my mind. 

I downloaded the IDE, installed the board specific software, and wrote my first program for the C6, "blink". Then I expanded to "Hello World,"  I was ready to dig into bringing up a Zigbee device, and then later, conquer the world.

The first thing I noted playing with the Zigbee examples supplied by the developers was that they were designed to connect a C6 controller to a C6 device. I wanted to connect a C6 device to Zigmee2mqtt and Home assistant; how does one go about that? I had to poke at it quite a bit to get my device to join, and it was really frustrating. There was a whole world of considerations that I didn't have in my development work under the Digi XBee model. At this point, I need to tell you about a way to cheat. You know how frustrating it is to look for an example of something like getting that little display on the expansion board to work, and even make it behave like a terminal and scroll information? It's really hard to search for it because you get 1.6 million hits, many of them on forums, and a huge number of youtube videos some of which are related, others that are not. Plus the usual totally unrelated hits that just drive you nuts. The answer to that for me is to use AI to search for me.

Let AI do the searching dealing with the ads, pop-ups, videos in the corner of the screen and give you back something that might actually help. I used it extensively to summarize discussions to a few real findings and translate the jargon into something I could understand. DO NOT let it write code for you. That would be great, but it puts in stuff you didn't ask for and inserts more errors than it solves, but for gathering information, it's a gem. Especially in today's ad-ridden internet.

I got the device to join with Z2M and then ran into problems with the data it was providing to Home Assistant. That led me to what's called a 'converter.' This is a piece of yaml code that describes the Zigbee clusters and what to do with the data. The documentation on these pieces of 'code' is odd and I had to prowl through it a lot to get some idea of what was going on. Also, Z2M had changed the way the converters worked and should be written, and the 'helpful' sites on the web were mostly too old, or just flat wrong. AI to the rescue, sort of. AI had the same problem I did, separating the junk from the real information. It kept suggesting things that just wouldn't work, and were a mix of the old and the new. However, it was pretty good at finding problems with the exceptionally weird combination of syntax, keywords, and indentation that plague yaml. Yaml was supposed to provide a way of creating code from a description without having to learn to code. Instead, you have to learn how to make a very elaborate description that is properly organized using specific keywords, indented to the way some programmer thought it should be. Basically, it is part of the future that one has to adapt to in order to get anything new done in the IOT field. Also, it sucks.

Net though, I got a device working. It measures the temperature using an 18B20 and looks for a contact closure. Two endpoints that show up just great in Z2M (Zigbee2mqtt) under Home assistant. And then later in any dashboard or card that I want to use. I didn't find anything that could do this particular combination anywhere on the internet. Heck, there's only a few contact sensors out there at all. Here it is as it looked while I was working on it.


The 18B20 is plugged in to one of the expansion board ports; I used the chip version at first and then changed to the waterproof version when I installed it outside. This is a picture of it installed and actually working in the same enclosure that I used for the other pool devices.



It has been VERY reliable in  the months that it has been running. I used the Seeed 'case' for the expansion board to protect it a bit. Of course, I broke the first one I used; the little crack repaired with super glue is visible in the photo. Here's a close up:


Sigh, one has to be careful with those tiny plastic parts. Hey, superglue is great stuff, might as well use it. Speaking of glue, that "Alien Tape" that used to be advertised all over the place is actually great stuff. I use it all over the place, but one has to be careful because sometime it lets loose. I used it to mount the board, and it has held up really well so far. The other stuff is that 3M double sided 'tape'; you use that to mount something and then let it set overnight, and it is there forever. Shortcuts for the various projects we develop.

If anyone is interested in the actual code for this, it will be available on github when I finally overcome my reluctance to relearn how to use it. 

No comments:

Post a Comment