acvigue / esphome-levoit-air-purifier

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

Levoit core400s support #1

Closed ryan-lang closed 9 months ago

ryan-lang commented 1 year ago

I wasn't sure if you had plans to merge your work with main, but I thought I'd contribute my additions, in case you were interested.

I have a Core 400s, and some payloads seem to have changed a little bit. Most of the changes are to support multiple device models. I also had some issues with frequent NACKs, and to address this, I increased the COMMAND_DELAY time, and disabled the WiFi light toggling. I believe the MCU just isn't keeping up fast enough.

Everything I changed should be non-breaking for the 300s. To use the 400s changes, a "model" configuration value must be provided.

Scags104 commented 10 months ago

Would love 200s support. i was able to flash mine with ESPhome but having some issues controlling it on anything other than HIGH or Sleep.

Let me know what is needed from my end to contribute. Hopefully this project is not dead!

ryan-lang commented 10 months ago

@Scags104 It's likely you'd need some sort of logic analyzer to eavesdrop on the rx/tx pins, and see what's actually being sent and received when you issue commands from the app. That was how I was able to reverse engineer the 400s differences.

Scags104 commented 10 months ago

Happy to do all of that if you provide the logic analyzer you used

ryan-lang commented 10 months ago

I have a Saleae Logic 8, which worked very well for this. Aiden (the original author of this project) has a good writeup on his process here:

https://vigue.me/posts/levoit-air-purifier-esphome-conversion

Scags104 commented 10 months ago

I have a Saleae Logic 8, which worked very well for this. Aiden (the original author of this project) has a good writeup on his process here:

https://vigue.me/posts/levoit-air-purifier-esphome-conversion

That's quite expensive. Was hoping there was a software that could do that when hooked into tx/rx on the board to serial USB while on mains power or something... Guess not...

haydonryan commented 9 months ago

@acvigue Just wondering if you're still looking to support this repo?

I was considering doing this to my two purifiers, both 300s. Would love an update on your experience and how they're running.

acvigue commented 9 months ago

To all, I am so sorry. I didnt get any notifications until I was mentioned!! I will take a look at this later today or tomorrow 😁

Scags104 commented 9 months ago

@acvigue similarly to @ryan-lang did you use a logic analyzer? i would love to contribute and get the 200s model as part of this. If there is another way to grab the commands would love some instructions.

Tried wireshark but so far nothing....

haydonryan commented 9 months ago

@acvigue A few more questions if you don't mind. Love the work you've done here and want to replicate it / test and help.

Would you consider:

  1. Instead of forking ESPHome, Have this as a standalone repo. My ratdgo garage doors just pull in a package from github: (https://github.com/ratgdo/esphome-ratgdo) vs clone the entire ESPhome repo. Which allows this to be compiled into the docker hosted ESPhome UI without needing to clone / build. (easier to install for end users)
substitutions:
  name: garage-secondary
  friendly_name: Garage Secondary
packages:
  ratgdo.esphome: github://ratgdo/esphome-ratgdo/v25iboard.yaml@main
  1. enabling "issues" in github for this repo? (not sure if that's because the esphome repo didn't have it enabled.)
  2. Readme including steps to install / build.

I'm happy to contribute to as much or as little of these as you wanted.

acvigue commented 9 months ago

@acvigue similarly to @ryan-lang did you use a logic analyzer? i would love to contribute and get the 200s model as part of this. If there is another way to grab the commands would love some instructions.

Tried wireshark but so far nothing....

Yes! I used a saleae logic pro 16. I'd be happy to add support for the 200s, but don't have a unit. The TTL levels are slow enough that one of these should work.

https://www.amazon.com/HiLetgo-Analyzer-Ferrite-Channel-Arduino/dp/B077LSG5P2

It works with the Saleae logic software too lol - it's a clone. Doesn't work well for high speed stuff but should work for this.

acvigue commented 9 months ago

@acvigue A few more questions if you don't mind. Love the work you've done here and want to replicate it / test and help.

Would you consider:

1. Instead of forking ESPHome, Have this as a standalone repo.  My ratdgo garage doors just pull in a package from github: (https://github.com/ratgdo/esphome-ratgdo) vs clone the entire ESPhome repo. Which allows this to be compiled into the docker hosted ESPhome UI without needing to  clone / build.  (easier to install for end users)
substitutions:
  name: garage-secondary
  friendly_name: Garage Secondary
packages:
  ratgdo.esphome: github://ratgdo/esphome-ratgdo/v25iboard.yaml@main
2. enabling "issues"  in github for this repo?  (not sure if that's because the esphome repo didn't have it enabled.)

3. Readme including steps to install / build.

I'm happy to contribute to as much or as little of these as you wanted.

Issues enabled, and you are welcome to work on the other stuff you mentioned. Just send another pr and I'll check it out. I enabled notifications for this repo so I should see it.

acvigue commented 9 months ago

@acvigue A few more questions if you don't mind. Love the work you've done here and want to replicate it / test and help.

Would you consider:

1. Instead of forking ESPHome, Have this as a standalone repo.  My ratdgo garage doors just pull in a package from github: (https://github.com/ratgdo/esphome-ratgdo) vs clone the entire ESPhome repo. Which allows this to be compiled into the docker hosted ESPhome UI without needing to  clone / build.  (easier to install for end users)
substitutions:
  name: garage-secondary
  friendly_name: Garage Secondary
packages:
  ratgdo.esphome: github://ratgdo/esphome-ratgdo/v25iboard.yaml@main
2. enabling "issues"  in github for this repo?  (not sure if that's because the esphome repo didn't have it enabled.)

3. Readme including steps to install / build.

I'm happy to contribute to as much or as little of these as you wanted.

Also, completely off topic. How do you like the ratgdos (specifically the software)? We have three chamberlain doors and I hate that they're the only cloud thing we still have.

Scags104 commented 9 months ago

@acvigue A few more questions if you don't mind. Love the work you've done here and want to replicate it / test and help. Would you consider:

1. Instead of forking ESPHome, Have this as a standalone repo.  My ratdgo garage doors just pull in a package from github: (https://github.com/ratgdo/esphome-ratgdo) vs clone the entire ESPhome repo. Which allows this to be compiled into the docker hosted ESPhome UI without needing to  clone / build.  (easier to install for end users)
substitutions:
  name: garage-secondary
  friendly_name: Garage Secondary
packages:
  ratgdo.esphome: github://ratgdo/esphome-ratgdo/v25iboard.yaml@main
2. enabling "issues"  in github for this repo?  (not sure if that's because the esphome repo didn't have it enabled.)

3. Readme including steps to install / build.

I'm happy to contribute to as much or as little of these as you wanted.

Also, completely off topic. How do you like the ratgdos (specifically the software)? We have three chamberlain doors and I hate that they're the only cloud thing we still have.

i use ESPHome for mine, soldered an ESP32 to my garage door remote and its been rock solid for 2-3 years. 4$ and 10 minutes of time. best thing ive done.

haydonryan commented 9 months ago

Also, completely off topic. How do you like the ratgdos (specifically the software)? We have three chamberlain doors and I hate that they're the only cloud thing we still have. I went the ratdgo route - I have a security 2.0 wifi garage door opener.

There was two firmwares available - MQTT and esphome. ESPhome is rock solid, haven't had an issue. MQTT is trash and I think they've removed it.

Because it plugs into the bus Paul was able to create sensors and buttons in HA for all the features door open / closed status light on / off obstruction lock (disable) remotes remotely restart the opener motion sensor for the garage button for open close. open/ close counter.

This wasn't $4 - i got two plus usb power to run each. But ultimately now that I'm on ESPhome I'm super happy with them. It's definitely a more premium option but the amount of dev work that has gone into it is pretty large too.

Scags104 commented 9 months ago

@acvigue similarly to @ryan-lang did you use a logic analyzer? i would love to contribute and get the 200s model as part of this. If there is another way to grab the commands would love some instructions. Tried wireshark but so far nothing....

Yes! I used a saleae logic pro 16. I'd be happy to add support for the 200s, but don't have a unit. The TTL levels are slow enough that one of these should work.

https://www.amazon.com/HiLetgo-Analyzer-Ferrite-Channel-Arduino/dp/B077LSG5P2

It works with the Saleae logic software too lol - it's a clone. Doesn't work well for high speed stuff but should work for this.

@acvigue came from amazon today! hooked it up. this is a block where i sent a power command from the app to the unit. What do i do from here? lol why did i assume the commands needed would just be listed for me to grab. Never that easy

image

acvigue commented 9 months ago

@acvigue similarly to @ryan-lang did you use a logic analyzer? i would love to contribute and get the 200s model as part of this. If there is another way to grab the commands would love some instructions. Tried wireshark but so far nothing....

Yes! I used a saleae logic pro 16. I'd be happy to add support for the 200s, but don't have a unit. The TTL levels are slow enough that one of these should work. https://www.amazon.com/HiLetgo-Analyzer-Ferrite-Channel-Arduino/dp/B077LSG5P2 It works with the Saleae logic software too lol - it's a clone. Doesn't work well for high speed stuff but should work for this.

@acvigue came from amazon today! hooked it up. this is a block where i sent a power command from the app to the unit. What do i do from here? lol why did i assume the commands needed would just be listed for me to grab. Never that easy

image

You have to turn on uart analyzer and cross-reference it with the protocol structure described in the blog post or the code here. It may help if you performed some actions and put the associated data here.

Scags104 commented 9 months ago

@acvigue learning as i go here. Hopefully this is what you meant - this was an on/off command from the app

name,type,start_time,duration,"data"
"I2C [1]","start",19.94461,5e-06,
"Async Serial","data",19.94461,8e-05,0x5B
"Async Serial","data",19.944695,8e-05,0x50
"Async Serial","data",19.94478,8e-05,0x4C
"Async Serial","data",19.94487,8e-05,0x46
"Async Serial","data",19.944955,8e-05,0x20
"Async Serial","data",19.94504,8e-05,0x45
"Async Serial","data",19.945125,8e-05,0x20
"Async Serial","data",19.945215,8e-05,0x6D
"Async Serial","data",19.9453,8e-05,0x65
"Async Serial","data",19.945385,8e-05,0x74
"Async Serial","data",19.94547,8e-05,0x68
"Async Serial","data",19.94556,8e-05,0x6F
"Async Serial","data",19.945645,8e-05,0x64
"Async Serial","data",19.94573,8e-05,0x5F
"Async Serial","data",19.945815,8e-05,0x74
"Async Serial","data",19.945905,8e-05,0x69
"Async Serial","data",19.94599,8e-05,0x6D
"Async Serial","data",19.946075,8e-05,0x65
"Async Serial","data",19.94616,8e-05,0x72
"Async Serial","data",19.94625,8e-05,0x5F
"Async Serial","data",19.946335,8e-05,0x63
"Async Serial","data",19.94642,8e-05,0x72
"Async Serial","data",19.946505,8e-05,0x65
"Async Serial","data",19.946595,8e-05,0x61
"Async Serial","data",19.94668,8e-05,0x74
"Async Serial","data",19.946765,8e-05,0x65
"Async Serial","data",19.94685,8e-05,0x3A
"Async Serial","data",19.94694,8e-05,0x31
"Async Serial","data",19.947025,8e-05,0x34
"Async Serial","data",19.94711,8e-05,0x36
"Async Serial","data",19.947195,8e-05,0x5D
"Async Serial","data",19.947285,8e-05,0x20
"Async Serial","data",19.94737,8e-05,0x54
"Async Serial","data",19.947455,8e-05,0x69
"Async Serial","data",19.94754,8e-05,0x6D
"Async Serial","data",19.94763,8e-05,0x65
"Async Serial","data",19.947715,8e-05,0x72
"Async Serial","data",19.9478,8e-05,0x20
"Async Serial","data",19.947885,8e-05,0x68
"Async Serial","data",19.947975,8e-05,0x61
"Async Serial","data",19.94806,8e-05,0x73
"Async Serial","data",19.948145,8e-05,0x20
"Async Serial","data",19.94823,8e-05,0x62
"Async Serial","data",19.94832,8e-05,0x65
"Async Serial","data",19.948405,8e-05,0x65
"Async Serial","data",19.94849,8e-05,0x6E
"Async Serial","data",19.948575,8e-05,0x20
"Async Serial","data",19.948665,8e-05,0x63
"Async Serial","data",19.94875,8e-05,0x72
"Async Serial","data",19.948835,8e-05,0x65
"Async Serial","data",19.94892,8e-05,0x61
"Async Serial","data",19.94901,8e-05,0x74
"Async Serial","data",19.949095,8e-05,0x65
"Async Serial","data",19.94918,8e-05,0x64
"Async Serial","data",19.949265,8e-05,0x2E
"Async Serial","data",19.949355,8e-05,0x0D
"Async Serial","data",19.94944,8e-05,0x0A
ryan-lang commented 9 months ago

@Scags104 You're on the right track. Now it's just a matter of methodically solving the puzzle.

Issue a command, write down what bytes were transmitted, and what bytes were received in response. Repeat for all commands. You should start to see patterns. Each byte position serves a purpose. There will likely be bytes that represent: the message type, the command type, the size of the payload, the payload itself, and a checksum at the end. Probably empty/unused bytes too. And bytes that will remain a mystery.

Unless the packets are encrypted, the structure will be logical, which means it should be mostly solvable.

Look at the source code for hints. Levoit::validate_message describes a response packet, Levoit::send_raw_command describes a command packet.

ryan-lang commented 9 months ago

@Scags104 The data you included looks like it must be several commands, or command/response all squished together. You'll want to try to isolate a single message. That's what your logic analyzer software should help you with. Use the waveform to see where the "gaps" in the byte stream are.

Scags104 commented 9 months ago

@ryan-lang thanks for the feedback. Any pointers on how to send the commands back to the unit? Is it through Saleae Logic or should i just fork the repo, create a 200 model and keep playing? Obviously this would mean i need to bog down 2 of my air purifiers for this process and need to keep rebuilding ESPHome on one for every command i attempt. I assume there is an easier way?

Thanks

ryan-lang commented 9 months ago

@Scags104 The logic analyzer's job is to just passively snoop on the messages coming across the wire, not actually send or receive packets directly. You can issue the commands using the air purifier's app, as a normal user would. Until you have a good sense of how the packets are structured, there's no need to involve esphome in your testing. The source code is just to give you some hints, since there will likely be similarities between your model and what we've already figured out.

Scags104 commented 9 months ago

@ryan-lang i think im outside of my comfort zone here unfortunately.

@acvigue @ryan-lang either of you up for supporting this model if i shipped you one of the boards from one of my units?

Also just an FYI the 300s code on the 200s has really inconsistent wifi, it seems to drop off the network after any command is sent from ESPHome and then quickly rejoins after a few seconds.

ryan-lang commented 9 months ago

@Scags104 I'm probably not going to be able to take that on in the near future. Would be happy to keep giving pointers though.

acvigue commented 9 months ago

@Scags104 I'm in (reportedly) my hardest semester at college right now and don't even have time to sleep 😴. From what I can see in your packets, they're following a format, but not one currently supported (i.e. starts with 0xA5.)

An easier way to view the data is definently in the viewer where you can see where one command starts and one stops.

Scags104 commented 9 months ago

@acvigue @ryan-lang was worth a shot!

If anyone else who comes across this post wants to take a crack at it let me know. Unfortunately, i dont think im that guy 👎

haydonryan commented 9 months ago

@acvigue - So what I think needs to be done is to start a new repo for the refactor, maybe something like Levoit-AirPurifier-ESPHome and we can then build that up. To refactor this repo would involve having all the history of esphome.

I'm happy to create a temporary repo under my user in the short term based on what I'm thinking, but think ownership should be yours, since you did all the hard work.

acvigue commented 8 months ago

@acvigue - So what I think needs to be done is to start a new repo for the refactor, maybe something like Levoit-AirPurifier-ESPHome and we can then build that up. To refactor this repo would involve having all the history of esphome.

I'm happy to create a temporary repo under my user in the short term based on what I'm thinking, but think ownership should be yours, since you did all the hard work.

Done. The repo has been renamed - should redirect to the new one.

acvigue commented 8 months ago
external_components:
  - source: github://acvigue/esphome-levoit-air-purifier
haydonryan commented 7 months ago

I built a TEMPORARY proof of concept https://github.com/haydonryan/esphome-levoit-purifier here, with sample config and the code. So far it compiles (and confirmed it pulls and compiles the code correctly) but I have not flashed my air purifier away from the standard firmware so it's untested. Will test next month due to other commitments.

acvigue commented 7 months ago

Hi @haydonryan thank you! It's already been published and tested in this repo though. Please see the latest commit & the comments directly above as the component has been isolated and is now the sole thing in here :)

Feel free to send a PR for 200S support once you have a chance to test.