# Decoder for Honeywell fan remotes.
#
# This fan is made by Intertek (model 4003229) but is sold by Honeywell
# as a model 'Salermo', number 10285. This fan may be sold under different
# makes and models, YMMV.
#
# Honeywell fans use OOK_PULSE_PPM encoding.
# The packet starts with a 300 uS start pulse.
# - 0 is defined as a 300 uS gap followed by a 900 uS pulse.
# - 1 is defined as a 900 uS gap followed by a 300 uS pulse.
#
# Transmissions consist of a short start bit followed by bursts of 24 bits.
# These packets are repeated up to 23 times.
#
# Possible packet layout:
#
#     Bit number 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23
#                -----------------------------------------------------------------------
#     Value      0  0  0  1  0  1  1  0  1  1  0  0  1  1  0  1 |Value|  Cmd   | 1 !d  d
#
# It is pure supposition that the leading 0x16CD and bit 21 are fixed values.
# I do not have more than 1 remote to test and there's no mention in the manual about
# dip switch settings, nor are there any on the remote. It's also possible that the
# value occupies 3 bits and the command is only two bits. It's also possible that
# there's no such command/value distinction. It looks very suspicious that the fan
# speed commands all share command 000 and the speed value (bit-reversed) appears in the
# value area.
#
#     Button  Fixed Other Bits       Function
#     ONE         16CD  1 0 0 0 0 1 !d d  Low speed fan
#     TWO         16CD  0 1 0 0 0 1 !d d  Medium speed fan
#     THREE       16CD  1 1 0 0 0 1 !d d  High speed fan
#     OFF-M       16CD  0 0 0 1 0 1 !d d  Fan off (momentary press)
#     OFF-C       16CD  0 0 1 0 1 1 !d d  Light off delay (continuous press)
#     STAR-M      16CD  1 1 0 1 0 1 !d d  Light on/off (momentary press)
#     STAR-C      16CD  0 1 1 1 0 1 !d d  Light dim/brighten (continuous press)
#     ONE+THREE-C 16CD  1 0 1 0 1 1 !d d  Learn mode ONE+THREE (continuous press)
#
# The 'd' bit indicates whether the D/CFL button in the battery compartment
# is set to 'D' (1 bit) or 'CFL' (0 bit). This switch inhibits the dim
# function when set to CFL. The !d bit seems to just be the complement of 'd'.
#
# Since the COMMAND/VALUE paradigm is not verified and only seems to apply to the fan speed
# buttons, we'll decode using the full 3rd byte right-shifted by 3 bits to omit the fixed '1'
# and 'Dim' bits.
#
#     byte[2] >> 3:
#     -------------
#     0x10: Low fan speed
#     0x08: Medium fan speed
#     0x18: High fan speed
#     0x02: Fan off, momentary press of the power button
#     0x05: Delayed light off, extended press of the power button
#     0x1A: Light on/off, momentary press of the 'star' button
#     0x0E: Light dim/brighten, extended press of the 'star' button
#     0x15: 'Learn' mode - hold ONE+THREE (low+high) for 5+ secs. Pairs remote to fan.

frequency 314.92M

decoder {
    name        = Honeywell-Fan,
    modulation  = OOK_PPM,
    bits        = 24,
    short       = 300,
    long        = 900,
    reset       = 1300,
    get         = id:@0:{16},
    get         = button:@16:{5}:[16:fan_low 8:fan_med 24:fan_hi 2:fan_off 5:light_off_delayed 26:light_on_off 14:light_dim_brighten 21:learn_mode],
    get         = dimmable:@23:{1}:[0:no 1:yes]
}