Salut,
J’ai trouvé les éléments sur le site de la communauté HA, voilà le lien. ESPHome water level sensor - #214 by kimocal - ESPHome - Home Assistant Community
Pour le montage c’est pas très compliqué, je te laisse regarder l’image.
pour mon code je peux te le partager, j’utilise la notion de package de esphome, et voilà le package qui gère la mesure.
voilà mon package : water_gauge.yaml
defaults:
full_index: '98.0'
empty_index: '15.0'
current_min: '3.0'
current_max: '19.3'
high_max: '100'
max_vol: '1060'
binary_sensor:
- platform: template
name: "Full"
icon: mdi:gauge-full
id: sensor_full
lambda: |-
if (id(level).state >= ${full_index}) {
return true;
} else {
return false;
}
- platform: template
name: "Empty"
icon: mdi:gauge-empty
id: sensor_empty
lambda: |-
if (id(level).state <= ${empty_index}) {
return true;
} else {
return false;
}
- platform: template
name: "Alerte"
icon: mdi:gauge
id: sensor_alert
lambda: |-
return (id(sensor_empty).state or id(sensor_full).state );
sensor:
- platform: template
name: Hauteur
id: hauteur
unit_of_measurement: cm
accuracy_decimals: 2
filters:
- calibrate_linear:
method: exact
datapoints:
- ${current_min} -> 0.0
- ${current_max} -> ${high_max}
- clamp:
min_value: 0.0
max_value: ${high_max}
on_value:
then:
# - component.update: remplissage
- component.update: volume
- platform: template
name: Volume
id: volume
unit_of_measurement: L
device_class: water
accuracy_decimals: 1
lambda: |-
return (id(level).state * ${max_vol} / 100.0);
filters:
- clamp:
min_value: 0.0
max_value: ${max_vol}
- platform: template
name: Level
id: level
unit_of_measurement: "%"
accuracy_decimals: 2
filters:
- calibrate_linear:
method: exact
datapoints:
- ${current_min} -> 0.0
- ${current_max} -> 100.0
- clamp:
min_value: 0.0
max_value: 100.0
pour le composant esphome il faut déclarer le package avec les bons paramètres, ainsi que le bus i2c, et le composant ina219 :
packages:
gauge: !include
file: common/packages/water_gauge.yaml
vars:
full_index: '98.0'
empty_index: '5.0'
current_min: '5.194'
current_max: '12.50'
i2c:
sda: D2
scl: D1
scan: true
id: bus_a
sensor:
- platform: ina219
address: 0x40
shunt_resistance: 0.1 ohm
max_voltage: 26.0V
# max_current: 3.2A
max_current: 400mA
update_interval: 10s
current:
name: "Current"
id: current
unit_of_measurement: mA
device_class: current
entity_category: diagnostic
filters:
- multiply: 1000 #convert from Amps to mA
- clamp:
min_value: 4.0
max_value: 13.0
on_value:
then:
- sensor.template.publish:
id: hauteur
state: !lambda 'return x;'
- sensor.template.publish:
id: level
state: !lambda 'return x;'
- component.update: volume
prends le temps de lire le forum de HA, il y a beaucoup d’explication. Dans mon cas je mesure avec un capteur qui a une amplitude de 1m, et j’ai étalonné en regardant la valeur de l’intensité quand la cuve était pleine et vide.
A+