DheerajKhajuria / pimatic-mysensors

mysensors
http://forum.mysensors.org/topic/797/pimatic-mysensors-controller-plugin
GNU General Public License v2.0
23 stars 24 forks source link

Extention for Pulse Watermeter #70

Closed mrdago closed 8 years ago

mrdago commented 8 years ago

Hi,

I've added a variable 'consumtion' to the Watermeter to measure the volume of the last water consumtion event. If the water flow returns to zero I calculate the last consumtion volume and send this value (V_VAR2) to the gateway. I guess that this measure is interesting for most of the people as this allow measuring water consumtion of every single withdrawal.

To have this function available after any update of the mysensors plugin I ask to implement this extension into the standard release.

class MySensorsWaterMeter extends env.devices.Device

constructor: (@config,lastState, @board) ->
  @id = config.id
  @name = config.name

...
  @_consumtion = lastState?.consumtion?.value
...

  env.logger.debug "MySensorsWaterMeter " , @id , @name
...
  @attributes.consumtion = {
    description: "Measure of last consumtion"
    type: "number"
    unit: ' l'
    acronym: 'last consumtion'
  }
...
        if result.type is V_VAR2
          env.logger.debug "<- MySensorsWaterMeter V_VAR2"
          @_consumtion = parseInt(result.value)
          @emit "consumtion", @_consumtion
...
getConsumtion: -> Promise.resolve @_consumtion

Here is the calculation of the last water consumtion in my Arduino sketch

   ...
   if(currentTime - lastPulse > 120000){
      flow = 0;    

      lastwc = (pulseCount - oldwc) / (unsigned long)ppl;  
      oldwc = pulseCount;     
      if(lastwc != 0){
        Serial.print("current Waterconsumtion:");
        Serial.println(lastwc);     
        gw.send(lastConsumtionMsg.setSensor(CHILD_ID).set(lastwc));      // Send consumtion value to gw
      }    
    } 
    ...
sweebee commented 8 years ago

Duplicate https://github.com/DheerajKhajuria/pimatic-mysensors/issues/69