owenb321 / hampton-bay-fan-mqtt

MQTT / RF Bridge for Hampton Bay Fan control
66 stars 18 forks source link

Changes to work with my version of the Hampton Bay remote #5

Open Concours99 opened 6 months ago

Concours99 commented 6 months ago

Thank you for the implementation on how to control a Hampton Bay fan via MQTT from my Home Assistant.

Unfortunately, it was not a turn-key solution. I discovered that my remote sends a checksum in addition to the data that you decoded. Without the checksum, the controller in the fan ignores the signal.

This is what my remote looks like: IMG_20240319_125451829

Differences in the code sent -

You documented the code sent as follows: 000xxxx000000yzz00000

Where:

What I have determined for my remote is similar: 000xxxxaaaaaaazzbbbbb

Where:

Here is the function that I wrote to implement it:

int calculateChecksum(int number) {
  int sum = 0;

  while (number > 0) {
    sum += number & 0xF;
    number >>= 4;
  }

  return sum % 16;
}

and I changed the code to complete the rfCode to:

 int rfCode = dipToRfIds[fanId] << 9 | fans[fanId].lightState << 2 | fanRf;
 rfCode = rfCode << 5 | calculateChecksum(rfCode);

so it calculates the left-most 16 bits, sends them to the checksum procedure and then constructs the entire 21-bit message to send.

Thanks again for your work. Hopefully my additional insights will help others with their own implementation.

BTW, the frequency for my remote is 303.85 which I found by searching the FCC site for the number indicated on the back of the remote:

https://fcc.report/FCC-ID/CHQ8BT7096T/

patrickdk77 commented 6 months ago

I'll look at adding this, but yes, there is an unlimited different versions of hampton bay codes, as they keep expanding it, and they are just rebranding china ones these days. ideally though I would like to name them after the encoding chip used, but that is more impossible for people to find out.

Concours99 commented 6 months ago

FWIW, my fan and remote are both quite old.

patrickdk77 commented 6 months ago

Yep, definition of old, I was meaning 80s :)