Hi everyone, I’m trying to get the water level of an horizontal tank but don’t know how to do it.
I’ve a 4-20mA pressure sensor and I’m able to read a voltage value with an ADS1115 converter but how can I add a complex equation with cosine and square root?
the equation is like this:
import math
WaterLevel = (4.5*(1.56252math.acos(-2.6)+(X-1.25)math.sqrt(X(2*1.25-X))))*1000
X-> is the voltage value of ADS1115 Analog input
I’ve tried to create a new custom input but I don’t know enough python in order to get this to work
The easiest way might be to use a Python 3 Code Input. You can get the voltage measurement, perform the mathematical conversion, then save the new value with the following code in your Python 3 Code Input. Make sure to set the appropriate Measurement/Unit in the Python 3 Code Input options, as well as copying the correct IDs from the ADS1115 Input. You can find/copy the Input ID with the button next to the Input name, and the measurement ID under Configure Measurements next to the channel/measurement name. Enable Log Level: Debug to see the debug messages appear in the Daemon Log.
import math
from mycodo.utils.influx import get_last_measurement
input_id = "REPLACE_WITH_ADS1115_INPUT_ID"
measurement_id = "REPLACE_WITH_ADS1115_MEASUREMENT_ID"
max_age = 1800 # Max age to query the measurement in the database (seconds)
voltage = get_last_measurement(input_id, measurement_id, max_age=max_age)
self.logger.debug("voltage: {}".format(voltage))
if voltage is not None:
try:
water_level = (4.5*(1.56252*math.acos(-2.6)+(voltage-1.25)*math.sqrt(voltage*(2*1.25-voltage))))*1000
self.logger.debug("water_level: {}".format(water_level))
self.store_measurement(channel=0, measurement=water_level)
except:
self.logger.exception("Error evaluating equation")
Hey there.
I’m curious about the same thing.
I guess knowing the water level of a hydroponic tank is a usecase for many people. Any chance you could implement this as a default input for a JSN-SR04T?