Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

minovap
Copy link

@minovap minovap commented Apr 9, 2022

Description:

Related issue (if applicable): fixes #

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.3
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@arendst
Copy link
Owner

arendst commented Apr 10, 2022

Before ever merge:

  • Do NOT change global code for a local feature. Add the presentation to the DHT driver only.
  • Do NOT use function pow() but use FastPrecisePowf() saving lots of code space

@arendst arendst added the on hold by dev team Result - Feature request put on hold by member of development team label Apr 10, 2022
@arendst
Copy link
Owner

arendst commented Apr 10, 2022

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.

@minovap
Copy link
Author

minovap commented Apr 10, 2022

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.

arendst added a commit that referenced this pull request Apr 10, 2022
Initial support for Sonoff MS01 (#15335)
@arendst
Copy link
Owner

arendst commented Apr 10, 2022

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.

@arendst arendst closed this Apr 10, 2022
@minovap
Copy link
Author

minovap commented Apr 10, 2022

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:

  • Voltage is nice to also include, so the end user can interpret it themselves if they wish to (the voltage is the actual value and the calculation we do is just a rough estimate)
  • I think 0% looks better as a lower limit than 0.1% - it is not a problem on normal air sensors since they practically never have to show the lower limit
  • Also I would suggest going with zero decimals for humidity

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):
https://makersportal.com/blog/2020/5/26/capacitive-soil-moisture-calibration-with-arduino

@arendst
Copy link
Owner

arendst commented Apr 10, 2022

The voltage < 15037 is caused by uin32_t. I already changed it to int32_t in latest commit.

I'll add voltage.

@barbudor
Copy link
Contributor

barbudor commented Apr 10, 2022

Also I would suggest going with zero decimals for humidity

Your choice: HumRes

@minovap
Copy link
Author

minovap commented Apr 10, 2022

By the way, before going the MS01 route I tried Gardernas solution but it had a really messy and unreliable integration to Home Assistant so I returned them. Anyway, I have attached a couple of screenshots with what they ask their customers to do in order to calibrate their capacitive sensor.
IMG_5998
IMG_5997
IMG_5996
.

@ascillato2 ascillato2 removed the on hold by dev team Result - Feature request put on hold by member of development team label Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants