(Probably a dumb question but I just can’t seem to get anything working)
I have a gas meter that creates a magnetic pulse every 10L of natural gas consumed. I have created a small device with a hall effect detector that measures the magnetic field strength and so tells me when the magnet goes past. I’m using ESPHome ADC code to measure the reading from the detector:
I can see the 'Gas Meter Reading" value in HA.
I’ve also created a Threshold sensor that tells me when the reading indicates that the magnet is close by (I’d show the YAML code but the only way to get it to work was by creating a ‘helper’ and I don’t know how to get the YAML code for one of those.)
I typically see a value from the ADC of over 3200 when the magnet is away and around 2900 when it is near.
The Threshold ‘Lower’ limit is 3100 with a hysteresis value of 100.
Again I can see the state of this binary sensor going on and off correctly.
What I want to do is to count the “on” to “off” transitions (as this will tell me that another 10L has gone through). I’ve tried a history_stats sensor and I can see the counts:
So, what is the “correct” way to get this count?
(Once I have the count then I can do the manipulations to convert the volume to MJ and then to a utility_meter integration for the daily usage to eventually feed into the energy usage for the house.)
Susan
Thanks for the suggestion Tom. I’ll look into those ESPHome components.
I should be able to put in a jumper on the PCB to make the connection as you suggest.
I must admit that my first attempt was to make my own ESPHome component using the Arduino ADC driver and perform my own hysteresis and pulse counting but I got an error that said teh “driver/ADC.h” file was not available and I didn’t investigate further.
BTW the MCU is an Seeed Studio Xiao ESP32S3 which does have GPIO1 as an ADC input. As I said, this part is working nicely.
Susan
@tom_l - I took your suggestion but with a small twist: instead of having the threshold sensor change a GPIO port that the pulse_counter read, I created my own clone of the pulse_counter that read from another sensor (in this case the analog_threshold sensor).
All works nicely.
Thanks for setting me on the right direction.
Susan