I have a soil moisture sensor that gives me values from 2850 (dry) to 1250 (in water). I would like to convert these into percentage values, i.e. 0-100%.
My problem is that I can only convert from small to large with the range node, i.e. the dry value is displayed as 100%.
Can I also reverse this? If so, how?
Is half way between 1250 and 2850 (2050) equivalent to 50%? If yes, then that means the it is a linear relationship, which would be represented on a graph by a straight line. If not, which means the line is curved, then it is a non-linear relationship.
No you don't need to change anything.
It will be fine as long as you work out what reading is too wet or too dry for your Monstera's comfort and water it so it stays within the limits.
I think overwatering is worse than underwatering.
Note that some soil moisture sensors corrode and quickly fail when left in contact with wet soil!
You misunderstand (I think). The range node will certainly give you 50% for an input of 2050, the question is does 2050 coming out of the sensor represent 50% humidity. In your case, as @jbudd suggests, it probably doesn't matter as all you need is to know what % the gauge shows when it is what you consider to the correct humidity for the plant.
By the way, using the Range node with the values reversed is more efficient than adding a Function node.
Well that’s raw values. I put the sensor first dry on my table (2800), afterwards I put it in a glass of water (1300), now I’m experimenting and watch when I’d usually would water my plant and what’s the value of it. I’ll change the representative colours of the gauge for it then.
I think every sensor and soil is a bit different so I have to play with it a bit.
I know it’s the wrong forum/topic here. But I put still my raw values in influx and over to grafana. Could someone give me a hint how to edit the value in grafana to get also there the percentage representation?
The formula you need to apply in Grafana is, I believe
percent = 100*(2850 - value) / (2850-1250)
Which is the same as
percent = 0.0625 * (2850-value)
If you look at the query in Grafana, at the right hand side is a pen symbol. Click that and it shows the query it is going to run. You should see something like SELECT mean("value") FROM "your_measurement" WHERE ....
You should be able to edit that to something like SELECT (2850-mean("value"))*0.0625 FROM "your_measurement" WHERE ....
"value" and "your_measurement" will be whatever your field and measurement names are of course.
Once you have done this you can't easily go back to the original query by clicking the pen again, if you do it will mess up the query (but only if you save it of course).
Initially you might like to do it by copying the existing query and editing the new copy, just in case it doesn't work.
The only thing, I guess I don’t get a basic concept, where do I put the code in grafana? I don’t find any option for it.
Where the query code from influx goes?
Oh you are using flux. I see that is being deprecated. I have not moved to influxdb 2 yet. I will see if I can work out how to do the maths in flux. Or you could look at the flux docs for how to do maths on a value.