My code is a bit different, but I’m using a dedicated ADC (costing around $1) because it is much more precise.
Here’s the bit of code I use to get the voltage reading from the ADC:
sensor:
- platform: ads1115
multiplexer: 'A3_GND'
gain: 4.096
id: zwemvijver_voltage
name: "zwemvijver Level Voltage"
icon: 'mdi:swim'
unit_of_measurement: 'V'
update_interval: 1s #the delta filter will ensure it only sends values when something changes.
filters:
- sliding_window_moving_average:
window_size: 10 #creates a moving average of the last 10 values
send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below))
send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
- delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this
I then have a lot of code to transform that voltage into centimeters, liters, percentage etc but first step for you is to make sure you get the voltage reading from the ADC
I believe I put the rest of my code in the other topic for which I shared the link earlier.
Here’s my set-up. As you can see I have multiple pressure and temperature sensors hooked up to my ESP8266 so it looks rather complex. The ADS1115 is in the upper left corner.
On some of the components you will see some short strands of wire that lead to nowhere? That is because I changed my design many times to get to the final design and I was too lazy to try to remove the wires on these components.
I want to have a backup because i live on the 3rd floor and if theres an overflow or anything i want to be as safe as i can be, plus im curious as how that works.
I got this working (getting Voltage readings) I used your config except I am using A0_GND as my output.
I do have a question about the config.
where and why did you choose that gain number exactly?
so I have done like youève asked and colected voltages at different quantities of water in my small tank
here they are:
10l: 0.621v
15l: 0.634v
20l: 0.649v
22l: 0.663v
32l: 0.689v
40l: 0.7v
50l: 0.715v
52l: 0.720v
65l: 0.718v
70l: 0.730v
numbers seeb to not be logical some yes some no… but maybe it needs some time in the water to adjust and be more stable (i’ve read some places that it need’s 24hr)
anyways, so from that how do I get a percentage or volume (max is 70L)
i got no documentation from manufacturer, none was available. And no, i didn’t read any documentation symply because i didn’t find any…
I did but i still am not so sure about what would be the code, I’m actually reaaly bad in maths. I mean that type of maths specially… I should have listened better in high school!
I thought you were talking about the pressure sensor!?
Of course i’ve read that documentation, but again I am using a 1118, and not much documentation. I was told they were the same …but they are not… i found my way though.
i think that i would get better results if I could get more info about the actual sensor, the pressure sensor!
Yes it would be good if you have the documentation of your sensor, but it is not necessary. You can instead test what voltages you get at various depths.
My reference to documentation was for your question on the gain factor
Well basically if I understand correctly in your case the max voltage you will be reading is 0.730v.
So based on the documentation I think you should set a gain factor of 1.024
This code will get you a sensor which shows the centimeters:
- platform: template
name: "CM"
id: watertank_cm
icon: 'mdi:water-well'
unit_of_measurement: 'cm'
lambda: |-
return id(watertank_voltage).state;
update_interval: 1s #the delta filter will ensure it only sends values when something changes.
filters:
- calibrate_linear:
# Measured value of X volt maps to y cm
- 0.464 -> 0
- 0.994 -> 55.2
- 1.424 -> 102.0
- 1.818 -> 144.0
- delta : 0.001 #only send the result if the difference with the last sent result is higher than this
This code will give you a percentage of how full your tank is:
- platform: template
name: "usable %"
id: watertank_percent
icon: 'mdi:water-well'
unit_of_measurement: '%'
lambda: |-
return id(watertank_cm).state / 165.0 * 100;
#divide by max water level height to get a percentage
update_interval: 1s #the delta filter will ensure it only sends values when something changes.
filters:
- delta : 0.001 #only send the result if the difference with the last sent result is higher than this
This code will give you the liters:
- platform: template
name: "usable liters"
id: watertank_liter
icon: 'mdi:water-well'
unit_of_measurement: 'l'
lambda: |-
return id(watertank_cm).state / 100 * 3.14159265 * 1.13751599 * 1.13751599 * 1000.0;
#height (meters) times pi times radius (meters) squared times 1000 gives liters. This works if your water tank is a cilinder shape. Otherwise you have to use different calculations.
update_interval: 1s #the delta filter will ensure it only sends values when something changes.
filters:
- delta : 0.001 #only send the result if the difference with the last sent result is higher than this