Mqtt fan component only supports 3 speed

The mqtt fan component only handle 3 speed

speeds
(string | list)(Optional)

List of speeds this fan is capable of running at. Valid entries are off, low, medium and high.

I’ve tuyu converted a fan with 6 speeds.

If there was a CONFIGURATION VARIABLE payload_speed_template, then it could be passed the speed, and parse it for the correct payload, handling any number of speeds.
Something like this:

  speeds:
    - '1'
    - '2'
    - '3'
    - '4'
    - '5'
    - '6'
    - breeze
  payload_speed_template:  >-
    {% if speed | string == "1"  %}
      '3,0'
    {% elif speed | string == "2" %}
      '3,1'
    {% elif speed | string == "3" %}
      '3,2'
    {% elif speed | string == "4" %}
      '3,3'
    {% elif speed | string == "5" %}
      '3,4'
    {% elif speed | string == "6" %}
      '3,5'
    {% elif speed | string == "breeze" %}
      '3,9'
    {% endif %}

There is an open architecture issue for this:

@diramu

I just set speed as per code below

   speeds:
    - '3,1'
    - '3,2'
    - ',33'
    - '3,4'
    - '3,5'
    - '3,6'
    - '3,7'

Assuming of course that speed command topic is TuyaSend4

speed_command_topic: "cmnd/bedroom_fan/TuyaSend4"

That’s interesting. Thanks. I might go revisit this (at some point).

Hey @Bartosz_Morawiec,

I tried your method and it’s works as advertised :slight_smile:
Do have this syncing back to the UI? I suppose a tasmota rule to publish this same 3,1 result might work?

Cheers

Linton

Hey @diramu,

@dgwynne had a pull request with a similar method with a speed_command_template. I’ve been speaking to him a bit lately as I find myself in the same boat and it’s working well for him.

I’ve tried to override the built in component as a custom_component without success but maybe that’s our best shot - a custom mqtt fan.

Ultimately it surprised a method similar to yours or David’s hasn’t already been implemented.

FTR I tried dropping fan.py into config/custom_components/mqtt/ with and without an empty init.py file. Others seemed to have done this more successfully.

mqtt could now be updated to support additional speeds as the fan entity model has changed to allow up to 100 speeds (previously only 3 were allowed) and preset modes.

I have been following the update of the fan entity model. I would love to see the MQTT fan getting support for percentage. For now through after this change auto discovery the speeds variable will still populate the speed list box other values than off, low, medium or high, but an error will follow if you select any of these. Since the speeds variable now is deprecated, we need to make use of the new percentage and preset_modes features in the MQTT context as well. A set_percentage_topic should be settable through the config topic to make auto discovery possible.
To replace the deprecated speeds variable we also need a way to set preset_modes to be configured through MQTT auto discovery as well.
The existing speed_state_topic and speed_value_template variables should be there in a way they can also help to report back the actual preset_mode or percentage and present the reported state using a template.