A Test of Patience and Will to Succeed.
Note: This simple item turned out to be a huge project with many, many false starts and dead ends in the effort. This is the first post on the project and is just an overview of what went on. I'll post details about various aspects over time. The project is almost done (maybe a month or so more) and shows promise for a great system.
I've covered my various projects to update the hardware in my home air condition system in several posts this year. I updated the theromostats and interfaces to the air handlers using ESP32 based processors, and that combination is working great. There was one piece left: my remote temperature sensors. I learned through experimentation and experience that the location where the home AC temperature is sensed matters a LOT <link>. That learning experience led me to create remote sensors for the temperature in my house; I wanted to make the house comfortable for people, and a thermostat on a hallway wall just wasn't meeting my needs. The remote sensors really did the job. I originally mounted them on the wall in my most used rooms but later started putting them on a shelf or table near places people happened to be. That project took quite a while but has been in place for years and years <link>.
The idea is to put the AC temperature sensing where the people are instead of some hallway wall or other place convenient to the AC technician installing it. Plus, thermostats have either a simple switch inside or a massive batch of hardware and software that the homeowner has no real control over. I broke that cycle several years back by building my own thermostats that I controlled, and I have never even considered the thermostats that the power company wants me to install.
Honestly, do you want the power company who sends you a monthly bill to control the thermostat in your house? Really??
So, the project is to create a battery-operated temperature sensor that transmits its battery level and the temperature over a Zigbee network to Home Assistant where it can be used to control the AC. All the other pieces have been put in place; I just have to build this one new piece, and my system will be complete...
The idea is to put the AC temperature sensing where the people are instead of some hallway wall or other place convenient to the AC technician installing it. Plus, thermostats have either a simple switch inside or a massive batch of hardware and software that the homeowner has no real control over. I broke that cycle several years back by building my own thermostats that I controlled, and I have never even considered the thermostats that the power company wants me to install.
Honestly, do you want the power company who sends you a monthly bill to control the thermostat in your house? Really??
So, the project is to create a battery-operated temperature sensor that transmits its battery level and the temperature over a Zigbee network to Home Assistant where it can be used to control the AC. All the other pieces have been put in place; I just have to build this one new piece, and my system will be complete...
What I thought would be a simple recap of previous work with new hardware turned out to be a huge pain in the butt. Now I totally understand why so many hobbyists in this area throw up their hands in disgust and set their project aside.
Easy Right? Well, roughly six MONTHS into the effort, I'm finally nearing the finish line for this simple project.
I decided to use a Xiao ESP32C6 module mounted on the Seeed Studio Grove Expansion board for several reasons. It gave me a place to mount the processor module and some nice connectors for hooking in a temperature sensor and maybe some switches; plus it has Zigbee capabilities. It also has a battery charger built into the expansion board, so I could use a rechargeable battery and just charge it when needed. My initial thoughts were to use the tried-and-true 18B20 temperature sensor and put the device to sleep and then wake up to send the temperature.
I've used that technique before with Arduino hardware, and it worked great. I got about six months of battery life, and they were very reliable over the years. So, I got the hardware and slapped together a rough prototype.
I hooked an 18B20 sensor to it and set up some quick code using the Arduino IDE written in C++ to see how things worked. It actually worked pretty well except for two things. First, it ate battery power way too quickly. A fully charged 18650 battery lasted less than 24 hours. Second, I couldn't have two analog sensors. The Arduino IDE library for Zigbee had problems mixing up two analog sensors. I would get the battery voltage on the wrong Zigbee endpoint.
Well, that was a problem. I didn't really want to dig into the Zigbee library to try and fix it because the load of software I'd have to work with was huge. Maybe I could use ESPHome since they were nearing completion on implementing Zigbee in their releases. That didn't work. It seems they were releasing the Zigbee software in bits and pieces, plus they did significant changes to their build to incorporate new code that would make their own progress easier and more reliable.
I could have easily used a mains-powered device and wifi to do this project, but there were other goals involved. My Zigbee network covers roughly five times the area my Wi-Fi network does. I have routers set up in places to forward data, and I can reach just about anywhere I want to. I wanted to use that network because it is really reliable. I have other projects in mind that can use anything I learn on this project going forward also.
So I waited until they got a critical mass of things completed and came back to the project. What followed was pure technical hell.
I worked with polling the device from Home Assistant, but that used too much battery also. I put the ESP32 to sleep and periodically woke it up to send data, but that still ate the battery. You see, there's multiple sleeps on the ESP32, and they use varying amounts of power. If you want to wake up periodically, you have to have something running to wake you up. There were options, external hardware to wake it up came to mind, but that still meant that something had to be awake to wake it up.
As a couple of people pointed out to me on various forums over the years, you have a device that runs on very little power, monitoring something like time, and when some trigger is reached, it shorts a line to ground, waking up the main processor to do some work. When the work is done, the processor goes back to sleep and the device waits for another trigger. This is one of the purposes of interrupts; interrupts was the answer I needed, but the 18B20 temperature sensor doesn't support interrupts.
There was an answer for me that I had ignored over the years because the 18B20 sensor was really easy to use; I needed an MCP9808. These things are not the easiest thing to use because of the way I'd have to read them, but fortunately, there were libraries to take care of that already on the web, so I ordered a couple of them.
How about OpenCAD? It's procedural in that you write code to build something and watch what happens in a 3D viewer. I tried it and it works pretty well except you have to do things in a certain order or it just doesn't work. There's no concept of a hole, you substract shapes instead. I never quite got the hang of it. Shapr3D was pretty cool because you work right on the screen without the annoyance of a timeline like fusion, but the cost was over the top for me. $200 bucks a year to make maybe three or four items is too steep.
I wound up using FreeCAD. It's free, opensource, and local. The things I build are right here on my drive, not on some server somewhere else. Sure, it's clumsy, but the latest version 1.1 and above have really improved what I can do with it.
I spent almost five weeks trying various modeling software and came to the conclusion that FreeCAD was my tool of choice for mounting hardware to a 3D model. But it would be hard to put together something that looked good instead of mechanically correct. Cool little models are called "organic." So, organic sculpting is the way to go if you want to show off a project to someone that wouldn't understand the idea of an interrupt driven temperature sensor. They want something that looks good. Do a search for organic sculpting and see what turns up. Lots of dragons, mysitical elves, sexy manga figures will crowd your screen.
I played with blender and it just wasn't satisfactory for building something to hold electronic parts, but it was fun to shape a solid into something fun and interesting.
Therefore, I plan on using two tools and build the final device with a base mounting area for the electronics using FreeCAD and a shell to wrap around it using Blender that looks presentable. That way I can change the shell anytime I want to and have a totally different look. It could be a pumpkin for fall, and a sunburst for summer. I could make a Halloweeen shell, or a fireworks display for the 4th. That will turn some high-tech device into a decoration.
I haven't gotten into the pretty part yet, but I have built the base plate for the components. This is what it looks like right off the printer:
Easy Right? Well, roughly six MONTHS into the effort, I'm finally nearing the finish line for this simple project.
I decided to use a Xiao ESP32C6 module mounted on the Seeed Studio Grove Expansion board for several reasons. It gave me a place to mount the processor module and some nice connectors for hooking in a temperature sensor and maybe some switches; plus it has Zigbee capabilities. It also has a battery charger built into the expansion board, so I could use a rechargeable battery and just charge it when needed. My initial thoughts were to use the tried-and-true 18B20 temperature sensor and put the device to sleep and then wake up to send the temperature.
I've used that technique before with Arduino hardware, and it worked great. I got about six months of battery life, and they were very reliable over the years. So, I got the hardware and slapped together a rough prototype.
I hooked an 18B20 sensor to it and set up some quick code using the Arduino IDE written in C++ to see how things worked. It actually worked pretty well except for two things. First, it ate battery power way too quickly. A fully charged 18650 battery lasted less than 24 hours. Second, I couldn't have two analog sensors. The Arduino IDE library for Zigbee had problems mixing up two analog sensors. I would get the battery voltage on the wrong Zigbee endpoint.
Well, that was a problem. I didn't really want to dig into the Zigbee library to try and fix it because the load of software I'd have to work with was huge. Maybe I could use ESPHome since they were nearing completion on implementing Zigbee in their releases. That didn't work. It seems they were releasing the Zigbee software in bits and pieces, plus they did significant changes to their build to incorporate new code that would make their own progress easier and more reliable.
I could have easily used a mains-powered device and wifi to do this project, but there were other goals involved. My Zigbee network covers roughly five times the area my Wi-Fi network does. I have routers set up in places to forward data, and I can reach just about anywhere I want to. I wanted to use that network because it is really reliable. I have other projects in mind that can use anything I learn on this project going forward also.
So I waited until they got a critical mass of things completed and came back to the project. What followed was pure technical hell.
I worked with polling the device from Home Assistant, but that used too much battery also. I put the ESP32 to sleep and periodically woke it up to send data, but that still ate the battery. You see, there's multiple sleeps on the ESP32, and they use varying amounts of power. If you want to wake up periodically, you have to have something running to wake you up. There were options, external hardware to wake it up came to mind, but that still meant that something had to be awake to wake it up.
As a couple of people pointed out to me on various forums over the years, you have a device that runs on very little power, monitoring something like time, and when some trigger is reached, it shorts a line to ground, waking up the main processor to do some work. When the work is done, the processor goes back to sleep and the device waits for another trigger. This is one of the purposes of interrupts; interrupts was the answer I needed, but the 18B20 temperature sensor doesn't support interrupts.
There was an answer for me that I had ignored over the years because the 18B20 sensor was really easy to use; I needed an MCP9808. These things are not the easiest thing to use because of the way I'd have to read them, but fortunately, there were libraries to take care of that already on the web, so I ordered a couple of them.
People have been using these sensors for years, and there should be a ton of examples I could use to get me started. And there really were a lot of examples out there, but NONE of them used the interrupt capability they provide. I literally hunted for days looking for something to help with this and found nothing. Lots and lots of polling examples and various temperature displays that used them, but nothing about how to use interrupts. It was the perfect chip to use; it could provide an interrupt, used a tiny bit of power, and had a quarter of a degree of accuracy.
Now if I could just figure out how to use the darn thing. Digging into its documentation left me with more questions than answers, but I realized there was another problem; I had no idea how to use sleep and interrupts in ESPHome.....
Skip forward a month, and I had finally gotten it to work. I could set the chip up to interrupt every degree of temperature change, positive or negative. That woke the processor up, and it would take the reading and send it over Zigbee to Zigbee2MQTT which handed it to Home assistant and I could display it in a chart. The ESP32C6 used the deepest sleep so it used only a tiny bit of power, 22 uA most of the time and 122 mA during the 10 seconds that it was awake to send the signal. If the temperature didn't change, it didn't send anything.
Now if I could just figure out how to use the darn thing. Digging into its documentation left me with more questions than answers, but I realized there was another problem; I had no idea how to use sleep and interrupts in ESPHome.....
Skip forward a month, and I had finally gotten it to work. I could set the chip up to interrupt every degree of temperature change, positive or negative. That woke the processor up, and it would take the reading and send it over Zigbee to Zigbee2MQTT which handed it to Home assistant and I could display it in a chart. The ESP32C6 used the deepest sleep so it used only a tiny bit of power, 22 uA most of the time and 122 mA during the 10 seconds that it was awake to send the signal. If the temperature didn't change, it didn't send anything.
To test for likely battery life, I prowled through my pile of 18650 batteries and found my worst cell. That was a process in itself because, how the heck do you tell if one of those batteries is going bad? I wondered about that for a while, looking at a ton of web articles, until I finally understood enough to realize I needed something better than a charger to handle these batteries properly. However, I simply couldn't trust the offerings out there because most of them lied about what their particular device actually did. ALWAYS look for reviews on this kind of thing because the net is full of devices that don't work. Eventually I settled on this device:
This is the Vapcell S4 Plus Battery Charger and Battery Discharge Tester. Yes, the vape industry led to this product, and it really does the job it was designed to do. The 18650 became one of the batteries used in the little vape machines that smoke shops sell these days, and people wanted fast chargers for them. Then they needed to be able to test the cells, and such until someone came out with a product. This product will completely discharge a cell, then charge it back up, then discharge it again to measure the capacity of the cell and finally charge the cell back up for use. It gives one a reading of the tested milliampere-hour capacity of the cell. That way I can test my cells, choose the worst of the bunch, and use it to test my new device over a longer period.
Note, to be honest with my readers, the first device I ordered worked exactly once, then died forever. I tried several things to wake it up but finally used Amazon's return policy and got another one. The second one worked fine and is still going strong.
Well, it turned out that ALL my 18650 batteries were crap, so I took the worst of the crap fired up my test device a month ago and have watched it ever since. The battery started out at the traditional 4.1 volts and has dropped to 3.71 over a month. That's on a cell that measured 840 mAh on the tester. So, it should last at least another month before it drops to lower than 3.3 V and the processor shuts off. Meanwhile, I hunted for some batteries that were actually what they were advertised to be, and that was a real treat as well. When you buy bulk, you get a couple of good ones and a pile that should have been dumped by quality control into the recycle bin. I did finally find a place that actually had good ones and picked up three high-capacity cells and tested them. They were rated at 3500 mAh, and all three tested at over 3600. I used 18650batterystore.com/ and will use them again, but I'm sure there are other quality vendors out there.
Now to the problem of an enclosure for it. A pile of pieces wired together is hardly what I wanted to show off after the months already invested in this project. I'm tired of the DIY crowd's favorite, Fusion. It works well, but is so complex it takes me a few hours to get the feel for using it again. It also seems to update daily. It was always wanting me to install an update or updating itself and telling me about it. It's cloud based, so everything is 'out there' someplace and subject to the whims of the people operating this system. So, I wanted something different that let me keep control and not worry about some vendor changing things out from under me. What to do?
I tried several CAD or CAD-like tools and really didn't get what I thought was necessary for me to develop with. I'm not an enterprise, so I don't need the collection of file handling and process-oriented software that is becoming rampant. SolidWorks is just like Fusion; it has everything everyone needs, whether they need it or not. It shares with Fusion a degree of complexity that takes months of hands-on training and testing to truly understand it well enough to feel comfortable. Sure it would be a good item on a resume, but that's of no interest to me.
Note, to be honest with my readers, the first device I ordered worked exactly once, then died forever. I tried several things to wake it up but finally used Amazon's return policy and got another one. The second one worked fine and is still going strong.
Well, it turned out that ALL my 18650 batteries were crap, so I took the worst of the crap fired up my test device a month ago and have watched it ever since. The battery started out at the traditional 4.1 volts and has dropped to 3.71 over a month. That's on a cell that measured 840 mAh on the tester. So, it should last at least another month before it drops to lower than 3.3 V and the processor shuts off. Meanwhile, I hunted for some batteries that were actually what they were advertised to be, and that was a real treat as well. When you buy bulk, you get a couple of good ones and a pile that should have been dumped by quality control into the recycle bin. I did finally find a place that actually had good ones and picked up three high-capacity cells and tested them. They were rated at 3500 mAh, and all three tested at over 3600. I used 18650batterystore.com/ and will use them again, but I'm sure there are other quality vendors out there.
Now to the problem of an enclosure for it. A pile of pieces wired together is hardly what I wanted to show off after the months already invested in this project. I'm tired of the DIY crowd's favorite, Fusion. It works well, but is so complex it takes me a few hours to get the feel for using it again. It also seems to update daily. It was always wanting me to install an update or updating itself and telling me about it. It's cloud based, so everything is 'out there' someplace and subject to the whims of the people operating this system. So, I wanted something different that let me keep control and not worry about some vendor changing things out from under me. What to do?
I tried several CAD or CAD-like tools and really didn't get what I thought was necessary for me to develop with. I'm not an enterprise, so I don't need the collection of file handling and process-oriented software that is becoming rampant. SolidWorks is just like Fusion; it has everything everyone needs, whether they need it or not. It shares with Fusion a degree of complexity that takes months of hands-on training and testing to truly understand it well enough to feel comfortable. Sure it would be a good item on a resume, but that's of no interest to me.
How about OpenCAD? It's procedural in that you write code to build something and watch what happens in a 3D viewer. I tried it and it works pretty well except you have to do things in a certain order or it just doesn't work. There's no concept of a hole, you substract shapes instead. I never quite got the hang of it. Shapr3D was pretty cool because you work right on the screen without the annoyance of a timeline like fusion, but the cost was over the top for me. $200 bucks a year to make maybe three or four items is too steep.
I wound up using FreeCAD. It's free, opensource, and local. The things I build are right here on my drive, not on some server somewhere else. Sure, it's clumsy, but the latest version 1.1 and above have really improved what I can do with it.
I spent almost five weeks trying various modeling software and came to the conclusion that FreeCAD was my tool of choice for mounting hardware to a 3D model. But it would be hard to put together something that looked good instead of mechanically correct. Cool little models are called "organic." So, organic sculpting is the way to go if you want to show off a project to someone that wouldn't understand the idea of an interrupt driven temperature sensor. They want something that looks good. Do a search for organic sculpting and see what turns up. Lots of dragons, mysitical elves, sexy manga figures will crowd your screen.
I played with blender and it just wasn't satisfactory for building something to hold electronic parts, but it was fun to shape a solid into something fun and interesting.
Therefore, I plan on using two tools and build the final device with a base mounting area for the electronics using FreeCAD and a shell to wrap around it using Blender that looks presentable. That way I can change the shell anytime I want to and have a totally different look. It could be a pumpkin for fall, and a sunburst for summer. I could make a Halloweeen shell, or a fireworks display for the 4th. That will turn some high-tech device into a decoration.
I haven't gotten into the pretty part yet, but I have built the base plate for the components. This is what it looks like right off the printer:
Yes, I use a brim around the object being printed. I hate watching my model slide around in the printer after two hours of waiting. It's 100 mm on each side and has a USB C hole cut in the pillar on the right.
Here it is with all of the components mounted, but not quite all of them wired up.
The temperature sensor is on a platform elevated a bit in the middle of the layout. I used a dipole antenna to get the best range I could out of it, but it's held in a cozy spot by friction so it could be moved if that ever becomes necessary. That 18650 holder is bolted down to the plate because changing it is a bit tough and I didn't want it coming loose when I get in there. I used a USB extension through the rear pillar with a tight friction fit to keep from damaging the USB connector on the Xiao ESP32C6. Those tiny boards can be a bit fragile, and this isolates someone wiggling the port around to an easily replaceable part.
One comment was that I had the temperature sensor too close to the processor and heat from there would ruin my readings. I chuckled as I pointed out that the device is only on for 10 seconds when the temperature changed by a degree. Almost all the time the device is dormant and not generating any heat at all. The period it is on is so small that it will never matter.
But it's ugly.
That's where a decortive shell comes in. I haven't started that work yet because I want to get some time with testing in various spots and learn as much as I can about using it. That part may actually be fun. Imagine a pumpkin for fall and you'll get the idea.
I'll post details about the various code and base plate in the future. This project opens up a whole new world of devices for me to play with. If I have access to mains power, I'll leave the battery out. But, think about a battery monitor for a tractor that is stored for the winter; something like this could keep it from freezing or the starting battery from going dead. How about a motion sensor under the hood of your car to tell you if the rodents are making another nest in there? Or, in my case inside my AC compressor out in the yard <link>.
But right this minute, I have remote temperature sensor for my home AC that can be placed anywhere, and can be powered by battery or main power and is rechargable right in the case if needed. It only took a few MONTHS and about a yard of hair pulled. This wasn't a project for the 'faint of heart' or a casual weekend.
Here it is with all of the components mounted, but not quite all of them wired up.
One comment was that I had the temperature sensor too close to the processor and heat from there would ruin my readings. I chuckled as I pointed out that the device is only on for 10 seconds when the temperature changed by a degree. Almost all the time the device is dormant and not generating any heat at all. The period it is on is so small that it will never matter.
But it's ugly.
That's where a decortive shell comes in. I haven't started that work yet because I want to get some time with testing in various spots and learn as much as I can about using it. That part may actually be fun. Imagine a pumpkin for fall and you'll get the idea.
But right this minute, I have remote temperature sensor for my home AC that can be placed anywhere, and can be powered by battery or main power and is rechargable right in the case if needed. It only took a few MONTHS and about a yard of hair pulled. This wasn't a project for the 'faint of heart' or a casual weekend.








No comments:
Post a Comment