Tasmota: Add decimal precision for moisture sensor

Created on 2 Jan 2020  路  14Comments  路  Source: arendst/Tasmota

Have you looked for this feature in other issues and in the docs?
Yes

Is your feature request related to a problem? Please describe.

This is related to https://github.com/arendst/Tasmota/issues/7182 and https://github.com/arendst/Tasmota/pull/7309
The moisture is given as a percentage, but the percentage is rounded to an integer. In many situations (e.g. if the analogue range is wet -> dry 720 -> 200), a mere 100 steps is loosing a lot of granularity. As the total possible range for the analogue input is 0->1023, it would be good to have one decimal point after the value to give the full possible granularity of the range.
The issue is compounded that with a moisture sensor which has 200 for wet and 720 for dry, the effective useful range for a pot plant may be only 300 -> 400. Without further precision this results in only 19 steps in the range where there could be 100.

Describe the solution you'd like

I think about here (https://github.com/arendst/Tasmota/pull/7309/commits/c1f30da81ee71fcfb9b293997fb4d4b1dc75fe7f#diff-346bd9707370e3b0529b922b797ef43bR122) it would be necessary to use a float rounded to one decimal place

enhancement fixed

Most helpful comment

Closing this issue as the feature has been added.

Thanks :+1:

All 14 comments

@effelle Maybe you are also interested in this one? :)

I'm on vacancy :P
Anyway, all Adcparam commands work with integer result, even if we use double precision as input values. I'll have a look but is not on my priority list.

I would definitely try to avoid floats. How about using promille instead?

As far, as I understand this, we're talking about a moisture sensor connected to A0? So, I guess, the best practice will be using the raw data 0-1023. Or you can try this sensor via I2C: https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/
(Yes, I know, you'll probably need to compile the stuff yourself....)

@joba-1 yes, if I'll change it I will use a per mille.

@GrendelWWU I prefer use the pure Analog value, but some users from time to time ask for a direct conversion/calibration similar to what we have added for analog LDR and TEMP. Normally is a better implementation for HAB.

Aadcparam 6 is simple and even if I understand Robin's request I'm not sure I'll add a more precise version. I'll think on it.
For now if you want a better calibration scalex and a var on a rule is still the best choice.
What do you think @ascillato?

For now if you want a better calibration scalex and a var on a rule is still the best choice.
What do you think @ascillato?

I agree. As a workaround for now, a rule can be used to set the range that is needed. Also, other workaround is to read A0 pin and do the calculations on a home automation software.

An idea for an optimization to add 1 decimal precision to the moisture conversion and not adding more flash size (due to float variables), can be just multiplying the input of adc by 10 ( 0-1024 to 0-10240 range - as the actual variables are uint16 - limit 65536 ), then do the scale conversion, then take the lowest digit as decimal and divide by 10 the result, having as ouput: [scaledvalue.decimal]

What do you think?

Could be the right call. I'll put it on optimization queue list. Adrian please add the correct tag to the thread, thanks.

First the moisture sensors are more a guess than just a correct measurement. I assume you will not get any additional value with more digits. Anyhow the easiest way to implement this is to set units from percent to per Mille. In this case the base is 1000. I assume this will have a minimum impact on the code.

First the moisture sensors are more a guess than just a correct measurement.

Is what I'm saying Stefan and it's why it is on low priority for now.

Thanks for the thoughts and considerations here! :)
Taking all that into account, I'm also :+1: for the per mille solution!

While such a moisture sensor most probably is far from having a precision needing decimals, I suppose that the point still could be to be able to see a more smooth curve, like when I like to plot values with two decimals from a temperature sensor which is only correct within a margin of +/- 0.5 degrees. A small change is likely to be of interest even while accepting that the value may be an order of magnitude more off. So I like that Tasmota has the TempRes command :-)

Update moisture calculation using AdcParams 6,0,1023,0,100 and below formula:

moisture = ( ((double)Settings.adc_param2 - (double)adc) / ( ((double)Settings.adc_param2 - (double)Settings.adc_param1)) * ((double)Settings.adc_param3 - (double)Settings.adc_param4) + (double)Settings.adc_param4 );

Closing this issue as the feature has been added.

Thanks :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ximonline picture ximonline  路  3Comments

grizewald picture grizewald  路  3Comments

jensuffhaus picture jensuffhaus  路  3Comments

he-so picture he-so  路  3Comments

Joeyhza picture Joeyhza  路  3Comments