acvigue / esphome-levoit-air-purifier

ESPHome custom component for Levoit branded smart WiFi air purifiers
https://vigue.me/
Other
31 stars 8 forks source link

What would be needed to add support for other Levoit air purifiers? #5

Open andreklug opened 5 months ago

andreklug commented 5 months ago

Hi,

I've got the Levoit Vital 100S and 200S devices. I am very keen to use them with esphome. I am more than happy to disassemble them and do some soldering.

Could you please outline the steps that I would need to do in order to provide all information you'd need to add support for these devices as well?

Thank you!

acvigue commented 5 months ago

Hi @andreklug ! Please upload high resolution photos of the control board. It should have an ESP32 module or something similar.

It may be as simple as adding support via a line of code, however the protocol may be completely different :/

andreklug commented 5 months ago

Here you go:

Levoit Vital 100S, will disassemble the 200 next.

Mittel (IMG_0300) Mittel (IMG_0301)

acvigue commented 5 months ago
Screenshot 2024-06-09 at 6 44 39 PM

This board please

andreklug commented 5 months ago

oh that was stupid. Anyway, I am awake now:

grafik grafik grafik

andreklug commented 5 months ago

a bit further information:

(to get this this into download mode, IO0 needs to be connected to ground when powering up / connecting to UART adapter)

This is how the device identifies itself:

esptool.py v4.7.0
Serial port /dev/cu.usbserial-0001
Connecting....
Detecting chip type... ESP32-C3
Chip is ESP32-C3 (QFN32) (revision v0.4)
Features: WiFi, BLE, Embedded Flash 4MB (XMC)
Crystal is 40MHz

I would now try your code as is to see if it already works. But as I have only been using esphome to flash precompiled stuff, I have no idea where to start compiling it. Would you mind giving me a short explaination?

Thank you!

acvigue commented 5 months ago

Sample config is given in repo - it will pull this code and compile for you

andreklug commented 5 months ago

Thank you. I created and adpated the config file. Deleted the flash and wrote it to the board. Setting the board to a generic ESP32-C3 compiles just fine, however the serial monitor shows "rst: 0x10 (RTCWDT_RTC_RST),boot:0xd (SPI_FLASH_BOOT) and then many lines of "invalid header: 0xffffffff".

I tried another C3 board and git this config error:

INFO ESPHome 2024.5.5
INFO Reading configuration /config/esphome/luftfilter-buro.yaml...
Failed config

uart: [source /config/esphome/luftfilter-buro.yaml:38]
  - 
    This pin cannot be used on ESP32-C3s and is already used by the SPI/PSRAM interface (function: SPIQ).
    tx_pin: GPIO17

    This pin cannot be used on ESP32-C3s and is already used by the SPI/PSRAM interface (function: SPID).
    rx_pin: GPIO16
    baud_rate: 115200

I guess the next step would be to identify the correct GPIO pin. Any hint how to do this?

EDIT: GPIOs are GPIO21 for TX and GPIO20 for RX

acvigue commented 5 months ago

Please upload full redacted with config

andreklug commented 5 months ago

In this very second I am trying the more generic "esp32dev" board. Here's the config:

esphome:
  name: "luftreiniger-buero"
  friendly_name: "Luftreiniger Büro"

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_FREERTOS_UNICORE: y

external_components:
  - source: github://acvigue/esphome-levoit-purifier
    components: [levoit]

logger:
  baud_rate: 115200

# Enable Home Assistant API
api:
  encryption:
    key: "REDACTED"

ota:
  password: "REDACTED"

wifi:
  networks:
    - ssid: !secret wifi_ssid_btst
      password: !secret wifi_password_btst

  ap:
    ssid: "LR-Buero Fallback"
    password: !secret ap_password

captive_portal:

uart:
  tx_pin: GPIO21
  rx_pin: GPIO20
  baud_rate: 115200

levoit:
  id: levoit1

fan:
  - platform: levoit
    name: Levoit Purifier

sensor:
  # Uptime sensor.
  - platform: uptime
    name: Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s

  # PM2.5 sensor
  - platform: levoit
    pm_2_5:
      name: PM2.5
    air_quality:
      name: Air Quality Index

switch:
  - platform: levoit
    display_lock:
      name: "Display Lock"
    display_on:
      name: "Display On"
    power:
      name: "Master Power"

select:
  - platform: levoit
    fan_mode:
      name: "Fan Mode"
    auto_mode:
      name: "Auto Mode"
andreklug commented 5 months ago

esp32dev as board results in the "invalid header" error.

acvigue commented 5 months ago

It should be the same board as the one I used edit: nevermind "esp32-c3-devkitc-02"

andreklug commented 5 months ago

no luck...

grafik
andreklug commented 5 months ago

This is what I can select for C3:

grafik
andreklug commented 5 months ago

So I tried esp32-c3-devkitc-02 (not found), devkitm1, m1i-kit. After a successful upload, both are returning this:

rst:0x10 (RTCWDT_RTC_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fcd5810,len:0x1684
ets_loader.c 78 
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x40049a42
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fcd5810,len:0x1684
ets_loader.c 78 

and this loops.

acvigue commented 5 months ago

Do you have a dump of the original firmware

andreklug commented 5 months ago

yes, you want me to share it?

acvigue commented 5 months ago

yes

andreklug commented 5 months ago

levoit.bin.zip

acvigue commented 5 months ago

Please also upload the binary you are attempting to flash to the device. Since it contains encryption keys & such, you may email it to me if you'd like...

I'm checking the image header to see if there's anything out of the ordinary

acvigue commented 5 months ago
~ ❯ esptool.py image_info Downloads/levoit.bin --version 2
esptool.py v4.7.0
File size: 4194304 (bytes)
Detected image type: ESP32-C3

ESP32-C3 image header
=====================
Image version: 1
Entry point: 0x403ce000
Segments: 3
Flash size: 4MB
Flash freq: 80m
Flash mode: DIO

ESP32-C3 extended image header
==============================
WP pin: 0xee (disabled)
Flash pins drive settings: clk_drv: 0x0, q_drv: 0x0, d_drv: 0x0, cs0_drv: 0x0, hd_drv: 0x0, wp_drv: 0x0
Chip ID: 5 (ESP32-C3)
Minimal chip revision: v0.0, (legacy min_rev = 3)
Maximal chip revision: v0.0

Segments information
====================
Segment   Length   Load addr   File offs  Memory types
-------  -------  ----------  ----------  ------------
      1  0x011c4  0x3fcd6100  0x00000018  DRAM, BYTE_ACCESSIBLE
      2  0x008a8  0x403ce000  0x000011e4  IRAM
      3  0x02ca0  0x403d0000  0x00001a94  IRAM

ESP32-C3 image footer
=====================
Checksum: 0x5d (valid)
Validation hash: db2ef7e43fbc89495281279dbd0ef193adca7a40ab28a34b67d3839f6113d226 (valid)
SeveranExp commented 3 weeks ago

@acvigue hey friend, are you still willing to work on this firmware?

moimeme81 commented 3 weeks ago

@acvigue hey friend, are you still willing to work on this firmware?

I was wondering the same. @andreklug anything new on your side?