Hello, i am trying to get my water and gas meter readings in home assistant.
I am using a Wemos D1 flashed with Esphome and with currently 1 hall switch connected to get pulses from a magnet on the last dial of the gas meter. The Esphome is connecting to HA with the native api.
Current state : i get the pulses from the dial in pulses/min on the esp8266.
But my problem is that the workings of the “pulse counter” in Esphome and Utility meter in HA are not clear to me.
The pulse counter is giving me a value in pulses/min, but how is this value being calculated ? If i set an update interval of 120s the value in pulses/min that i get will be the average number of pulses/min on the last 120 seconds and will then be reset, and restarted for 120s ?
If correct, to get the consumed m3 of gas i will have to multiply the average p/min i get every 120s by 2 to get the number of pulses in that interval, then multiply the result by the value in m³ per pulse (0,01), is this correct ? At the end it gives : p/min x 0.02 = m³ (used in the last 120s)
If correct, this can be achieved with a sensor filter in the configuration :
At the end, if everything is correct , in HA i get a value every 120s from the “Gas Consumption” Sensor of the cosumed m³ for the last 120s. But if i feed this directly into the Utility meter it seems not to sum every value to get a total daily gas usage. Do i need to use a temporary “counter” in HA ?
I Don’t understant it like that if i refer to the Following example from the Esphome Wiki :
" Tip
To store local variables inside lambdas that retain their value across executions, you can create static variables like so. In this example the variable num_executions is incremented by one each time the lambda is executed and the current value is logged. "
lambda: |-
static int num_executions = 0;
ESP_LOGD("main", "I am at execution number %d", num_executions);
num_executions += 1;
Added the lambda to the filter section of the pulse counter, to have only one sensor in HA wich is the total m³ consumed, since it is that value that is needed by the utility meter sensor.
I still do not understand completely the working of the pulse_counter in Esphome (when it is reset for example) but it is working now for what i am doing. I think it would be simpler if we could just have a number of pulses and not pulses/min as output.
But if my problems can help others… thank you nickrout for the time you took to help me.
Since my last answer, everything is working great for Gas meter.
I am now starting the Electricity meter project. I have an Electricity Meter with a rotating wheel with a black line on it. So with a photo resistor i can count the turns.
i would like to extract two values from these pulses :
The Kwh used (Easy as i can use the same method as for the Gas meter, with different factor)
The current Watts used (This could be done counting the time between two pulses)
My question is still related to the fact that i don’t fully understand how the pulse counter works in esphome.
Can i use two sensor that are using the same gpio as input ? Pulse Width and pulse counter ?
If i use pulse width how do i manage the refresh rate ? because if i have the default update time of 60s and the weel takes 70s to make a full turn, what will i get from the sensor at the first update ? and at second update ?
Is the sensor data resetting itself when i ask for an update ?
Or does the sensor stores the time in seconds between pulses (gpio HIGH) and keeps it until a new pulse is trigered (gpio LOW) ? If it is working like that, if i set an update interval of 10s i should get the same value in seconds from the sensor at every update until a new full rotation has been registered at another speed.
Of course, i used a Wemos D1 with a A3214LUA-T Hall Effect Switch, this one is very sensitive and able to sense the magnet on the las wheel of my meter dial.
The sensor has 3 pins, The first is the supply voltage (i uses 3,3v) the midle one is the Ground pin, and on the right one is the signal pin.
I connected the signal pin to one of the GPIO ports of the wemos, and soldered a pull-ip resistance of 10k between +3,3v and the signal pin, also placed 2 capacitors like recommended on the Data sheet of the sensor.
Every time the magnet is in front of the sensor, the signal pin is connected to ground and the GPIO is at 0V (LOW), we have our reading.
Do you have any more information on this project? Where exactly do the resistor and capacitors go? And which ones did you use? Apologies for the many questions, I’m learning about this stuff and working on this project currently and this would be massively useful. Thanks
Yes but I’ll be honest and say I don’t fully understand it. I understand I need a capacitor between supply and ground, and a resistor between supply and signal but I can’t see a mention of a second capacitor on the datasheet (unless it’s on the technical drawings which I don’t know how to interpret) or their specifications.
My only experience with capacitors is on guitar wiring so any help would be appreciated.
I am in the process of doing something very similar using a spare esp8266. Could the author of the post @nbdriver or anyone else that already tried it recommend any proper hall switch that works?
I have been looking for information about them (hall sensors and reed switches) but I can’t seem to find any definitive answer for one that “just works” using pulse_counter and esphome and is sensitive enough.
while scanning a simple key
in "/config/esphome/weather_station_d1.yaml", line 60, column 9:
static float total_value = 0.0;
^
could not find expected ':'
in "/config/esphome/weather_station_d1.yaml", line 61, column 9:
total_value += x * 0.01;