Gas Meter with Shelly Plus Uni

I decided to use the Shelly Plus Uni as a device to read the reed contact, which counts the impulses from my gas meter.

The first unit I received was unfortunately dead on arrival, but Shelly’s support was very helpful and quickly replaced it.

For the Home Assistant Shelly integration, I had to patch the sensor.py file to support the COUNT IN function (source here):

--- /usr/src/homeassistant/homeassistant/components/shelly/sensor.py.original
+++ /usr/src/homeassistant/homeassistant/components/shelly/sensor.py
@@ -960,6 +960,30 @@
         native_unit_of_measurement=PERCENTAGE,
         state_class=SensorStateClass.MEASUREMENT,
     ),
+    "analoginput_xpercent": RpcSensorDescription(
+        key="input",
+        sub_key="xpercent",
+        name="Analog value",
+    ),
+    "pulse_counter": RpcSensorDescription(
+        key="input",
+        sub_key="counts",
+        name="Pulse counter",
+        native_unit_of_measurement="pulse",
+        state_class=SensorStateClass.TOTAL,
+        value=lambda status, _: status["total"],
+        removal_condition=lambda config, _status, key: (config[key]["enable"] is False),
+    ),
+    "counter_value": RpcSensorDescription(
+        key="input",
+        sub_key="counts",
+        name="Counter value",
+        value=lambda status, _: status["xtotal"],
+        removal_condition=lambda config, status, key: (
+            config[key]["enable"] is False
+            or status[key]["counts"].get("xtotal") is None
+        ),
+    ),
 }

After initial testing, everything is working fine and looks promising. Now I’m looking for a case to secure it more permanently to the gas meter. I found a 3D-printed case that fits everything well by wiring the outputs and inputs accordingly.

Now, the setup works perfectly, and I was even able to add a temperature and humidity sensor (DHT / 2302), so I’m quite happy with the results.

Let me know if you have any questions!

Hi,
does it work flawlessly for you ?
I have used a classic reed sensor (glass tube) attached to COUNT IN to count pulses from the gas meter. Most of the time it works well (increment +1; nice linear graph), but few times a day it increases the pulses ~ +10 or even more (eg. from 350pulses to 460) and then it continues normally.

1 Like

I need to double-check the data. From a distance, it looks like it’s working more or less fine. I noticed some jumps, but nothing too bad that would bother me. My explanation so far is that it might count incorrectly if the magnet stops exactly over the reed sensor. Could that be the case for you?

I programmed the LED to light up whenever there’s a count, making it easier to debug when you’re in front of your meter.

I double-checked the data, and although there’s a slight discrepancy between the meter value and the counter, the counter frequency is usually at level 1, with only occasional spikes to level 2.

I’m experiencing more issues with my water meter, where the counter frequency varies significantly. I’ll look into whether it’s possible to set a limit on the frequency (in Hz) to ensure only values within that range are counted.


Counter frequency of my water meter