How to get a pulse from a value

Hi!
I’ve got a traditional gas meter.
Fortunately it emits a magnetic field each time the smallest digit makes one turn.
So I gave a QMC5883L Magnetometer a try and the digit “2” on the meter is always seen as a nice >= 270 µT peak in a reliable manner.

Now I hope to get it working as a pulse counter:
Each time I get a “>= 270 µT” value I’d like to have it as a pulse.
It’s like the esphome Pulse Meter Sensor without the “pin”.

This is how I get the current values:

sensor:
  - platform: qmc5883l
    address: 0x0D
    field_strength_z:
      name: "QMC5883L Field Strength Z"
      internal: false
      id: magnetfeld_z
    range: 200uT
    oversampling: 512x
    update_interval: 1s

Is it possible to get this going with esphome? Any ideas or suggestions?

I bet you forgot to post the yaml that you use to get that sensor.

Thanks for the hint! Just made up for it.

I think something like this should switch on GPIO5 when it’s above 270.
Then in Home Assistant you could add a history stats sensor to count the number of times the switch is on.

It could probably be done in ESP-Home also but not sure about if the counter can be saved past a restart and such.

switch:
  - platform: gpio
    pin: GPIO5 # some unused pin
    id: sw
    name: "past 270"

sensor:
  - platform: qmc5883l
    address: 0x0D
    field_strength_z:
      name: "QMC5883L Field Strength Z"
      internal: false
      id: magnetfeld_z
    range: 200uT
    oversampling: 512x
    update_interval: 1s
    on_value_range:
      - above: 270
        then:
          - switch.turn_on: sw
      - below: 270
        then:
          - switch.turn_off: sw
1 Like

@Hellis81 thank you for your approach! esphome threw this at me:

> [on_value_range] is an invalid option for [sensor.qmc5883l]. Please check the indentation.

Any idea how to get around this?

I have no clue then.
But I guess you can do the “same” automation in HA since you get the reading there.