esp8266/mqtt watermeter using homie platform
Enable read-out of the water meter to get measurement of this meter in OpenHAB using mqtt messages.
- ESP8266 dev board (Wemos D1 mini)
- Homie-esp8266 framework / platformIO
- TCRT5000 reflection sensor
- OpenHAB script for persistence
// receive count from mqtt on intermediate tag; OpenHAB Rule will perform filter/log to update to total
// OR reset the instrument to previous value if it was restarted
Number WaterMeter_TotalReceived "Water Total Received[%d l]" <water> () {mqtt="<[mosquitto:homie/600194100ff2/watertotal/total:state:default]"}
Number WaterMeter_Total "Water Total [%d l]" <water> (Utilities, Water, F0_MeterCupboard)
Number WaterMeter_Flow "Water Flow [%.1f l/m]" <water> (Utilities, Water, F0_MeterCupboard) {mqtt="<[mosquitto:homie/600194100ff2/waterflow/flow:state:default]"}
Number WaterMeter_Uptime "Water Uptime [%d s]" <water> (Utilities, Water, F0_MeterCupboard) {mqtt="<[mosquitto:homie/600194100ff2/$stats/uptime:state:default]"}
/* rules to handle the home water counter */
rule "Handle water meter update"
when
Item WaterMeter_TotalReceived received update
then
if (WaterMeter_TotalReceived.state < 1000) {
// set last value to the water meter if it was reset to zero after powerup
// -- allow for max 1m3 of pulses during startup
publish("mosquitto","homie/600194100ff2/watertotal/total/set", WaterMeter_Total.state.toString)
} else {
postUpdate(WaterMeter_Total, WaterMeter_TotalReceived.state)
}
end
Adjust/reset counter by updating the counter device:
$mosquitto_pub -t homie/600194100ff2/watertotal/total/set -m 1234567
... script
Water Meter without the sensor: