> For the complete documentation index, see [llms.txt](https://homey.solweb.no/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://homey.solweb.no/custom-integrations/water-metering.md).

# Water metering

**Works in progress! I'm not done with migrating this setup to Homey yet!**

This article describes the setup of digitally measuring water usage, using a tessel.io microcontroller.

### Choosing the correct water meter <a href="#choosingthecorrectwatermeter" id="choosingthecorrectwatermeter"></a>

You are not allowed to install a water meter yourself. In dialog with the waterworks, ro replace or install a water meter you need to ask for a water meter that can support digital readings.

In Trondheim, Norway, [Øwre-Johnsen as](https://owre-johnsen.no/) delivers the water meters allowed to be installed.

In dialoge with Øwre-Johnsen as, I ended up installing [Elster V200 (KVM-T)](https://owre-johnsen.no/produkt/ringstempelmaler-v200-kvm-t/). In addition I ordered and installed the [Falcon PR6 pulse module](https://owre-johnsen.no/produkt/signalgiver-falcon-pr6/). This one you can install your self.

![](https://1587494504-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ltn3vQOSB-YGC6qLZu_%2F-LtokHvCItp5hBZHutp_%2F-LtolRCFVRVdk0v6Hn12%2Fimage.png?alt=media\&token=d7ecb50b-94a0-40b9-94e5-5536226b7884)

### Reading the pulse <a href="#readingthepulse" id="readingthepulse"></a>

I chose to use a [tessel.io](https://tessel.io/) microcontroller, because it has both analog and digital gpio ports that is very easy to interact with using javascript.

![](https://1587494504-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ltn3vQOSB-YGC6qLZu_%2F-LtokHvCItp5hBZHutp_%2F-LtolZPls47hPBcsjBo1%2Fimage.png?alt=media\&token=ad4b2f5e-05de-4742-b57f-4591dfe22de8)

The Falcon PR6 contains a battery and gives a digital impulse every liter user detected. Connect the black wire to GND and the yellow to one of the numbered PINs.

![](https://1587494504-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ltn3vQOSB-YGC6qLZu_%2F-LtokHvCItp5hBZHutp_%2F-LtoleqMw0zS-gUgLLuR%2Fimage.png?alt=media\&token=de770162-a678-44ab-803e-8b51e2b2e4d0)

And when/if you order a Tessel 2, remember to also order a set of [jumper wires](https://www.sparkfun.com/products/11709)that fits.

![](https://1587494504-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ltn3vQOSB-YGC6qLZu_%2F-LtokHvCItp5hBZHutp_%2F-Ltom6OR6LKlqNMgg4i-%2FIMG_1177.jpg?alt=media\&token=499a78c4-ff27-437f-810c-9d5a549b3691)

Here is a class to read the pulse indicating one liter used.

```javascript
const  
  EventEmitter = require('events'),
  tessel = require('tessel')

const pin = tessel.port.A.pin[4]

class PulseReader extends EventEmitter {  
  constructor() {
    super()
    this.previous = false
    setInterval(() => {
      this.read()
    }, 50) // Read impulse every 50 ms
  }

  // Give a short blue LED blink to signal that an pulse is detected.
  blink() {
    blue.on()
    setTimeout(function () {
      blue.off()
    }, 100);
  }

  read() {
    pin.read((error, value) => {
      if (error) {
        console.error("Error reading analog input: " + error)
        return
      }
      let val = (value === 0)

      // Emit a value event every time a digital pulse is detected
      // Will discard all subsequent readins from the same pulse
      if (val && val !== this.previous) {
        this.emit('value', true)
        this.blink()
      }
      this.previous = val
    })
  }
}

module.exports = PulseReader
```

It can be used like this:

```javascript
let d = new Database()  
let p = new PulseReader()

p.on('value', (value) => {  
  d.post(1)
})
```
