Luckily I have the board in front of me (it’s going back in the enclosure later this morning) so I was able to snap a picture.
As you can see, not a lot exciting going on. On the right, AC power coming in. I put it through a large MOV, and then a PCB-mount 220V-5V adapter. Then a small MOV (because I am paranoid), and a 4700uF capacitor. All of that is just to clean the power supply and protect the D1 from spikes.
Then I just have the D1 Mini mounted on some female pin headers, and on the other side of the board, I soldered some traces. On the left side, the three connectors are for the flowmeter, and the trigger and echo pins of the ultrasonic I’m using to measure how much water is in the reservoir.
The resistor you see on the left joins to the flowmeter’s data line before it hits the D1’s input pin. It’s a 10kohm resistor, coming from 5V+. I am not an electronics genius, I saw this in a YouTube tutorial for working with this flowmeter, and they didn’t explain it, but if I have to guess what it does, I think it effectively boosts the signal that the flowmeter is putting out.
Here is the full yaml file:
esphome:
name: d1m001_reservoir
platform: ESP8266
board: d1_mini
wifi:
ssid: "xxxxxxxx"
password: "xxxxxxxxxxxxx"
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
sensor:
- platform: pulse_counter
name: "Flow rate"
pin: GPIO5
update_interval: 60s
filters:
- lambda: return (x / 27.0) * 60.0;
unit_of_measurement: "L/hr"
- platform: ultrasonic
name: "Reservoir level"
trigger_pin: D3
echo_pin: D4
update_interval: 60s
filters:
- lambda: return 200000 - ((x / 2.1) * 200000.0);
unit_of_measurement: "L"
As you can see, I am using filters to format the data into usable form. ESPHome reports the flowmeter’s speed in revolutions per minute, and I know that the flowmeter turns 27 revolutions per litre. Therefore the formula is (x/27)*60, which gives the speed in Litres per hour.
Then for ultrasonic, I really want to do the formula better, but, basically, I know the capacity of the reservoir is 200,000L, and it’s 2,1m deep. The ultrasonic is returning a measurement in metres, so I divide by 2.1 to get percentage, and multiply by 200,000. This effectively shows how much water would still be needed to fill the reservoir. To get the actual amount, therefore, I just subtract the result from 200,000. It works, but I wish I could make that calculation a little more elegant.
Anyway I hope that helps you.