@CeeCee
So during testing I got a voltage of 0.63v or 5.16mA at about 20cm depth.
None of the formula I can find work to return a depth anywhere close to that
Any ideas?
Well,
the first step when using an ADC is always converting the Voltage into the unit the sensor is sending. You obviously did it, so this is good. Please also check with a mA Meter that your conversion from Volt to milliAmps is precise enough.
The next step is to convert the milliAmps into a pressure reading of your sensor. This should be doable with the datasheet of the manufacturer. Double check your formula for sanity.
These two steps could be skipped if you do not have any problems. But in your situation it should ged rid of uncertainties in the formulas.
Then you can apply the final step: calculating height from the pressure values. If it does not work out, check your equasions, compare the units that are at the beginning of your math to the units that are at the end of the math (âEinheitenvergleichâ, if you speak German). Check that you did not make mistakes by getting rid of millis, kilos, etc without compensating these.
Make a short scetch that helps you understand what pressure at which level you are measuring.
This should lead to a good reading.
I think you might already have settled on a solution. But reading the (environmental) requirements of your application. might it not be better to take a full industrial solution?
A siemens LOGO PLC with AM2 analogue module will read that 4-20ma sensor quite easily and is able to send it through MQTT (https://github.com/sinty/Siemens-LOGO-smart-home)
Only problem with a full industrial solution is itâs full industrial price. Take a deep breath before looking at that.
The LOGO is aimed more towards the Home gamer though. But still not in a ESP range. If you want a frame of reference look at S7 1200 series ranges thatâs Siemens actual âentry levelâ
How did you integrated this into HA?
I did not yet.
The sensor will be connect on a SONOFF TH10, then we will use MQTT. One friend will help for this, I donât know yet how to do it.
The built in REST-api is a bit silly, so I had to resort to a command-line sensor.
I donât remember the exact details now, but I believe it did not send properly formatted json or something. The sensor is currently offline for the winter, so I canât check what it reported.
So I added two command_line sensors:
- platform: command_line
name: Plant Water Raw Zero
command: curl -s http://10.1.1.124/get_sensors | sed -e 's/\\//g' | sed -e 's/"\[//' | sed -e 's/\]"//' | jq '.local_s["z"]' 2>/dev/null
- platform: command_line
name: Plant Water Raw Current
command: curl -s http://10.1.1.124/get_sensors | sed -e 's/\\//g' | sed -e 's/"\[//' | sed -e 's/\]"//' | jq '.local_s["1"]' 2>/dev/null
And then I generate two template-sensors based on these values:
- platform: template
sensors:
plant_water_level:
friendly_name: "Plant Water Level"
unit_of_measurement: "%"
value_template: >
{% set zero = states('sensor.plant_water_raw_zero') | float%}
{% set max = 100 %}
{% set current = states('sensor.plant_water_raw_current') | float %}
{{ ((current - zero) / (max - zero) * 100) | round(0) }}
icon_template: mdi:water-percent
plant_water_level_dec:
friendly_name: "Plant Water Level Dec"
unit_of_measurement: "%"
value_template: >
{{ ((states('sensor.plant_water_level') | int / 10) | round(0)) * 10 }}
icon_template: mdi:water-percent
The â_decâ sensor rounds the value to the nearest 10%, which I the use to display an image in a picute-glance:
- cards:
- type: picture-glance
entity: sensor.plant_water_level_dec
entities:
- entity: sensor.plant_water_level
show_state: true
icon: 'mdi:water-percent'
name: Waterlevel
show_name: true
state_image:
'100': /local/icons/status/water-100.png
'90': /local/icons/status/water-90.png
'80': /local/icons/status/water-80.png
'70': /local/icons/status/water-70.png
'60': /local/icons/status/water-60.png
'50': /local/icons/status/water-50.png
'40': /local/icons/status/water-40.png
'30': /local/icons/status/water-30.png
'20': /local/icons/status/water-20.png
'10': /local/icons/status/water-10.png
'0': /local/icons/status/water-0.png
Thanks! I will try this one I received it
Hi,
I pasted this into my HA, it created the sensors but no data is being shown.
sensor:
- platform: command_line
name: Water Tank
command: curl -s http://192.168.253.139/get_sensors | sed -e 's/\\//g' | sed -e 's/"\[//' | sed -e 's/\]"//' | jq '.local_s["z"]' 2>/dev/null
- platform: command_line
name: Water Tank
command: curl -s http://192.168.253.139/get_sensors | sed -e 's/\\//g' | sed -e 's/"\[//' | sed -e 's/\]"//' | jq '.local_s["1"]' 2>/dev/null
- platform: template
sensors:
tank_water_level:
friendly_name: "Water Tank Level"
unit_of_measurement: "%"
value_template: >
{% set zero = states('sensor.water_tank_zero') | float%}
{% set max = 100 %}
{% set current = states('sensor.water_tank_current') | float %}
{{ ((current - zero) / (max - zero) * 100) | round(0) }}
icon_template: mdi:water-percent
tank_water_level_dec:
friendly_name: "Water Tank Level"
unit_of_measurement: "%"
value_template: >
{{ ((states('sensor.tank_water_level') | int / 10) | round(0)) * 10 }}
icon_template: mdi:water-percent
2 years later, Iâm back in my own topic.
My friend finished the electronic part (that I canât do).
The pressure sensor (4-20mA model) is in the water well since 3 years.
55m of Cat7 cable.
On the other side of the cable, in the house, the cable is connected to a converter (A to voltage).
The converter is connected on the TH10.
The TH10 send tha value to HA via MQTT. Itâs working well.
The value is a voltage.
0v of 0cm of water.
0.9v for 200cm of water.
Olen, how can I use your code to read the MQTT value?
The TH10 is sending values, 1 pressure, and 2 temperature (from the bottom and top of the well).
During the first test on HA, I created a sensor for temperature with this in the configuration.yaml :
mqtt:
sensor:
- name: "Température Puits fond 2"
unique_id: "73948462"
state_topic: "office/sensor1"
device_class: "temperature"
unit_of_measurement: "°C"
state_class: "measurement"
How should I create the pressure sensor (the value is a voltage).
Which kind of sensor? With which options?
I will manage to draw images to display the water well.
thanks