3030 * at each device restart (due to arduino library
3131 * interrupt bug)
3232 * * other tiny improvements
33+ * Version 1.3 - Paolo Rendano
34+ * * change flow measurement unit to m3/h to adopt
35+ * in home assistant as standard measurement unit
36+ * for V_FLOW
3337 *
3438 * DESCRIPTION
3539 * Use this sensor to measure volume and flow of your house water meter.
7882// flowvalue can only be reported when sleep mode is false.
7983#define SLEEP_MODE false
8084
81- // Max flow (l/min ) value to report. This filters outliers.
82- #define MAX_FLOW 40
85+ // Max flow (m3/h ) value to report. This filters outliers.
86+ #define MAX_FLOW 2 .4d
8387
8488// Timeout (in milliseconds) to reset to 0 the flow
8589// information (assuming no pulses if no flow)
@@ -129,10 +133,10 @@ void IRQ_HANDLER_ATTR onPulse()
129133 lastPulse = millis ();
130134 if (interval<500000L ) {
131135 // Sometimes we get interrupt on RISING,
132- // 500000 = 0.5 second debounce ( max 120 l/min )
136+ // 500000 = 0.5 second debounce ( max 7.2 m3/h )
133137 return ;
134138 }
135- flow = (60000000 .0 /interval) / ppl;
139+ flow = (3600000 .0 /interval) / ppl;
136140 }
137141 lastBlink = newBlink;
138142 }
@@ -178,7 +182,7 @@ void setup()
178182void presentation ()
179183{
180184 // Send the sketch version information to the gateway and Controller
181- sendSketchInfo (" Water Meter" , " 1.2 " );
185+ sendSketchInfo (" Water Meter" , " 1.3 " );
182186
183187 // Register this device as Water flow sensor
184188 present (CHILD_ID, S_WATER);
@@ -206,14 +210,14 @@ void loop()
206210 if (!SLEEP_MODE && flow != oldflow) {
207211 oldflow = flow;
208212#ifdef APP_DEBUG
209- Serial.print (" l/min :" );
213+ Serial.print (" m3/h :" );
210214 Serial.println (flow);
211215#endif
212216 // Check that we don't get unreasonable large flow value.
213217 // could happen when long wraps or false interrupt triggered
214218 if (flow<((uint32_t )MAX_FLOW)) {
215219 // Send flow value to gw
216- send (flowMsg.set (flow, 2 ));
220+ send (flowMsg.set (flow, 4 ));
217221 }
218222 }
219223
@@ -268,7 +272,7 @@ void checkAndFirstTimeInitValuesOnHomeAssistant() {
268272#endif
269273 firstValuesMessageSent = true ;
270274 // Send flow value to gw
271- send (flowMsg.set (0 .0d, 2 ));
275+ send (flowMsg.set (0 .0d, 4 ));
272276 // Send volume value to gw
273277 send (volumeMsg.set (0 .0d, 3 ));
274278 // Send pulsecount value to gw in VAR1
@@ -320,4 +324,4 @@ void receive(const MyMessage &message)
320324#endif
321325 }
322326 }
323- }
327+ }
0 commit comments