I created a new device (ESPHome) that collects data from a water tank using an ultrasonic sensor and it also measures the main voltage and current (CT clamp).
What I’m struggling with is that I cannot add it to the Energy dashboard:
Here’s the code:
esphome:
name: cisterna-ct-vac
platform: ESP8266
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
networks:
- ssid: "xxxxxxxxxx"
password: "xxxxxxxxxxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Cisterna Fallback Hotspot"
password: "xxxxxxxxxx"
captive_portal:
i2c:
ads1115:
- address: 0x48
sensor:
- platform: ads1115
name: "Voltaje entrada"
id: voltaje_entrada
unit_of_measurement: "V"
icon: "mdi:flash"
accuracy_decimals: 1
update_interval: 24ms
multiplexer: 'A2_GND'
gain: 6.144
filters:
- offset: -2.397593089 # compenstate the offset (value measured at 0V)
- lambda: return x * x;
- sliding_window_moving_average:
window_size: 1250 # average over 30 seconds (update interval is 24ms)
send_every: 208 # report every 05 seconds (update interval is 24ms)
- lambda: return sqrt(x);
- multiply: 330 # calculate mains voltage (calibration)
- platform: ads1115
id: ads_ct
multiplexer: 'A0_A1'
gain: 2.048 # ±2.048V 1 bit = 0.0625mV
name: "ADS1115 A0-A1"
update_interval: 10s
- platform: ct_clamp
sensor: ads_ct
name: "Corriente"
id: corriente_medida
update_interval: 10s
filters:
- calibrate_linear:
# Measured value of 0 maps to 0A
- 0 -> 0
- 0.14633 -> 6.9
- platform: template
id: my_power
name: "Potencia medida"
lambda: return id(corriente_medida).state * id(voltaje_entrada).state / 1000; #Power = Current * Voltage (so change 230 to whatever your mains voltage is)
unit_of_measurement: 'kWh'
update_interval: 5s
- platform: ultrasonic
trigger_pin: D6
echo_pin: D5
name: 'Distancia al agua'
unit_of_measurement: 'm'
accuracy_decimals: 1
update_interval: 10s
pulse_time: 20us
timeout: 2.0m
filters:
- filter_out: nan
- platform: ultrasonic
trigger_pin: D6
echo_pin: D5
name: "Nivel cisterna"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 10s
filters:
## Tank Depth = all the way from the cover where the sensor is mounted to the bottom = 75
## Sensor Value = x this is will stay the same as this is the reading from the sensor
## Excluded Distance = EX which is the distance I have on top from the sensor which is mounted to the cover to the highest level the water can reach = 21
## return ((((x*100)-EX)-(TD-EX))/(TD-EX))*-100
- lambda: return ((((x*100)-21)-(75-21))/(75-21))*-100;
- 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.05 #only send the result if the level difference with the last sent result is higher than this
- filter_out: nan
Sensor displaying on the Device details:
I read the topics below, but not sure if those fixes are still valid
Running on HAOS:
- Home Assistant 2022.8.3
- Supervisor 2022.08.3
- Operating System 8.4
- Frontend 20220802.0 - latest