The Raspberry Pi Died — Now What?

For a while, I tracked my water consumption using a LJ12A3 inductive sensor mounted on my water meter (blog post: https://rutg3r.com/watermeter-reading-with-inductive-proximity-sensor/), feeding pulses into a Raspberry Pi running Node-RED. Everything worked well — until the Pi crashed. To make things worse, my personal computer refused to write a new SD card image. Bricked hardware and a broken SD card writer at the same time.

Clearly, I needed an alternative that could handle the sensor’s 6–36V input signal without a dedicated microcontroller. After looking at several ESP-based options, I remembered a Shelly 1 Gen1 that had been sitting in stock for a long time. As it turned out, it was the perfect fit.

The Shelly 1 Gen1 as a Pulse Counter

The Shelly 1 Gen1 supports a wide input voltage range and works perfectly in Detached Switch mode via the native Home Assistant Shelly integration. The inductive sensor connects directly to the input terminal. Every time the water meter dial completes a rotation — one pulse equals one liter — the Shelly registers it.

In Home Assistant, the device appears as binary_sensor.shelly_1_gen1_watercounter_input, toggling from off to on with each pulse.

What I Tried First — And Why It Did Not Work

My first approach was a counter helper incremented by an automation on every off-to-on transition of the binary sensor. At low flow rates this worked fine. However, at higher flow rates pulses arrived faster than Home Assistant could process state changes, so some transitions were missed entirely.

Next, I tried a trigger-based template sensor to bridge the counter to a utility meter. The indentation-sensitive YAML caused headaches, and even after fixing the structure the sensor updated slowly and still dropped rapid changes.

Both approaches shared the same root problem: relying on Home Assistant to catch every binary sensor state transition is simply too fragile when pulses arrive in quick succession.

The Right Solution: Shelly Internal Event Counter

Fortunately, the Shelly 1 Gen1 has a built-in pulse counter that increments internally on every input event — completely independent of Home Assistant. It is exposed via the device REST API at http://<shelly-ip>/status.

The key field is inputs[0].event_cnt. Because this counter runs on the device itself rather than through the HA event bus, it never misses a pulse.

To bring the data into Home Assistant, I created a REST sensor that polls the endpoint every 30 seconds:

rest:
  - resource: http://192.168.1.59/status
    scan_interval: 30
    sensor:
      - name: "Shelly Watermeter Internal Event Count"
        unique_id: shelly_watermeter_internal_event_count
        value_template: "{{ value_json.inputs[0].event_cnt }}"
        unit_of_measurement: "L"
        device_class: water
        state_class: total_increasing

Thanks to state_class: total_increasing, HA handles Shelly reboots gracefully. If the counter resets to zero after a reboot, Home Assistant detects the drop and continues accumulating from the new baseline without corrupting the statistics.

Utility Meter and Energy Dashboard

With the REST sensor in place, I added a utility meter on top for daily tracking:

utility_meter:
  water_daily_m3_shelly:
    source: sensor.shelly_watermeter_internal_event_count
    cycle: daily

Finally, sensor.shelly_watermeter_internal_event_count is added to the Home Assistant Energy dashboard under Water consumption. This gives me long-term historical tracking with no extra sensors needed.

The result is a clean and reliable pipeline:

Shelly internal counter → REST sensor (every 30s) → Utility meter → Energy dashboard

No automations. No counter helpers. No template sensors. Just a Shelly sitting in a cabinet, reliably counting every liter.

Privacy Preference Center