Single switch ceiling fan - with saved states!

I have a single switch ceiling fan in my bedroom. This means there is one line that powers both the fan and the lights. Naturally, if the switch is off there is no power to the fan or lights. If the switch is on, one must pull the draw strings to toggle the light and / or change the fan mode. Obviously those of you reading this will agree getting up to change the fan settings is unacceptable.

I scoured for a long time to try and find a solution to this problem. One of the ideas was to use the GE fan control and an aeotec nano swtich in the fan canopy. My particular fan has a small canopy space and those devices might not have fit. Further I am not sure if the wiring would work and that solution provides me with no redundancy should my Zwave or HomeAssistant go down.

I settled on an RF fan control to sit in the canopy and controlled it with a Broadlink pro that I purchased off Amazon. I will say that the Broadlink has been rock solid for the last few months used exclusively for fan control.

The part about this setup that I did not like was that the RF control would not read states. Everything was executed by a script and I would have to assume state. While not a bad setup, I had pondered looking into new setups. Recently I began playing with the new lovelace UI and figured out how to solve all of my problems.

The end state is fan control with an RF device in the canopy. I save the state of the lights and I save the state of the fan. Should the fan be adjusted through the remote and not HA I will lose synch. I have built some protocols to get me back into synch quickly via a script and with a daily reset.

  1. Installed honeywell fan controller which has a light toggle, fan speed off / low / med / high, button to turn off fan and lights in 60 seconds
    https://www.lowes.ca/ceiling-fan-controls-remotes/honeywell-handheld-step-up-full-function-ceiling-fan-remote-control_g1839802.html?searchTerm=Honeywell-fan

  2. Setup Broadlink pro+ to control fan through home assistant creating 6 switches

    1. fan high
    2. fan med
    3. fan low
    4. fan off
    5. fan lights
    6. turn off fan and lights in 60 seconds
  3. Create input booleans which will be used to record the states of the lights and fan speed. RF does not record states and so the switches do not tell us on or off. Switches will be called by a script which will update input boolean

input_boolean.yaml

  bedroom_ceiling_lights:
	name: Bedroom Ceiling Lights
	icon: mdi:lightbulb
  bedroom_fan_off:
	name: Bedroom Fan Off
	icon: mdi:fan-off
  bedroom_fan_low:
	name: Bedroom Fan Low
	icon: mdi:fan
  bedroom_fan_med:
	name: Bedroom Fan Med
	icon: mdi:fan
  bedroom_fan_high:
	name: Bedroom Fan High
	icon: mdi:fan
  1. Create scripts for fan control. Example below turns the fan to low, puts the corresponding input booleans to “on” and the other input_booleans to “off”

scripts.yaml

  sequence:
  - service: switch.turn_on
	data:
	  entity_id: switch.ceiling_fan_low
  - service: input_boolean.turn_on
	data:
	  entity_id: input_boolean.bedroom_fan_low
  - service: input_boolean.turn_off
	data:
	  entity_id:
		- input_boolean.bedroom_fan_off
		- input_boolean.bedroom_fan_med
		- input_boolean.bedroom_fan_high
  1. Customize the scripts. I used the mdi:numeric-X-box as my icons to show 0 1 2 3 for off, low, med high

customize.yaml

script.ceiling_fan_high:
  friendly_name: High
  icon: mdi:numeric-3-box
script.ceiling_fan_med:
  friendly_name: Med
  icon: mdi:numeric-2-box
script.ceiling_fan_low:
  friendly_name: Low
  icon: mdi:numeric-1-box
script.ceiling_fan_off:
  friendly_name: "Off"
  icon: mdi:numeric-0-box
  1. Create a front end conditional glance card for each fan state. Which ever input boolean is “on” will have a custom icon for the corresponding script, I used the mdi:numeric-X-box-multiple-outline. Example below:

ui-lovelace.yaml

  - type: conditional
    conditions:
      - entity: input_boolean.bedroom_fan_off
        state: "on"
    card:
      type: glance
      title: Bedroom Fan
      column_width: calc(100% / 4)
      show_name: true
      show_state: false
      entities:
        - entity: script.ceiling_fan_off
          tap_action: toggle
          icon: mdi:numeric-0-box-multiple-outline
        - entity: script.ceiling_fan_low
          tap_action: toggle
        - entity: script.ceiling_fan_med
          tap_action: toggle
        - entity: script.ceiling_fan_high
          tap_action: toggle

  - type: conditional
    conditions:
      - entity: input_boolean.bedroom_fan_low
        state: "on"
    card:
      type: glance
      title: Bedroom Fan
      column_width: calc(100% / 4)
      show_name: true
      show_state: false
      entities:
        - entity: script.ceiling_fan_off
          tap_action: toggle
        - entity: script.ceiling_fan_low
          tap_action: toggle
          icon: mdi:numeric-1-box-multiple-outline
        - entity: script.ceiling_fan_med
          tap_action: toggle
        - entity: script.ceiling_fan_high
          tap_action: toggle
  1. Fan setup is now complete!

  2. Back to the lights

  3. Create script for light control

scripts.yaml

ceiling_light
  sequence:
  - service: switch.turn_on
	data:
	  entity_id: switch.ceiling_light			  
  1. Create a template switch mapped to the the input boolean for light created in step 3. This is because the front end will not change colour of light to yellow when on for input booleans but will for template switches

switches.yaml

  - platform: template
	switches:
	  bedroom_ceiling_lights:
		value_template: "{{ is_state('input_boolean.bedroom_ceiling_lights', 'on') }}"
		turn_on:
		  service: input_boolean.turn_on
		  data:
			entity_id: input_boolean.bedroom_ceiling_lights
		turn_off:
		  service: input_boolean.turn_off
		  data:
			entity_id: input_boolean.bedroom_ceiling_lights
  1. Create automation to toggle the script.ceiling_light whenever the input_boolean state changes

  2. Add recorder line to customize.yaml to save previous state of input boolean during power cycle

customize.yaml

recorder:
  1. Create script that will toggle the input boolean for the lights should the system go out of synch. If someone turns the light on from the RF remote the system will go out of synch. The script will toggle the input boolean, the automation created above will also toggle the lights so we wait 1 second and toggle again. This is handy in a hidden folder

sequence:

  • service: input_boolean.toggle
    data:
    entity_id: input_boolean.bedroom_ceiling_lights
  • delay:
    seconds: 1
  • service: switch.turn_on
    data:
    entity_id: switch.ceiling_light
  1. OPTIONAL STEPS BELOW – I reset the fan and switches daily. I like to turn everything off at 11:00am because I do not need the fan or lights on at that time ever.

  2. Create script to toggle the fans 60 second timer which will turn off fans and light. Within the script we reset the 5 input booleans to the appropriate state

scripts.yaml

ceiling_fan_light_off
  sequence:
  - service: switch.turn_on
	data:
	  entity_id: switch.ceiling_fan_light_off
  - service: input_boolean.turn_off
	data:
	  entity_id:
		- input_boolean.bedroom_ceiling_lights
		- input_boolean.bedroom_fan_low
		- input_boolean.bedroom_fan_med
		- input_boolean.bedroom_fan_high
  - service: input_boolean.turn_on
	data:
	  entity_id:
		- input_boolean.bedroom_fan_off
  1. Create automation daily to call script from step 15

Example%201

1 Like

not to rain on your parade but…

I had almost exactly the same problem. I had a ceiling fan with an RF controller that didn’t update to HA. the solution I found (and seems to be an easier solution) was a new product from Sonoff:

I heard there were some issues with the fan speeds using it so I just ended up setting it up as a kind of “relay station” for my fan controller:

I used the broadlink to learn the original fan remote signals, then in HA i created a fan & light mqtt devices that when operated call an automation to switch the broadlink switches for the fan. Then I hid the original remote so that the sonoff is the only remote be used.

1 Like

Not raining on any parade it is good to see there are more options on the table. When I set this up several months ago there were limited ways to get a fan control through HA specifically in a single switch scenario without the use of Zigbee.

I haven’t dabbled into MQTT or sonoff as of yet but I am wondering why you need your Broadlink with the current solution? Doesn’t the sonoff handle everything?

In terms of my solution, it really is not that complicated, albeit a bit clunky. It works and it has been rock solid for 4 days.

The sonoff would handle everything but I’ve heard in other forums that the sonoff speed settings are a little off from what we are used to in the American market. So instead of going thru the trouble of rewiring my fan and finding out that I’m not happy with the speeds i figured I’d just use my current controller that I can already control with the broadlink and use the sonoff as a relay control.

And as a side benefit if the sonoff dies I’ll just dig the original remote out of its hiding spot and be back in business again immediately without having to do any re-wiring.

I had the same problem. Rf 433 fans (6 speed plus a light). To send the rf commands i use a esp8286 with openmqttgateway. As for the states of the fan I used a energy monitoring smart plug(xiaomi) so depending on the power consumption I know the speed and state of the light. So in the attic the fans are connected to a base socket where I can plug the smart plug.

Now the plugs don’t report the energy consumption immediately so takes about a minute to update the state. The xiaomi plugs are controlled via zigbee2mqtt so I hope in the future that update frequency can be increased.

This is really cool thanks for sharing. I have 5 fans in my house all controlled via rm pro. I was considering getting the sonoff but shuddered at the idea of dropping that money and also the 5x wiring for something that was so close to working. This is a perfect solution for me. 100 thanks sir.

The system has been working flawlessly for months with the only issue being the wife factor. She does not use home assistant and so she controls the fan via the RF fan remote control. While my system synchs itself daily, it gets out of synch frequently when my wife gets to the bedroom before me.

To solve for this pressing issue I purchased a GoControl scene switch (https://www.amazon.ca/GOCONTROL-LINWA00Z1-Z-Wave-Scene-Controller-Switch/dp/B01BKWG9XS/ref=sr_1_1?ie=UTF8&qid=1548944465&sr=8-1&keywords=gocontrol+z-wave+scene)

I have programmed the top button on a quick press to toggle the fan lights. The top button on a long press will toggle a hue bulb in a lamp we have in the room. Previously my wife would turn this lamp on and off via the switch which when in the off position leaves me unable to control the lamp.

The bottom button on a quick press will toggle through the various states of the fan (low - med - high - off). A long press of the bottom button will turn the fan off regardless of the current speed.

I have since hidden the RF remote from my wife but it is available should HA go down.

Happy to share my code if there is interest.

2 Likes