Firstly, what am I trying to achieve? I’d like to have the water level of a rain water reservoir as well as feedback if there is moisture in the pipes leading to the house.
What do I have currently? I have got a Nano in the tank that sends data of the ultrasonic distance sensor and a boolean that tells me if there is a lot of moisture/water in the pipe. The messages are structured like this: LM<moisture as a boolean (value: 0;1)>.
Currently, I display the data on a web server and store the water levels as CSVs on my NAS, but I just discovered HA and would like to implement it there.
I already installed the ESPHome plugin and installed ESPHome on the esp. I can configure and upload the YAML rn.
What I need HA/ESPHome to do. It needs to collect the data from the serial communication and display it. The water level is given as cm (float) and should be converted in the degree of filling. Therefore, the user (I) need to be able to enter a value of cm for max and min, so the software can calculate the percentage.
If you have any idea, please tell me. Also, what the code does and what exactly I have to do. As I said, I’m completely new, but I’d love to learn more. Thanks!
Here is what I got so far as code. The entities are there, but I can’t get the values. It shows N/A.
substitutions:
name: esphome-web-******
friendly_name: ESPHome Tank
esphome:
name: ${name}
friendly_name: ${friendly_name}
min_version: 2024.6.0
name_add_mac_suffix: false
project:
name: esphome.web
version: dev
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: VERBOSE #makes uart stream available in esphome logstream
baud_rate: 0 #disable logging over uart
# Enable Home Assistant API
api:
# Allow Over-The-Air updates
ota:
- platform: esphome
wifi:
# Set up a wifi access point
ap: {}
# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:
dashboard_import:
package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
import_full_config: true
# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
authorizer: none
# To have a "next url" for improv serial
web_server:
uart:
baud_rate: 9600
tx_pin: 1
rx_pin: 3
id: UART3
debug:
direction: RX
dummy_receiver: true
sequence:
- lambda: |-
auto str = std::string(bytes.begin(), bytes.end());
float sensorL = 0;
float sensorM1 = 0;
// Parsing the sensor data "L<level>M<moisture>"
if (sscanf(str.c_str(), "L%fM%f", &sensorL, &sensorM1) == 2){
id(level).publish_state(sensorL);
id(moisture).publish_state(sensorM1);
}
sensor:
- platform: template
name: "Level"
id: "level"
- platform: template
name: "Moisture"
id: "moisture"
The nano is an Arduino Nano. I can’t replace it with an esp directly because the arduino is outside in the tank and there is no way it can connect to internet. In addition I only got 2 wires and power in the tank. So thats the only communication I can think of rn.
Use binary sensor for moisture.
Height conversion to level % you can do with calibrate linear filter.
Be aware that serial wiring should be short/shielded and that you need level shifter for Nano 5V to Esp 3.3.V, at least for rx line.