dhewg / esphome-miot

ESPHome components for MIoT devices
Other
16 stars 8 forks source link

Support for dmaker.fan.p18 and dmaker.fan.p33 #19

Open helgek opened 2 months ago

helgek commented 2 months ago

Hi,

I have here a dmaker.fan.p18 and a dmaker.fan.p33 (Mi Smart Standing Fan 2 and Mi Smart Standing Fan 2 Pro). Difference between the two is that one has a battery, otherwise they should be the same. The specs differ slightly though:

https://home.miot-spec.com/s/dmaker.fan.p18 https://home.miot-spec.com/spec?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p18:1

https://home.miot-spec.com/s/dmaker.fan.p33 https://home.miot-spec.com/spec?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p33:1

Screenshots of the app show that there are differences regarding accessible controls through the app. The control name for speed adjustment differs:

(dmaker.fan.p18 / Mi Smart Standing Fan 2) Screenshot_2024-04-13-02-48-56-74

(dmaker.fan.p33 / Mi Smart Standing Fan 2 Pro) Screenshot_2024-04-13-02-50-21-79

These are pictures of the dmaker.fan.p33 / Mi Smart Standing Fan 2 Pro version (for the other one I haven't done the sull teardown yet but I could see inside that it's an ESP-WROOM-02D for both):

image

image

Unlike the Air Purifier devices that are already supported in this project these fans don't seem to have an easily accessible UART port so one probably has to flash directly on the pins of the ESP-WROOM-02D.

I checked plenty of contacts combinations for continuity but for the ESP-WROOM-02D I could only find test points for IO13 and IO15 on the backside of the PCB (marked in the pictures above) + 3.3V and GND. My hope is that IO13 and IO15 would work if I use them in the ESPHome config:

uart: tx_pin: GPIO15 rx_pin: GPIO13 baud_rate: 115200

For Air Purifier 4 Lite the config looks like this:

uart: tx_pin: GPIO17 rx_pin: GPIO16 baud_rate: 115200

and the docucmentation (ESP32-­WROOM­-32D - https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32d_esp32-wroom-32u_datasheet_en.pdf) states this :

image

This is from the ESP-WROOM-02D documentation ( https://www.espressif.com/sites/default/files/documentation/esp-wroom-02u_esp-wroom-02d_datasheet_en.pdf ):

image

image

image

As a next step I will try backing up the original firmware and flashing the chip with ESPHome, starting with only a basic config and as a next step I would try if e.g. a switch added to the config would work. I'd be happy though if - in the meantime - maybe one of the pros here could share their opinion if these things I've summarized here make sense. Thank you!

helgek commented 2 months ago

Spend a night shift and I have good news: I was both able to do a backup of the original firmware, flash ESPHome and then I tried one test control in the config (power on/off) and the device does react to it 👍

This is the original firmware:

mi-smart-standing-fan-2-pro--dmaker.fan.p33-orignal-firmware.zip

The ESPHome log for this device shows many commands sent from the MCU to the ESP8266/ESP-WROOM-02D which should be additionally helpful to further complete the config with all possible controls.

This is the working ESPHome config with the first working controls (most essential controls already included):

external_components:
  source: github://dhewg/esphome-miot@main

esphome:
  name: mi-smart-standing-fan
  friendly_name: Xiaomi Mi Smart Standing Fan 2 Pro
  comment: Xiaomi Mi Smart Standing Fan 2 Pro (dmaker.fan.p33)
  project:
    name: "dhewg.esphome-miot"
    version: "dmaker.fan.p33"

esp8266:
  board: esp_wroom_02
  framework:
    version: recommended

logger:
  level: DEBUG

api:
  #encryption:
  #  key: !secret api_encryption_key
  reboot_timeout: 0s

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    password: !secret wifi_ap_password

captive_portal:

uart:
  tx_pin: GPIO15
  rx_pin: GPIO13
  baud_rate: 115200

miot:
  id: miot_main

button:
  - platform: "miot"
    miot_siid: 2
    miot_aiid: 1
    name: "Toggle Power"
    icon: mdi:power

switch:
  - platform: "miot"
    miot_siid: 2
    miot_piid: 1
    name: "Power"
    icon: mdi:power
  - platform: "miot"
    miot_siid: 4
    miot_piid: 1
    name: "Indicator Light"
    icon: mdi:power
  - platform: "miot"
    miot_siid: 5
    miot_piid: 1
    name: "Notification Sound"
    icon: mdi:power
  - platform: "miot"
    miot_siid: 7
    miot_piid: 1
    name: "Child Lock"
    icon: mdi:power

select:
  - platform: "miot"
    miot_siid: 6
    miot_piid: 1
    name: "Fan Blades turning direction"
    options:
      0: "Auto"
      1: "Left"
      2: "Right"
  - platform: "miot"
    miot_siid: 2
    miot_piid: 2
    name: "Fan Level"
    options:
      1: "Level 1"
      2: "Level 2"
      3: "Level 3"
      4: "Level 4"
  - platform: "miot"
    miot_siid: 2
    miot_piid: 3
    name: "Mode"
    options:
      0: "Straight Wind"
      1: "Natural Wind"
scrampker commented 1 month ago

I just bought the non-pro version based on this post and looking to flash the ESP. Did you end up soldering pig-tails to the chip to flash via USB-to-serial adapter?

If this works, this will be the only full-local smart tower fan that I'm aware of, and I have had nearly 7 of them. So far they all require cloud API integrations.

scrampker commented 1 month ago

Sure is a shame that these pins cannot be used :/

image

scrampker commented 1 month ago

I wired up to io13 and 15 on the back per your previous post, and I'm hoping that I can piggyback on the VDD5 and GND front the other controller in my above photo. I just need to dig out my serial to USB adapter and fiddle with it. Any tips? Would be so cool to build a full guide on this.

scrampker commented 1 month ago

I built up a little mount to hold pins/wires up against the ESP, and when I set my USB-to-Serial adapter to 3.3v and plug in, my port disappears immediately from my Windows PC, and the fan board just keeps chirping, about once every second.

My next test will be with the 12v plugged into the board. I was hoping to avoid this, just in case it could shoot it into my serial adapter.... somehow

image

helgek commented 1 month ago

@scrampker you should try it only using UART USB device connection, incl power coming from UART. This worked well for me. I used FTDI Chip based UART like this one https://amzn.eu/d/2w40Qh4 . Experience with it was much more stable than other noname chip UART that I used before. I'm traveling until the end of the week, I thought I had already posted the instructions how I successfully put the ESP into bootloader mode but it doesn't seem to be the case. I'll post it later. I think I kept notes about it.

scrampker commented 1 month ago

Oh that would be really cool. I'm using https://www.amazon.com/dp/B09F3196FB?psc=1&ref=ppx_yo2ov_dt_b_product_details which looks to be using a proper FTDI chipset. I tested a loopback to make sure it's working properly.

When I connect everything WITH the 12v base attached, the serial adapter does not crash. I believe what is happening is that the 3.3v line is pulling too much power for my serial adapter -- due to all the extra components being powered off that rail.

That being said, I tried using the UART0 TXD/RXD pins, and also the IO13/15 pins you reference in the yaml, but nothing seems to stick. It's been 3+ years since I've programmed an ESP device from a serial header, so I could be screwing up any number of things.

Your notes would be amazing, exactly which pins you used for each step. I'm trying to ground IO0 like it says to flash firmware, but no dice. Could even be that I'm not making sufficient contact with the pads. Did you solder directly to the chip, or were the underside contacts enough for everything?

Thanks so much!

scrampker commented 1 month ago

I finally got it connected. Here's what seemed to work, but I'm not 100% sure if I had a bad connection for other attempts or not.

Looking good so far. Time to re-assemble.

helgek commented 1 month ago

Congrats! Glad you got it to work. My yaml is work in progress as you probably noted already, it's not on top of my priority list at the moment since there are some other projects I want to complete before, but I will definitely continue on it in the later course of this year. Of course I'm happy if others join the yaml configuration work.

helgek commented 1 month ago

Because you asked how I flashed the chip. I bought PCBite from Sensepeek some time ago. I'm not capable of soldering and using this amazing equipment I was able to flash more than 10 devices, some of them had ESP pins which were extremely difficult to reach due to the PCB design. PCBite saved me. It's such a well designed toolset.

scrampker commented 1 month ago

Dang, that's pretty cool. Never seen it before, which is why I 3D printed my own pin-holder. I also was not confident in soldering such small pads without damaging the connection to the traces.

Word of warning to anyone else doing this.. the nut that attaches the motor housing to the base which allows it to tilt, (the tensioner,) is made out of extremely soft metal and stripped instantly. I have to find a suitable replacement at the hardware store. My guess is it was made out of aluminum.

scrampker commented 1 month ago

I do have to say, this build quality and features of this fan are pretty weak when you look at the sale price of $159. It's actually horrendous, and unforgiveable.

I have several of these $139 Dreo Pedestal fans that oscillate left/right and up/down, with temperature, and better algorithms for natural-feeling airflow. The only reason I don't have 20 of them in my house is because I have to rely on the cloud to control them. https://www.amazon.com/dp/B0BSH7YKHT?psc=1&ref=ppx_yo2ov_dt_b_product_details

All that being said, I'm very pleased to have flashed this ESP and have 100% local control. Not relying on the internet, or some greedy company that wants to charge for their API access.