PLEASE HELP WITH Fan Configuration

I ask very nicely and also urgently for help with the aroma diffuser Christmas gift
My Aroma diffuser requires the following ventilator configuration

fan:
  - platform: mqtt
    name: "Difuzér"
    icon: "mdi:smoke"
    state_topic: "stat/aroma_difuzer/RESULT"
    state_value_template: "{% if value_json.POWER1 is defined %}{{ value_json.POWER1 }}{% endif%}"
    command_topic: "cmnd/aroma_difuzer/POWER1"
    preset_modes:
      - "2h timer"
      - "4h timer"
      - "timer off"
    preset_mode_state_topic: "stat/aroma_difuzer/timer"
    preset_mode_command_topic: "cmnd/aroma_difuzer/tuyaenum2"
    preset_mode_command_template: >-
      {% if value == "2h timer" %}
        {{ 0 }}
      {% elif value == "4h timer" %}
        {{ 1 }}
      {% else %}
        {{ 2 }}
      {% endif %}
    percentage_state_topic: "stat/aroma_difuzer/fanmode"
    percentage_value_template: >-
      {% if value == "low" %}
        {{ 1 }}
      {% elif value == "medium" %}
        {{ 2 }}
      {% elif value == "high" %}
        {{ 3 }}
      {% else %}
        {{ 0 }}
      {% endif %}
    percentage_command_topic: "cmnd/aroma_difuzer/event"
    percentage_command_template: >-
      {% if value == 1 %}
        {{ 'fanmode=1' }}
      {% elif value == 2 %}
        {{ 'fanmode=0' }}
      {% elif value == 3 %}
        {{ 'fanmode=2' }}
      {% else %}
        {{ 'fanmode=-1' }}
      {% endif %}
    speed_range_max: 3
    availability_topic: "tele/aroma_difuzer/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    unique_id: "fan-diffuser"

select:
  - platform: mqtt
    name: "Diffuser Color Mode"
    command_topic: "cmnd/aroma_difuzer/event"
    state_topic: "stat/aroma_difuzer/colormode"
    options:
      - "solid"
      - "cycle"
    availability:
      - payload_available: "Online"
        payload_not_available: "Offline"
        topic: "tele/aroma_difuzer/LWT"
    unique_id: "select-livingroom-diffueser-color-mode"

binary_sensor:
  - platform: mqtt
    name: "Difuser Error"
    state_topic: "stat/aroma_difuzer/error"
    value_template: "{{ 'ON' if value != '0X00' else 'OFF' }}"
    device_class: problem
    availability_topic: "tele/aroma_difuzer/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    unique_id: "binary-diffueser-error"
    



The lovelace card that I want to control the fan again requires this code :

fan:
  - platform: mqtt  
    name: "Aroma Difuzér"
    command_topic: "cmnd/aroma_difuzer/FanSpeed"
    speed_command_topic: "cmnd/aroma_difuzer/FanSpeed"    
    state_topic: "stat/aroma_difuzer/RESULT"
    speed_state_topic: "stat/aroma_difuzer/RESULT
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.master_bedroom_fan.state == 'off' -%}0{%- elif states.fan.master_bedroom_fan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/aroma_difuzer/LWT
    payload_off: "0"
    payload_on: "4"
    payload_low_speed: "1"
    payload_medium_speed: "2"
    payload_high_speed: "3"
    payload_available: Online
    payload_not_available: Offline
    speeds:
      - "off"
      - low
      - medium
      - high

Respectively, I need using card:

Control from lovelace this aroma diffuser :

Thank you in advance for your amazing strength of help.

don’t use the fan-control-entity-row plugin.

use either the fan-percent-button-row or fan-preset-button-row available from the same github user (me :wink:)

the fan-control-entity-row is only for previous versions of HA that used fan speeds and not percentages/presets.

Thank you.
That’s good.
But my aroma diffuser doesn’t even listen to this card (doesn’t accept)

I have no idea what that means.

is the diffuser entity a “fan.xxx”?

and does it use percent speeds or preset modes to control it when you open it up in the frontend?

Yes. It’s a fan domain.

Your questions are best answered by the fan configuration:

fan:
  - platform: mqtt
    name: "Diffuser"
    icon: "mdi:smoke"
    state_topic: "stat/%topic%/RESULT"
    state_value_template: "{% if value_json.POWER1 is defined %}{{ value_json.POWER1 }}{% endif%}"
    command_topic: "cmnd/%topic%/POWER1"
    preset_modes:
      - "2h timer"
      - "4h timer"
      - "timer off"
    preset_mode_state_topic: "stat/%topic%/timer"
    preset_mode_command_topic: "cmnd/%topic%/tuyaenum2"
    preset_mode_command_template: >-
      {% if value == "2h timer" %}
        {{ 0 }}
      {% elif value == "4h timer" %}
        {{ 1 }}
      {% else %}
        {{ 2 }}
      {% endif %}
    percentage_state_topic: "stat/%topic%/fanmode"
    percentage_value_template: >-
      {% if value == "low" %}
        {{ 1 }}
      {% elif value == "medium" %}
        {{ 2 }}
      {% elif value == "high" %}
        {{ 3 }}
      {% else %}
        {{ 0 }}
      {% endif %}
    percentage_command_topic: "cmnd/%topic%/event"
    percentage_command_template: >-
      {% if value == 1 %}
        {{ 'fanmode=1' }}
      {% elif value == 2 %}
        {{ 'fanmode=0' }}
      {% elif value == 3 %}
        {{ 'fanmode=2' }}
      {% else %}
        {{ 'fanmode=-1' }}
      {% endif %}
    speed_range_max: 3
    availability_topic: "tele/%topic%/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    unique_id: "fan-diffuser"

select:
  - platform: mqtt
    name: "Diffuser Color Mode"
    command_topic: "cmnd/%topic%/event"
    state_topic: "stat/%topic%/colormode"
    options:
      - "solid"
      - "cycle"
    availability:
      - payload_available: "Online"
        payload_not_available: "Offline"
        topic: "tele/%topic%/LWT"
    unique_id: "select-livingroom-diffueser-color-mode"

binary_sensor:
  - platform: mqtt
    name: "Difuser Error"
    state_topic: "stat/%topic%/error"
    value_template: "{{ 'ON' if value != '0X00' else 'OFF' }}"
    device_class: problem
    availability_topic: "tele/%topic%/LWT"
    payload_available: "Online"
    payload_not_avail: "Offline"
    unique_id: "binary-diffueser-error"

I saw that already. And it looks like you can use either percents or presets.

but it still doesn’t answer:

I don’t know what you mean by this?

I can already change the intensity level (speed) and presets (timers).
Speed is enough for me three values: 33 - 66 - 100. So I’d appreciate the buttons rather than the slider.
I also wanted to change the color of the active preset buttons - this is not possible.
I don’t know why I have so many problems, probably due to the unconventional Fan configuration

Thank you.

you still haven’t answered this question yet.

I don’t understand what kind of answer you’re expecting…

type: custom:fan-percent-button-row
entity: fan.difuzer
name: Aroma Difuzer
reverseButtons: false
customTheme: true
customSetpoints: true
lowPercentage: '33'
medPercentage: '66'
hiPercentage: '100'
isOnLowColor: '#CCFF99'
isOnMedColor: '#888888'
isOnHiColor: '#222222'
buttonInactiveColor: '#202020'
isOffColor: red
customLowText: Slabě
customMedText: Středně
customHiText: Silně
customOffText: 'OFF'
width: 50px
height: 46px

The answer I was expecting was demonstrated in the video. Thanks for that.

Could you look in the “states” section of the developers tools for that fan and tell me what the “speed” & “percentage” attributes are when you change the speeds with the slider (not the card)?

like this:

What I think is possibly happening is that your percentages are being set to 0,1,2,3 in the config and the built-in slider uses those numbers but the card config is using 33,66,100 for the settings. And since the two don’t match it can’t work.

What does it look like when it is actually on each of the three speeds?

That’s the mystery. It only changes. On - Off.
There are two hw buttons on the device, from the home assistant I am able to control the mqtt device exactly the same. But when I want to use some services from HA as a fun.xxx turn_on (turn-off). The device does not respond to these commands at all.

TBH, I have zero experience with any tuya fans so I’m not sure how the integration interacts with HA and the fan integration.

Unfortunately until you get the fan control worked out to work with the HA fan services then none of my plugins will work for you since my plugins just use the built-in services with a different UI.

Thank you for your time and patience.
I’m going to look for what else I need to do…

1 Like

You’re welcome. Sorry I couldn’t help any more.

succeeded
solved - works as a percentage
Thanks.

I would also like to ask:
I have set up

    preset_modes:
      - "2h timer"
      - "4h timer"
      - "timer off"

a percentage state topic

    percentage_state_topic: "stat/aroma_difuzer/fanmode"
    percentage_value_template: >-
      {% if value == "low" %}
        {{ 1 }}
      {% elif value == "medium" %}
        {{ 2 }}
      {% elif value == "high" %}
        {{ 3 }}
      {% else %}
        {{ 0 }}
      {% endif %}

and speed shows me the preset mode - see picture
is that correct or is there still a mistake?

Again, I’m not sure how the presets are supposed to look in the interim between the speed list and the percentages.

It seems they are just adding everything to the speed list.

But if it’s working I wouldn’t mess with it any more if it was me.