I have always wanted to get involved in a hardware project. And I love home automation. So automating my home fan seems to be the perfect project to start with. I use HomeKit for my door locks and lights. When I leave, HomeKit will lock my door and turn off all lights. But I always have to search for my fan remote to turn it off manually. It is not how I imagine my smart home should be. Setting up the Raspberry Pi Having had no experience with hardware, starting on my first project was quite intimidating. I did some research on what I needed, then purchased a and . Raspberry Pi starter kit a pair of 433Mhz receiver/transmitter Setting up Raspberry Pi 3 was a lot easier than I thought. comes with the OS preloaded in a microSD card. It also comes with jumper wires, a breadboard, a GPIO to breadboard interface board, LEDs and resistors. Canakit Ultimate Starter Kit The next thing I did, I went through an , and figured out how to use the breadboard. I was not sure if I would fry my Raspberry Pi if it was not connected properly, so I turned off the device during setup, turned it on when I was done. When connected wrongly, the device simply did not boot. I was lucky, the LED test went fine. That is equivalent to the ‘Hello World’ of coding. LED tutorial Reading RF Signals I suspected that my fan remote uses RF because it can work from a different room, but I was not sure that a 433Mhz receiver/transmitter was the right hardware to buy. It was a guess, but it worked out for me. Left: 433Mhz RF receiver. Right: 433Mhz RF transmitter. My first task was to read signals with the RF receiver. I followed —installed and , connected the data-pin of the RF receiver to GPIO27, GND to GND, VCC to 5V, run and pressed my remote. It worked! this guide closely wiringPi 433Utils RFSniffer Sending RF Signals Next, I connected the 433Mhz RF transmitter following the instructions . I was able to test that the transmitter was working fine using to transmit a number, and received by the RF receiver running . here codesend RFSniffer Sending RF Signals to emulate fan remote Everything went very smoothly until this point. However, the signal received from my remote using were not able to control my fan when re-transmitted with . There must be something I misunderstood about how RF remote works. Looks like the hardware was the easy part. RFSniffer codesend Then I came across this . post that uses pilight RF Transmitter connected to pin 17, and the RF receiver connected to pin 27 After installing , I configured it to work with my setup. The photo above shows that RF transmitter was connected to pin 17 and RF receiver to pin 27. pilight GPIO numbering table from http://wiringx.org The sender and receiver value in the config.json file can be determined by referencing the GPIO table above. Sender value at pin 17 should be 0, and receiver value at pin 27 should be 2. pilight configuration file: sender=0 and receiver=2, by referencing the GPIO table above Then I used to read and output raw information from my remote. Remember to kill before running . pilight-debug pilight-daemon pilight-debug pi@raspberrypi:~/ $ sudo killall pilight-daemon pi@raspberrypi:~/ $ pilight-debug Run pilight-debug and press the buttons in the remote to capture the signals. The raw code from is a series of numbers, with each single number measuring the time difference between a HIGH-LOW or LOW-HIGH transition. There were a lot of other noise signals, so I had to filter manually for the correct signal that originated from my remote. It seems the trick is to look out for series of numbers that only contain three unique numbers. These ‘cleaner’ numbers are only ones that worked for me. I had to keep pressing my remote until I get a code that looks ‘clean’ like this. pilight-debug 209 627 627 209 209 627 209 627 209 627 209 627 209 627 627 209 209 627 209 627 209 627 209 627 209 627 209 627 209 627 209 627 627 209 627 209 209 627 209 627 209 627 209 627 209 627 209 627 209 7106 Then I used to send the raw code (If you have previously killed , remember to start it again ). Viola! It worked. I repeated that for all buttons on the remote to get the different code for turning off, and changing speed. The signals are different for different remotes as well, so I have to repeat the same steps for the fan in my bedroom even though it is the same model. pilight-send pilight-daemon sudo pilight-daemon pi@raspberrypi:~/ $ sudo pilight-daemon pi@raspberrypi:~/ $ pilight-send -p raw -c “209 627 627 209 209 627 209 627 209 627 209 627 209 627 627 209 209 627 209 627 209 627 209 627 209 627 209 627 209 627 209 627 627 209 627 209 209 627 209 627 209 627 209 627 209 627 209 627 209 7106” Apple HomeKit integration with HomeBridge Now that I have managed to control my fan with command line, the next step is to get it working with HomeKit. is an open-sourced server to emulate iOS API. You can find the instruction to install in Raspberry Pi . HomeBridge NodeJS HomeKit HomeBridge here _homebridge - HomeKit support for the impatient_github.com nfarina/homebridge has a . However, I had to create a custom plugin instead because I could not figure out how to set up to do this. I found an open-source plugin to control a 3-speed TOSR0x fan, via API calls. I used that as a template for my plugin. pilight plugin HomeBridge pilight HomeBridge homebridge-tosr0x-fan I created a REST API using that executes with command line. Python/Flask pilight-send _rfremote-fan-api - API to control RF fan using pilight in Raspberry Pi_github.com honcheng/rfremote-fan-api Then I modified the plugin to call the , and removed temperature sensor, which is not supported by my fan. REST API = _homebridge-rfremote-fan - HomeBridge plugin to replace RF remote control for fans_github.com honcheng/homebridge-rfremote-fan I used the command below to install the plugin, though it is slower compared to . setting up a development folder pi@raspberrypi:~/ $ npm install -g homebridge After installing the plugin, I added my fans to by editing the configuration file in ~ . The key ‘accessory’ has to be identical to the name declared in the plugin. HomeBridge /.homebridge/config.json Restart for changes to take effect. HomeBridge pi@raspberrypi:~/ $ sudo killall homebridge pi@raspberrypi:~/ $ homebridge Fan controls in iOS Control Center Changing fan speed in HomeKit Not bad for my first hardware hack, done in a weekend. If you are trying to replicate the same setup for your RF remote controlled fan, you will have to identify the signals again because it will be different from mine. Good luck!
Share Your Thoughts