Here ya go!
I more or less copied code from the forum post I linked to earlier and then tweaked it to my needs. I cleaned up the code here so only the relevant bits are shown (I’ve got a fair bit extra, since I’m also capturing my electrical data on this device as well as using it as a BT proxy). You’ll probably want to uncomment out the other axis (as well as the internal true part) on yours so you can see all the data that you’re getting. Obviously you’ll have to see what kind of readings you get on yours before adjusting the high and low thresholds in the interval lambda bit to match.
globals:
- id: gas_counter_total
type: long
restore_value: no
initial_value: '0'
- id: gas_counter
type: long
restore_value: no
initial_value: '0'
- id: gas_high
type: bool
restore_value: no
initial_value: 'false'
interval:
- interval: 0.1s
then:
- lambda: |-
if (id(gasz).state > -75 && !id(gas_high)) {
id(gas_counter_total) += 1;
id(gas_counter) += 1;
id(gas_high) = true;
} else if (id(gasz).state < -125 && id(gas_high)) {
id(gas_high) = false;
}
i2c:
sda: GPIO21
scl: GPIO22
sensor:
- platform: qmc5883l
address: 0x0D
# field_strength_x:
# name: "Gas Meter Field Strength X"
# id: gasx
# field_strength_y:
# name: "Gas Meter Field Strength Y"
# id: gasy
field_strength_z:
name: "Gas Meter Field Strength Z"
id: gasz
internal: true
# heading:
# name: "Gas Meter Heading"
range: 200uT
oversampling: 512x
update_interval: 0.1s
#8 counts per cubic foot, multiplied by 2 to get per minute based on update interval
- platform: template
name: "Gas Rate"
lambda: |-
int temp = id(gas_counter);
id(gas_counter) -= temp;
float temp2 = temp;
float temp3 = (temp2/8)*2;
return temp3;
update_interval: 30s
unit_of_measurement: ft³/min
device_class: 'gas'
- platform: template
name: "Gas Total"
lambda: |-
float temp = id(gas_counter_total);
return temp/8;
update_interval: 1s
unit_of_measurement: 'ft³'
state_class: 'total_increasing'
device_class: 'gas'