MQTT Fan speed issue

I am having problem in setting up mqtt fan. When change the fan speed from the UI, I notice HA will publish 2 topics simultaneously; the on command and speed command. Is there anyway to change that? I just need it to publish the speed command without the on command when I change speed.

If you put it to optimistic mode HA is assuming that controls are working and does not need to publish/subcribe the state.

optimistic (Optional): Flag that defines if lock works in optimistic mode. Default is true if no state topic defined, else false.

This is not true. For a given command from the front end, HA will still publish whatever commands it is set up to publish, in this case speed and on. Optimistic mode true tells HA not to wait for an update on a state topic before changing the state in the system - eg you give the command speed 40, HA will assume the speed is 40 and the fan is on.

thanks for everyone replies. please allow me to elaborate further.

All the fans in my home are dumb fans with IR remote control. Right now, I use the Broadlink RM Switch component to control them. The issue is each buttons on the remote control are consider as a switch entity in HA. For example, one of the fans has 5 switches; 1 switch for on/off, 3 switches for speed (low, medium and high) and 1 switch for oscillation. It would cleaner if I can streamline it so that one fan has only one entity.

Also this should provide better control for Alexa. Right now, to change the fan speed, I have to say “Alexa, turn on low fan”. Better command should be “Alexa, set fan speed to low”.

That is why I am thinking of changing the control of my fans using the MQTT fan component.

Any idea on how to make this works?

Are you using dumb fans? If so you’ll need to design an mqtt interface for them (ie with an esp8266) that accepts mqtt messages and sends IR to the fan.

that’s one way. but i already have Broadlink RM mini 3.

what i did initially is using automation in HA to turn on the switch. Example…

fan:
  - platform: mqtt
    name: "Wall Fan"
    command_topic: "home/mqttfan/power/office_wall_fan_power/set"
    payload_on: "on"
    payload_off: "off"

the automation:

- alias: 'MQTT Fan Control - Power'
  initial_state: 'on'
  trigger:
    platform: mqtt
    topic: home/mqttfan/power/+/set
  action:
    - service_template: >
        switch.turn_{{trigger.payload}}
      data_template:
        entity_id: >-
          switch.{{ trigger.topic.split('/')[-2] }}

To answer your initial question: no, I don’t think there is any way to prevent HA from sending an on command with a speed command.

Guys, I found the solution to my needs with this custom component Broadlink IR Climate Component