So I have something that is mostly working and if your cycles are as long as they look it may work for you. It’s not for me because the qmc5883l is only sampling once a second and my meter spins faster than that.
globals:
- id: water_counter_total
type: long
restore_value: no
initial_value: '0'
- id: water_counter
type: long
restore_value: no
initial_value: '0'
- id: water_high
type: bool
restore_value: no
initial_value: 'false'
interval:
- interval: 5000ms
then:
- lambda: |-
if (id(qmc5883lx).state >= 7 && !id(water_high)) {
id(water_counter_total) += 1;
id(water_counter) += 1;
id(water_high) = true;
} else if (id(qmc5883lx).state <= -2 && id(water_high)) {
id(water_high) = false;
}
sensor:
- platform: qmc5883l
address: 0x0D
field_strength_x:
name: "QMC5883L Field Strength X"
id: qmc5883lx
range: 200uT
oversampling: 64
update_interval: 1s
- platform: template
name: "Flow Sensor"
lambda: |-
int temp = id(water_counter);
id(water_counter) -= temp;
return temp;
update_interval: 60s
- platform: template
name: "Total Sensor"
lambda: |-
return id(water_counter_total);
update_interval: 5s