Note: This project is a copy of Ben Owen original hampton-bay-fan-mqtt repo modified to work for my fans - most of the credit should go to him!
You can find out more about this project in my blog post.
ESP8266 project enabling MQTT control for a Hampton Bay fan with a wireless receiver. Wireless communication is performed with a CC1101 wireless transceiver operating at ~303 MHz
.
This will also monitor for Hampton Bay RF signals so the state will stay in sync even if the original remote is used to control the fan.
This project uses the following libraries that are available through the Arduino IDE
and have been added locally just in case:
- SmartRC-CC1101-Driver-Lib by LSatan
- rc-switch by sui77
- PubSubClient by Nick O'Leary
- ESP8266 development board (Tested with
D1 Mini
) - CC1101 wireless transceiver
- Wiring info can be found in the SmartRC-CC1101-Driver-Lib readme
Modify the appropriate configuration in ./homefans/config.h
to work with your WiFi \ MQTT settings.
Change the WIFI_*
and MQTT_*
definitions in the sketch to match your network settings before uploading to the ESP.
You may need to alter the value of FREQUENCY
(in config.h
) if you are struggling to get your fan to respond. It took a lot of trial and error, but I finally got mine working using a value of 303.875
MHz.
From what I can find online - these are known good frequencies:
303.875
- working for me303.631
- original frequency used303.000
- in some cases this works?
By default, the state/command topics will be
- Fan on/off (payload
on
oroff
)home/fans/<fan_id>/on/state
home/fans/<fan_id>/on/set
- Fan speed (payload
low
,medium
,high
, oroff
)home/fans/<fan_id>/speed/state
home/fans/<fan_id>/speed/set
- Light on/off (payload
ON
orOFF
)home/fans/<fan_id>/light/state
home/fans/<fan_id>/light/set
fan_id
is a 4-digit binary number determined by the dip switch settings on the transmitter/receiver where up = 1 and down = 0. For example, the dip setting:
1 | 2 | 3 | 4 |
---|---|---|---|
↓ | ↓ | ↓ | ↑ |
...corresponds to a fan ID of 0001
To use this in Home Assistant as an MQTT Fan and MQTT Light, I'm using this config
mqtt:
fan:
- name: "Master Bedroom Fan"
state_topic: "home/fans/0001/light/state"
command_topic: "home/fans/0001/light/set"
preset_mode_state_topic: "home/fans/0001/speed/state"
preset_mode_command_topic: "home/fans/0001/speed/set"
preset_modes:
- "off"
- "low"
- "medium"
- "high"
qos: 0
payload_on: "on"
payload_off: "off"
light:
- name: "Master Bedroom Fan Light"
state_topic: "home/fans/0001/light/state"
command_topic: "home/fans/0001/light/set"
qos: 0
payload_on: "on"
payload_off: "off"
optimistic: false
Once restarted your new entities should be listed in Home Assistant:
The fan controls operate as you would expect:
Same for the light:
Note: You will need to repeat this for each new fan.
- Download Arduino IDE - if needed
- Add additional boards -
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- In Boards Manager search for and install
esp8266
- Clone this repo and open
./homefans/homefans.ino
- Install required libs
SmartRC-CC1101-Driver-Lib
via managerrc-switch
- via managerPubSubClient
- via manager OR zip
- Ensure that your board is selected (i.e.
D1 Mini
) - Run a test compilation to see if everything builds