Help with a fan and its speeds

Hello,

I have a Maxcio 400ML diffuser I would like to migrate from Tasmota to ESPHome.

As it is for the Tasmota template, I would like to use it as a fan.

dpID1 is for power and dpID103 for mist strength.
But the Maxcio diffuser has a strange conception.
When plugged in,:

  • dpID1=0
  • dpID103=0

Then dpID103=0 when switched on and mist strength is low, dpID103=1 when high.

But when switched off:

  • dpID1=0
  • dpID103=2

So if I use it in a tuya template, I have 3 speeds where the third is in fact off.
And for Google Assistant in HA, even when switched off it is returned as on because speed is not 0.

Is there a solution to use it as a ESPHome fan?
I thought about using a template output but I don’t succeed in understanding how I could do that with my device.
My goal is to avoid having too much switches and sensors in HA as it is the case with Tasmota, I wish to have only the fan and the water alert sensor.

I hop I have explained enough clearly the situation.

If it could help, here is the code.
I commented all tuya fan related code, which worked excepting for this max speed when switched off.

substitutions:
  piece: Bureau
  sufix: bureau

esphome:
  name: diffuseur-${sufix}
  platform: ESP8266
  board: esp01_1m
  project:
    name: "Nardol.maxcio_diffuser"
    version: "1.0.0"

#web_server:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_key
  ap:
    password: !secret ap_key

captive_portal:

api:
  password: !secret api_pass

ota:
  password: !secret ota_pass

uart:
  baud_rate: 9600
  tx_pin: GPIO1
  rx_pin: GPIO3

# debug:

logger:
  baud_rate: 0
  level: NONE

tuya:

binary_sensor:
  - platform: "tuya"
    name: Eau Diffuseur ${piece}
    id: eau_diffuseur_${sufix}
    sensor_datapoint: 12
    device_class: "problem"
  - platform: tuya
    name: ""
    id: power
    sensor_datapoint: 1
    internal: true

fan:
  #- platform: tuya
    #name: "Diffuseur ${piece}"
    #id: diffuseur_${sufix}
    #switch_datapoint: 1
    #speed_datapoint: 103
    #speed_count: 3
  - platform: speed
    output: fan_output
    name: "Diffuseur ${piece}"
    speed_count: 2

output:
  - platform: template
    id: fan_output
    type: float
    write_action:
      then:
          - lambda: -|
            if (state == 50) id(turbo).publish(false);
            else if (state == 100) id(turbo).publish(true);
        else:
          switch.turn_off: power

sensor:
  - platform: tuya
    name: ""
    id: turbo
    sensor_datapoint: 103
    internal: true
    #on_value_range:
      #above: 2
      #then:
        #- fan.turn_off: diffuseur_${sufix}

light:
  - platform: tuya
    name: Leds Diffuseur ${piece}
    id: leds_diffuseur_${sufix}
    dimmer_datapoint: 111
    switch_datapoint: 11
    min_value: 1