visit
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 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. 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.
Left: 433Mhz RF receiver. Right: 433Mhz RF transmitter.
My first task was to read signals with the RF receiver. I followed —installed wiringPi and 433Utils, connected the data-pin of the RF receiver to GPIO27, GND to GND, VCC to 5V, run RFSniffer and pressed my remote. It worked!
Next, I connected the 433Mhz RF transmitter following the instructions . I was able to test that the transmitter was working fine using codesend to transmit a number, and received by the RF receiver running RFSniffer.
Everything went very smoothly until this point. However, the signal received from my remote using RFSniffer were not able to control my fan when re-transmitted with codesend. There must be something I misunderstood about how RF remote works. Looks like the hardware was the easy part.
Then I came across this .RF Transmitter connected to pin 17, and the RF receiver connected to pin 27
After installing pilight, 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.
GPIO numbering table from //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 pilight-daemon before running pilight-debug.
pi@raspberrypi:~/ $ sudo killall pilight-daemon pi@raspberrypi:~/ $ pilight-debugRun pilight-debug and press the buttons in the remote to capture the signals.
The raw code from pilight-debug 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.
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 7106Then I used pilight-send to send the raw code (If you have previously killed pilight-daemon, remember to start it again sudo pilight-daemon
). 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.
Now that I have managed to control my fan with command line, the next step is to get it working with HomeKit. HomeBridge is an open-sourced NodeJS server to emulate iOS HomeKit API. You can find the instruction to install HomeBridge in Raspberry Pi .
pilight has a . However, I had to create a custom plugin instead because I could not figure out how to set up pilight to do this. I found an open-source HomeBridge plugin to control a 3-speed TOSR0x fan, via API calls. I used that as a template for my plugin.
I created a REST API using Python/Flask that executes pilight-send with command line.
Then I modified the plugin to call the REST API, and removed temperature sensor, which is not supported by my fan.
After installing the plugin, I added my fans to HomeBridge by editing the configuration file in ~/.homebridge/config.json. The key ‘accessory’ has to be identical to the name declared in the plugin.
Restart HomeBridge for changes to take effect.
pi@raspberrypi:~/ $ sudo killall homebridge pi@raspberrypi:~/ $ homebridgeFan 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!