-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Sonoff MS01 soil moisture sensor #15335
Conversation
Before ever merge:
|
I ordered an MS01 and will play with it. I plan to use your code for a more simpler implementation. So no action on your part needed for now. |
Ok, thanks for looking into it! I was just about to dive in and see if I could rewrite my implementation as a new driver that is compatible with ESP32, but I haven’t worked in C++ before so I am glad you can help out with finishing up 👍 I added the datapoints in a comment for reference. I obtained the dataset by connecting a MS01 to a Sonoff TH10 and then ran a script that listened for a signal with a digital analyzer, read the data and waited for Sonoff to give their soil percentage value. I tried fitting the value conversion as a single third polynomial function, but it I could not get close to anything like linear correlation with the moisture reported by the sensor and how many % of the sensor was being dipped into water. I used a salt water mix with a concentration that gave me 100% soil moisture at the white line indicating soil level in the sensor, so I had some kind of reference values - dry air 0% and water up to the line 100%. Anyway Sonoffs implementation is of course not a “correct” value anyway, but I wanted to reverse engineer it as they implemented it anyway. I think the best implementation for this sensor would have some kind of sane default voltage values for 0% and 100%, and then let the user calibrate by changing those values according to their soil properties. I could look into a calibration process and a function for calculating moisture based on calibration values if you are willing to add user inputs to the driver. |
Initial support for Sonoff MS01 (#15335)
I merged it in my way (less code changes and kept it close to the source). Does the original sonoff app also need calibrating? I sure hope not. Let's wait until I receive mine (should be next tuesday) and verify my results. For now pls test if my merge works for you. |
I tested and I can't get it to work in the (voltage < 15037) range. The calculations looks correct. All I get is -0.1% humidity. A couple of suggestions:
The Sonoff app doesn't have calibration, however in their firmware I found api endpoints for getting soil type tables for voltage to humidity conversion. I never figured out the authentication method so I don't know exactly what the look like. Also, read this to get a better idea of what this sensor does and why calibration would be a good addition (or at least sending voltage so the end user can implement their own calibration): |
The voltage < 15037 is caused by uin32_t. I already changed it to int32_t in latest commit. I'll add voltage. |
Your choice: HumRes |
Description:
Related issue (if applicable): fixes #
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass