I have a more primitive setup, but it should be translatable. If you have the 4 levels you could use it as 4 percentiles, and use the templating language to extract and place the information, right?
Something along the lines of this should work
- platform: mqtt
name: "Nilan"
state_topic: "ventilation/control/RunSet"
command_topic: "ventilation/runset"
percentage_state_topic: "ventilation/control/VentSet"
percentage_value_template: >
{% if value == 1 %}
25
{% elif value == 2 %}
50
{% elif value == 3 %}
75
{% elif value == 4 %}
100
{% else %}
0
{% endif %}
percentage_command_topic: "ventilation/ventset"
qos: 2
retain: true
payload_on: "1"
payload_off: "0"
percentage_command_template: >
{% if value < 10 %}
0
{% elif value < 38 %}
1
{% elif value < 63 %}
2
{% elif value < 78 %}
3
{% else %}
4
{% endif %}
Disclaimer, there might be prettier solutions and the intermediate thresholds of 10,38,63,78 are just an example.
Here’s my initial attempt at converting… speed control not working though—open to suggestions (note the commented out parts are the old version—this is a 6-speed fan that was cobbled in HA as 3 speeds):
fan:
#Arlec wall fan (boy's bedroom)
- platform: mqtt
name: "Wall fan"
state_topic: "stat/arlec_fan/POWER1"
command_topic: "cmnd/arlec_fan/POWER1"
oscillation_state_topic: "stat/arlec_fan/POWER2"
oscillation_command_topic: "cmnd/arlec_fan/POWER2"
# speed_state_topic: "stat/arlec_fan/speed"
# speed_command_topic: "cmnd/arlec_fan/TuyaSend4"
percentage_state_topic: "stat/arlec_fan/speed"
percentage_command_topic: "cmnd/arlec_fan/TuyaSend4"
percentage_value_template: >-
{% if value == '3,0' %}
16
{% elif value == '3,1' %}
33
{% elif value == '3,2' %}
50
{% elif value == '3,3' %}
67
{% elif value == '3,4' %}
83
{% elif value == '3,5' %}
100
{% endif %}
percentage_command_template: >-
{% if value < 17 %}
'3,0'
{% elif value < 34 %}
'3,1'
{% elif value < 51 %}
'3,2'
{% elif value < 68 %}
'3,3'
{% elif value < 84 %}
'3,4'
{% else %}
'3,5'
{% endif %}
qos: 0
payload_on: 'ON'
payload_off: 'OFF'
payload_oscillation_on: 'ON'
payload_oscillation_off: 'OFF'
# payload_low_speed: '3,0'
# payload_medium_speed: '3,1'
# payload_high_speed: '3,5'
availability_topic: tele/arlec_fan/LWT
payload_available: Online
payload_not_available: Offline
# speeds:
# - 'off'
# - low
# - medium
# - high
Thanks for the heads up. My setup works correctly from the physical switch (i.e. if I change the fan speed it changes in home assistant correctly). It just does not change if I go the other way (i.e. home assistant to the physical switch). That is what leads me to believe that the preset_mode_command_template is wrong.
I’ve requested that the old speed list options should be kept and I’ve had a suggestion from a dev that if a FR gets enough votes they would implement it.
I have an MQTT fan which is running out of time before needing a code change due to the deprecated fan speeds. I’m guessing the FR to not remove the old speed system isn’t going to happen so could someone please help me convert this? (it was pretty much copy / pasted from a tutorial)
I actually don’t yet have it working properly. I updated things as per the blog post linked above but the functionality isn’t quite right on my device / HA
If you have the exact fan controller as per that blog post then you can only get max 3 speeds as that is how the hardware is built. No software can change that.