Jste zde

Domácí automatizace s Homekitem (pouze anglická verze)

I have decided to write an article about my home automation project. It is a really long-term project. During several years I have spent thousands of hours working on that. The idea to create my own solution has started in the time of family house reconstruction.

The electronic development is something I really like and I have been doing pretty much all my life. So for me, there is no possibility to buy these products on the market. My intention is not to provide you exact solutions, schematics, boards, etc. like as is case of other projects. But if you are at least a bit like me, or you want to build your own home automation, or you just want to be inspired, then this article is intended for you. It can save you a lot of time.

During past years I came up with many different solutions, a lot of them have been discarded. I reworked some PCBs just because I have decided to move to different MCUs. I have tried to implement all my technology very robustly and there is always an easy way how to replace my solution with something available on the market. I am not a type of person, who wants to have electronics everywhere. I just want to improve our home living a bit.

I do not want to split this article into more pages, so if you want, please use these links to find your point of interest:
The main controller
The interconnection
The power supply
The Dimming controller & the Micro dimmers
The high power dimmer & the control button
The Smarlight & the Spirtit TRX
The Jablotron interface
The other boards

The main controller

Although this is one of the most recent modules, I think it is a good point where to start describing my project. Actually, I will describe the 3rd version of the main controller mostly.

The first one had quite a short life. I created it before the house reconstruction, and I use it to monitor heat consumption of our house. It was useful when deciding which type of new heat source to select. It had an ATxmega MCU and the Ethernet, so I was able to collect the data to my home server and visualized them.

I was really pleased, when Apple announced the Homekit. Until than, I was thinking about writing my own mobile application. I had some experience with writing Android applications, but Apple solution just fitted me at the time. I wanted to deal with hardware mostly.
At the beginning, I used the Homebridge app running on my home server machine. I had a RS-485 converter connected to the server. The next step was the creation of my own hardware with a Homekit support.

The second version of the main controller is quite recent too. To be honest, there was no need for the 3rd version. It had everything what I needed. It had a very good and powerful STM32 MCU with a lot of RAM/FLASH memory and the crypto engine. It is good to have it all for the Homekit implementation. In case of this controller, it was necessary to write a firmware with RTOS. I can hardly imagine running its firmware without it. The device had many functionalities, many interfaces etc.

I was quite lucky because I found the implementation of the Homekit by Maxim Kulkin on the Internet. He saved me a ton of time. He has written a code for ESP32 devices. The code is quite easy to use with a STM32 MCU. Thanks a lot, Maxim! The most problematic part was bringing a mDNS protocol to life. The ESP environment has some differences. I have written functions for the LwIP network stack. These functions are called by Maxim's code.
The main controller works like a bridge, other devices connected to this bridge are dynamically presented by Homekit according to configuration. When I was working on it, there wasn't such a good support for this, so it took me some time to understand Maxim's macros. Nowadays it's easier and more clearer.

The big advantage of this project for me is to learn some new stuff, to improve my skills and experience. Last year, I wanted to try something new, but I didn't have any project suitable for this step, so I decided to rework the main controller, and that decision was just perfect! The project has many more possibilities now, so I am excited about it and I have plans to implement new features. It is much easier to implement them in comparison with the previous version.

The 3rd version of the controller is powered by Linux. I am quite skilled Linux user, so I always wanted to build my own Linux board. Actually, the 2nd version should have been powered by Linux too. At that time, I was considering building the board with AT91SAM CPU, but I didn't have enough courage and especially equipment good enough to design and assembly the board. Another solution was to build a board with preassembled System on module (SOM), but I gave it up because that solution wasn't good enough for me. I just wanted to build my own board, not to use someone elses solution, even if it makes your life much easier.
Nowadays, because I have already some experiences with building my own Linux board, I would choose SOM or System in Package (like Octavo Systems). It doesn't make sense to design your own Linux solution if you are not planning to assembly at least a hundred of boards. In comparison with SOM/SIP, it's too complicated, too expensive and too risky. But if you want to try it like I did, or learn some new stuff, go for it.

Developing boards like this is often a painful process. It can take weeks of thinking how to design it properly. Thanks to a friend of mine, I got a tip to use SOM with Sitara CPU by Texas Instrument. I am used to seeing TI drivers in the Linux kernel, so I was confident enough to use their CPU. I have done some research around it and because I wanted to minimize the risk, I decided to build the board like the BeagleBone. Actually, a following of the reference designs is a very common technique. But be careful, it doesn't mean the reference designs are designed correctly. It can be tricky sometimes and can be better to design it from the scratch.

However I made one mistake. I filled in my library with missing components, I drew all schematics, but I almost gave it up again because I didn't know how to design the board. The standard PCB manufacturing process was too expensive for my use. The PCB stackup of the BeagleBone is something which is not offered by any PCB pool service (at least I don't know any). Even worse fact is, there is no PCB pool service with PCB stackup suitable for high speed designs with BGAs. Finally, I have discovered only one manufacturer, which is offering the pool service with a usable stackup (the big one in China). I was able to built it because I did not need to fanout all CPU pins. Otherwise, it would be almost impossible even with their stackup. The board has 6 layers and 3 of them can be used for high speed signals. The BeagleBone stackup offers one more high speed layer.

I had to use a different stackup and I had to increase the width of all high speed signals due to a different impedance calculation. That caused thinner gabs between signals (crosstalk), so I had to re-route pretty much every high speed signal. I don't know if it is safe to say (I don't have any analysis), but I think I have matched signal lengths more precisely in comparison with the reference design. At least, the board works well. It has 1 GHz ARM A8 CPU, 512 MB of RAM, two RS-485 interfaces, one CAN interface and a few GPIOs for LEDs, etc.

Next, I needed to boot Linux. The flash memories have limited lifetime, so I chose to use only the SD card as the removable storage medium. The Sitara CPU has many options how to boot from the selected medium. It can read data directly from the SD card with a FAT32 partition. I placed built MLO, u-boot and Linux kernel on this partition. The Linux file system is on a separated ext4 partition. A custom device tree (according to my schematic) was built together with the Linux kernel. Everything, including file system, was built in a minimalistic way, so the Linux is booting very fast. It takes around 2 seconds to boot fully.

With running Linux I could start to rewrite the STM32 code to it, which was a really nice process. Linux offers many ways how to develop and debug applications remotely, so the board can be placed somewhere in a server rack, and you can do whatever you want. I wrote a code to store the configuration in JSON file. mDNS protocol is provided by the Linux avahi daemon, so I only had to write some client code.

Here are some pictures of the configuration console. I am using a console I have developed to configure all devices. The main controller console is provided by the Telnet protocol; some devices have a serial console with built-in USB-C connector. But the most devices are configured through the main controller. For this purpose, I have a special section in its console.

The interconnection

When I started the house reconstruction, I used Sykfy 3x2x0.5 cables to interconnect all places where I planned to have some automation hardware. Nowadays I would prefer to use a CAT6 cable everywhere. It is much more universal. I tried to avoid using any wireless communication, but after some time of using dimmable lights, I realized that I want to have all lights dimmable. However I don't have cables everywhere, so it forced me to develop a wireless communication. It was really interesting to develop a protocol which works on different layers, can be encrypted, can be encapsulated for wireless or CAN bus transfer.

So the most devices are connected by RS-485 bus. I am using a CAN bus inside of the rack and for the wireless communication I am using Spirit1 transceiver by STMicroelectronics. It is transmitting data on 868 MHz frequency. At the beginning, I built some boards with a Microchip wireless solution, but because I am using mostly MCUs by STM, I reworked PCBs to use chips of the same manufacturer. It makes sense, STM provides some examples, so it was faster to implement. Before that, I didn't notice that STM has its solution too.

Because I am writing about interconnection, I want to mention something about my cable management; It was a painful process. Again, I spent a lot of time just thinking about it. I have 15 cables leading into the rack and I didn't know how to terminate them in an elegant way. I designed PCB with Krone connectors. The cables are connected to them. There are several rows of pin headers, which create interconnection matrix, so I can connect wires between the cables just by using a simple jumper.

This PCB design was interesting. There was a strong relation between the PCB design and the CAD design for 3D print. Each of this board is connected to the controller by a flat cable and a Centronics connector.

The power supply

The power supplies are very often the weakest point of most electronic devices. So again, a painful process, I spent ages to find out my solution. It wasn't simple because I wanted to use one central power supply to power the whole rack, and the rack is powering other devices like WiFi access points. There are also backup batteries, a charger and a MPPT regulator to connect a photovoltaic panel.

Yes, it is quite a beast. From my point of view, it is the most complicated part of the whole home automation. It has 8x 24 V outputs and 8x 48 V outputs. Each of them is separately fused and monitored. I can set current limits, disable them, etc. Every output can deliver up to 100 W, but the total power is limited. If the overload is detected, the output with the highest current consumption is disconnected. In case of the battery backup, I can set when the output will be disconnected, so it can save energy for more important systems. It monitors more than 40 electrical values continuously. I still have some work to do with the code.

The main board logic is built robustly, I used only components with long lifetime. The system is redundant. There are two bought power modules with 48 V output. On the main board, there are two high efficient buck converters, one battery charger (SEPIC) and one up-converter with MPPT, all of them directly connected. It has many advantages as it can be serviced much more easily, the development is much easier without the need to power off the whole system (in case I want to tune some module), and what is even more important - the design is not so risky in comparison with one board. So there are a lot of boards here.

The system has a built-in self test. After the power-up, all power modules are tested with and without dummy load, the voltages have to stay in a specific range. If some of them don't pass the test, it is replaced by a functional module. It may sound too over-engineered, but if you want a system like this with a high reliability, I think it is necessary to have a diagnostics like this.

The Dimming controller & the Micro dimmers

The purpose of this device is mainly to control the lighting in the corridors or on the staircase. These modules are situated in fuse boxes on the DIN rails together with 12 V power supplies. From the fuse box leads a standard installation cable, so it can be replaced by any type of light anytime. It is a low voltage, so instead of ground, I am using the 3rd wire for the communication with lights. It is something like a low speed RS-232, but it uses only one wire and it can communicate in both directions. The each individual light has a DIP switch to set the address, and can be controlled separately according time of sunset, sunrise or differently. It is not part of Homekit (but it can be).

Dimming controller
Micro dimmer

The high power dimmer & the control button

It is fashionable to use the LED strips as a lighting. I have them installed in aluminum profiles. The total power consumption can easily reach hundred watts in each room. I didn't know where to install a power source. They are often too large and my aluminum profiles offer only a 28 mm wide maintenance hole.

So, I accepted some risk and I installed a toroid transformer behind the plasterboard ceiling. The risk of transformer failure is very small compared to general switching power supply. I am using 12V LED strips. To stabilize voltage is used a synchronous buck converter.

This regulator is easy to access via a maintenance hole. I made a special rotary button to control the regulator manually. It communicates with the regulator by a similar bus like in case of the dimming controller. For the enclosure I bought some plastic parts made by ABB. They are using them for their rotary switches and it is in the same style as my other switches and sockets. As in case of MicroDimmer, I developed this board before my decision to move to STM microcontrollers, so these boards have an AVR MCU. They are not connected by the RS-485, so I let them be. Otherwise, I would prefer to rework them too. Still, I can update their firmware remotely without the need to remove them.

The button has RGB LEDs used to backlight the knob. I have printed some plastic parts to shield and diffuse the light. Practically, I am turning on only a weak blue light during the night. It helps locate the button.

The Smarlight & the Spirtit TRX

After some time I realized that I want to add more accessories, but I don't have any cables there. So I had to develop a transceiver for a wireless communication. There is no point in describing the transceiver in length. It is just a simple module with RS-485 interface and Spirit1 module. Generally it behaves like a switch in the computer networking, but it is a bit smarter than that. Unencrypted frames are denied to be transmitted.

In case of the Smartlight, there is a bit more about it. I bought a few lights made by Philips. They had 4 halogen bulbs and more glass sheets to diffuse the light. I replaced the halogen bulbs with LED bulbs, but they are small and they have probably a weak or non filtration capacitor, so they are flickering. It was really bad, so I have designed a board with white LEDs and a white solder mask. With some modifications, it fits with the original Philips light nicely.

It was more complicated to add some intelligence to the light, because there is only a installation cable with an ON-OFF switch there, but I found a simple solution. The MCU has a real time clock with a supercapacitor backup. So it knows what time it is, even when it is turned off. It is detecting every half of the sine wave on its input from the grid. It turns off the LEDs immediately after turning the switch to the OFF position, so after that, there is enough energy for additional few seconds. For example, the light can transmit a frame "Hey, I have been turned off!" to the main controller. After turning the switch to the ON position, the light sets its brightness according to the current time. In the night, it has a lower brightness, so it doesn't blind you etc.

The Jablotron interface

I did not want to spend time building my own security system. There are good enough solutions on the market. I bought one made by Jablotron company. The Homekit supports a security system accessory, so I wanted to add it to my home automation. Jablotron company offers a communication module for smart houses. Its price is not too friendly, but I used that module for my purpose. You can do quite a lot of stuff with it, but sometimes the communication can be too slow. For this reason, I preferred to use the security sensors with balanced loops. I am measuring voltage levels directly on the loops. So for example, I can use a security sensor output to control lighting on the stairs without latency.

The other boards

Access controller
Heat pump monitor

The access controller is a module to control door locks. It is a part of Homekit, but it is also controlled by the RFID Wiegand keyboard situated outside the house. I am using some electrical isolation techniques to separate outside keyboard from systems inside of the house.

The heat pump monitor is a new project. I am looking forward to work on it. I want to monitor the heat pump performance over time, so I will be able to detect if the heat pump works correctly or if it needs some maintenance. Linux offers many tools to present and store the long term measurements.

I will measure the heat pump performance independent of its electronics, but there is also a one interesting fact. I will be probably able to communicate with the heat pump regulator made by Siemens, and because the Homekit supports thermostat accessory, I will be able to control the home temperature remotely. By the way, I can do this by using their web server, but with the Homekit, it is a completely different experience. I prefer to set the same temperature during the whole year, but sometimes, it can be useful.

Closing words

These are some samples of my Home automation project. I wanted to share it with you. It has been a lot of work, many thousands of hours and I am still not finished. Maybe it is a shame, it will not serve to other people, but it was not my goal. I like it, I can always learn something new and at least, I can use it on a daily basis and that is great. So if you are working on a project like this, I hope, it will inspire you or at least, it will save you some time.