How to streamline UI fan controls?

Hi, I’ve recently dipped a toe into using home assistant, and have set it up to control our RF fans, lights and blinds via a broadlink rm pro, and integrating the controls into apple home so they can also be controlled via Siri.

My fans are setup as switches as they send the same RF command for on/off, then I have scripts to execute the RF commands for the various fan speeds and to also ensure the state of the fan is displayed as on if the fan is started via one of the speed commands (otherwise on/off just resumed the last used speed).

I’ve seen a couple of examples of other people’s fan controls which look great, but I can’t figure out how to emulate them… is anybody able to point me in the right direction please?

Here’s how mine look now…

And how I’d like them to work…
ha-fan-control
902ab9f1510ef9f8ac66a529cb5034a39a2dbaee

Thank you

You have a number of options.

  1. Using a slider with 4 positions you could use the custom:slider-entity-row card and an automation triggered on the slider or switch to set the fan speed (templates involved if you dont want multiple automations). You could actually do this with the standard input_number component but you wouldn’t have the toggle switch to turn it off. Just slide the slider down to 0.

  2. Use the custom:tiles-card to create the row of four buttons to call scripts to set the fan speed.

Do you wan to use the buttons or slider?

Do you need to have a toggle switch to turn it off if using the slider or are you happy just to slide it to 0 (this is the easiest solution)?

I have rf fans also(6 speed) and comes with a light. In my case for sending the rf commands I use openmqttgateway. As for the fans entities I use the template fan one with a combination of input_number and input_boolean for the state and some scripts that fire the mqtt command according to speed. I can post later on the template fan yaml so you get the idea and you can adapt it to your setup.

As for having a 6 speed fan displayed in Lovelace I use a custom card that’s being around the forum.

2 Likes

Nice. I hadn’t seen that card before. Much better solution.

I actually just ended up converting over a basic fan I had set up in HA when I originally started using it A LONG time ago. It had just been a bank of four switches that I had set up automations for to toggle the broadlink switches back off after I changed the fan speeds. The fan is now converted to a proper “fan” in the HA sense of the word.

And with that to get my version of the fan card to work from that other thread I just had to make a change to pick up the “off” speed state. It wasn’t turning off and it was giving me an error.

I’m starting a new thread to split my config away from the other thread and it has a link to a package of fans to use as a template for anyone who wants to use it.

Here is the link to the thread I just started:

This one of my template fan definition

- platform: template
  fans:
    masterbedroom:
      friendly_name: "Master Bedroom"
      value_template: "{{ states('input_boolean.masterbedroom_fan_state') }}"
      speed_template: "{{ states('input_select.masterbedroom_fan_speed') }}"
      turn_on:
        service: script.fan_on
        data_template:
          name: "masterbedroom"
      turn_off:
        service: script.fan_off
        data_template:
          name: "masterbedroom"
      set_speed:
        service: script.fan_set_speed
        data_template:
          speed: "{{ speed }}"
          name: "masterbedroom"
      speeds:
        - '0'
        - '1'
        - '2'
        - '3'
        - '4'
        - '5'
        - '6'

This is the set_speed script which is generic for all 4 fans

alias: fan set speed
sequence:
  - service: input_select.select_option
    data_template:
      entity_id: input_select.{{name}}_fan_speed
      option: '{{speed}}'
  - service: mqtt.publish 
    data_template:
      topic: >-
        {% if name == "masterbedroom" %}
          {% if speed | int == 1  %}
            home/OpenMQTTGateway/commands/PLSL_336/433_8/RFBITS_12
          {% elif speed | int <= 4 %}
            home/OpenMQTTGateway/commands/PLSL_337/433_8/RFBITS_12
          {% elif speed | int == 5 %}
            home/OpenMQTTGateway/commands/PLSL_338/433_8/RFBITS_12
          {% elif speed | int == 6 %}
            home/OpenMQTTGateway/commands/PLSL_337/433_8/RFBITS_12
          {% endif %}
        {% elif name == "lounge" %}
          {% if speed | int >= 1  %}
            home/OpenMQTTGateway/commands/PLSL_332/433_8/RFBITS_12
          {% endif %}
        {% elif name == "olivia" %}
          {% if speed | int >= 1  %}
            home/OpenMQTTGateway/commands/PLSL_342/433_8/RFBITS_12
          {% endif %}
        {% elif name == "javier" %}
          {% if speed | int >= 1  %}
            home/OpenMQTTGateway/commands/PLSL_335/433_8/RFBITS_12
          {% endif %}
        {% endif %}
      payload_template: >-
        {% if name == "masterbedroom" %}    
          {% if speed | int == 1  %}
            1143
          {% elif speed | int == 2 %}
            1141
          {% elif speed | int == 3 %}
            1135
          {% elif speed | int == 4 %}
            1127
          {% elif speed | int == 5 %}
            1117
          {% elif speed | int == 6 %}
            1119
          {% endif %}
        {% elif name == "lounge" %}
          {% if speed | int == 1  %}
            119
          {% elif speed | int == 2 %}
            117
          {% elif speed | int == 3 %}
            111
          {% elif speed | int == 4 %}
            103
          {% elif speed | int == 5 %}
            93
          {% elif speed | int == 6 %}
            95
          {% endif %}
        {% elif name == "olivia" %}
          {% if speed | int == 1  %}
            375
          {% elif speed | int == 2 %}
            373
          {% elif speed | int == 3 %}
            367
          {% elif speed | int == 4 %}
            359
          {% elif speed | int == 5 %}
            349
          {% elif speed | int == 6 %}
            351
          {% endif %}
        {% elif name == "javier" %}
          {% if speed | int == 1  %}
            631
          {% elif speed | int == 2 %}
            629
          {% elif speed | int == 3 %}
            623
          {% elif speed | int == 4 %}
            615
          {% elif speed | int == 5 %}
            605
          {% elif speed | int == 6 %}
            607
          {% endif %}
        {% endif %}
  - service: input_boolean.turn_on
    data_template:
      entity_id: input_boolean.{{name}}_fan_state

You should adapt yours here to the broadlink commands

2 Likes

Thank you all for your help, I haven’t had time to go back to this yet but have plenty of good information to work with now :slight_smile:

Could you please explain how you expanded the card to show the 6 numeric buttons instead of the low-med-high buttons, and how you changed the off button to a toggle?

I initially tried modifying your code but was unable to understand what the MQTT section does or how to change this for my broadlink.

Instead I’ve managed to implement the control as per the instructions by @finity and it works well with my broadlink commands, but when I try to add additional speed settings and change them to numeric values it all stops working.

Thank you

If you follow the link above to the thread for my code there is a further link there to a fan_package.yaml that has an example of how to set up a RF controlled fan using a Broadlink RM Pro.

The code is pretty extensive to get it set up as a “fan” entity and to work with the Fan Control Entity Row but it’s doable.

Once you get your fan set up as a HA “fan” entity then making further changes to get it to work with more buttons is also possible.

This is the fan card modified for me for 6 speed

AFAIK that is part of the fan entity itself. If there is a state topic or entity to fetch the state from, unless is optimistic. If I list the fan in an normal lovelace entity card it shows like this

Say you have 4 different broadlink switches (rf commands) for each of the 4 speeds, I will have the set speed command script like this

alias: fan set speed
sequence:
  - service: input_select.select_option
    data_template:
      entity_id: input_select.{{name}}_fan_speed
      option: '{{speed}}'
  - service: switch.turn_on
    data_template:
      entity_id: >-
        {% if speed | string == "1"  %}
          switch.{{name}}_fan_1
        {% elif speed | string == "2" %}
          switch.{{name}}_fan_2
        {% elif speed | string == "3" %}
          switch.{{name}}_fan_3
        {% elif speed | string == "4" %}
          switch.{{name}}_fan_4
        {% endif %}
  - service: input_boolean.turn_on
    data_template:
      entity_id: input_boolean.{{name}}_fan_state

So each broadlink switch will be named switch.lounge_fan_1, switch.lounge_fan_2, etc

Wondering if you could provide some advice for my Broadlink fans? I have two ceiling fans that are dumb but I can turn them on and off and set speeds using Broadlink but with no feedback. With the help of @tom_l, I created a template sensor that provides an off/on state based on the monitored power use by a Shelly PM1.

But then @swiftlyfalling suggested a fan template which I’d never heard of and I found your thread. I’m wondering if you can look at the code below and provide feedback on the fan template code required? It looks like your script is fine and I should be able to adapt that.

switch:
  - platform: broadlink
    host: !secret broadlink_ip
    mac: !secret 'broadlink_mac'
    timeout: 15
    switches:
      master_bedroom_fan_1:
        friendly_name: Master Fan Level 1
        command_on: 'abunchofnumbersandlettersandothersymbols'
        command_off: 'abunchofnumbersandlettersandothersymbols'
      master_bedroom_fan_2:
        friendly_name: Master Fan Level 2
        command_on: 'abunchofnumbersandlettersandothersymbols'
        command_off: 'abunchofnumbersandlettersandothersymbols'
      master_bedroom_fan_3:
        friendly_name: Master Fan Level 3
        command_on: 'abunchofnumbersandlettersandothersymbols'
        command_off: 'abunchofnumbersandlettersandothersymbols'
input_select:
  master_fan:
    name: Master Bedroom Fan
    options:
      - 'Off'
      - '1'
      - '2'
      - '3'
    # initial: 'Off'
    icon: mdi:fan