I have been using this project to measure sump (under ground) water tank water level with NodeMCU and ultrasonic sensor, implemented using Arduino, MQTT and Home Assistant.
- Calculates how many liters of water available in tank (Here we used rectangular tank)
- Calculates Percentage of water in tank
- Calculates distance of water level in cm
- Calculates distance of water level in feet
- Shows historical record of water level in cm, percentage and in liters
- Open
secret.h
and change Wifi settings, server settings and few other parameters as per your project requirement. - Open
settings.h
- Usually you don't need to change any values here, but if you need any customization feel free play with it.
5V/VCC to Vin
Trig to D6/12
Echo to D5/14
GND to GND
mqtt:
discovery: true
discovery_prefix: homeassistant
broker: xxx.xxx.xxx.xxx
port: xxxx
client_id: Home-Assistant
username: Your-MQTT-Username
password: Your-MQTT-Password
- platform: mqtt
name: "Water Sump Firmware Update"
state_topic: "/house/watersump/Confirmfirmware/"
command_topic: "/house/watersump/firmware/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
- platform: mqtt
name: "Distance in feet"
state_topic: "/house/watersump/"
unit_of_measurement: "ft"
value_template: '{{ value_json.distanceInFeet }}'
- platform: mqtt
name: "Distance in cm"
state_topic: "/house/watersump/"
unit_of_measurement: "cm"
value_template: '{{ value_json.distanceInCm }}'
- platform: mqtt
name: "Liters"
state_topic: "/house/watersump/"
unit_of_measurement: "L"
value_template: '{{ value_json.volume }}'
- platform: mqtt
name: "Percentage"
state_topic: "/house/watersump/"
unit_of_measurement: "%"
value_template: '{{ value_json.percentage }}'
- platform: mqtt
name: "Water Sump Build Number"
state_topic: "/house/watersump/"
value_template: '{{ value_json.buildNumber }}'
- Download and install the Home Assistant App for iOS or Android.
- Download this repo and copy the files in to your sketches directory. Open the sketch in Arduino IDE.
- Go to the
settings.h
tab. This is where all the customisable settings are. You should be able to change almost everything from there before compiling. - Go to the
secret.h
tab. Here you change Wifi settings, server settings and few other parameters as per your project requirement.