Simple program using rpitx to control ceiling fans
This is a Python script using rpitx to control Harbor Breeze fans (or other simple rf fans) with a Raspberry Pi.
In order to use this with your own fan, you need to know the fan ID and frequency which can be obtained using a sdr/tv-tuner. Your Raspberry Pi needs* a bandpass filter on pin 7 or GPIO4. Read here for more info
This fan can be found for cheap at local home improvement stores and are common in some rental units (link). The fan comes with hardware to attach to a ceiling junction box, a reciever, and a small remote to control the fan.
The Remote has 5 buttons for controling the light and fan speed. This remote uses 304.2MHz on/off keying (or ook) to control the fan.
In order to control the fan, you need to know the ID of the fan and the control code used for each button the remote has. Using this software, the fan remote, and a SDR radio, The signal can be decoded to simple binary data once you know the right frequency. For this fan it is 304.2MHz
This remote uses a carrier signal of '10_' where '_' is 1 bit of data. Removing the carrier signal produces this below
After Analyzing the decoded signal, The first 16 bits correspond to the fan ID or which fan the remote is talking to (marked in green above). The last 8 Bits are the Control Code or which button on the remote got pressed (marked in yellow)
So, we need to get the Pi to send this signal in order to control the fan.
rpitx has a module called sendook that allows us to send on/off keyed messages which we will use to control the fan. sendook also requires us to specfiy a few extra details such as timing between on/off keys, pause duration, and # of repeats.
Install rpitx
sudo apt-get install git
git clone https://github.com/F5OEO/rpitx
cd rpitx
./install.sh
sudo reboot
Download the program
wget 'https://raw.githubusercontent.com/Aechs/rpitx-fancontrol/main/parse_tx.py'
Run the program This example would set a low fan speed on the "K" fan
python parse_tx.py K 1