Giter Club home page Giter Club logo

pimatic-smartmeter's People

Contributors

gitter-badger avatar mwittig avatar saberone avatar sweebee avatar

Watchers

 avatar  avatar  avatar  avatar

pimatic-smartmeter's Issues

Adapted for meter Kaifa Type: MA105

I adapted the program a little bit for my own usage but maybe other people can use this so I put it here.
These meter is wireless connected to a gasmeter Itron G4RF1e WL .
Below the adapted program en screenshot.
The graph is a little bit crowded because I added also tariff3 and 4 because of my solar panels and also the gasmeter.

/KFM5KAIFA-METER

1-3:0.2.8(40)
0-0:1.0.0(151013144451S)
0-0:96.1.1(4530303039303030303134373436313134)
1-0:1.8.1(000117.566_kWh)
1-0:1.8.2(000072.650_kWh)
1-0:2.8.1(000007.845_kWh)
1-0:2.8.2(000012.889_kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.369_kW)
1-0:2.7.0(00.000_kW)
0-0:17.0.0(999.9_kW)
0-0:96.3.10(1)
0-0:96.7.21(00008)
0-0:96.7.9(00006)
1-0:99.97.0(1)(0-0:96.7.19)(000101000001W)(2147483647_s)
1-0:32.32.0(00000)
1-0:32.36.0(00000)
0-0:96.13.1()
0-0:96.13.0()
1-0:31.7.0(001_A)
1-0:21.7.0(00.365_kW)
1-0:22.7.0(00.000_kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303139333430323138353337363135)
0-1:24.2.1(151013140000S)(00041.604_m3)

image

#Plugin pimatic-smartmeter

module.exports = (env) ->
Promise = env.require 'bluebird'

assert = env.require 'cassert'

class Smartmeter extends env.plugins.Plugin

init: (app, @framework, @config) =>
  deviceConfigDef = require("./device-config-schema")

  @framework.deviceManager.registerDeviceClass("Smartmeterdevice", {
    configDef: deviceConfigDef.Smartmeterdevice,
    createCallback: (config) => new Smartmeterdevice(config)
  })

class Smartmeterdevice extends env.devices.Sensor

attributes:
  activetariff:
    description: "Active tariff"
    type: "number"
    unit: " 1/3 or 2/4"
  actualusage:
    description: "Actual usage"
    type: "number"
    unit: " Watt"
  tariff1totalusage:
    description: "Tariff 1 total usage(T1)"
    type: "number"
    unit: " kWh"
  tariff2totalusage:
    description: "Tariff 2 total usage(T2)"
    type: "number"
    unit: " kWh"
  tariff3totalredelivery:
    description: "Tariff 3 total usage(T3)"
    type: "number"
    unit: " kWh"
  tariff4totalredelivery:
    description: "Tariff 4 total usage(T4)"
    type: "number"
    unit: " kWh"
  totalgasusage:
    description: "Total gas usage"
    type: "number"
    unit: " m3"

actualusage: 0.0
activetariff: 1
tariff1totalusage: 0.0
tariff2totalusage: 0.0
tariff3totalredelivery: 0.0
tariff4totalredelivery: 0.0    
totalgasusage: 0.0 

constructor: (config) ->

  @config = config

  @id = @config.id
  @name = @config.name
  @portName = @config.serialport
  @baudRate = @config.baudRate
  @dataBits = @config.dataBits
  @parity = @config.parity
  @stopBits = @config.stopBits
  @flowControl = @config.flowControl

  super()

  if @debug
    env.logger.debug ("Smartmeter portName : \"#{@portName}\"")
    env.logger.debug ("Smartmeter baudRate : \"#{@baudRate}\"")
    env.logger.debug ("Smartmeter dataBits : \"#{@dataBits}\"")
    env.logger.debug ("Smartmeter parity : \"#{@parity}\"")
    env.logger.debug ("Smartmeter stopBits : \"#{@stopBits}\"")


  P1DataStream = require "./p1meterdata"
  p1datastream = new P1DataStream({
    portName: @portName,
    baudRate: @baudRate,
    dataBits: @dataBits,
    parity: @parity,
    stopBits: @stopBits,
    flowControl: @flowControl
  })
  p1datastream.on 'data', (data) =>
    @actualusage = Number data.currentUsage
    @emit "actualusage", Number @actualusage

    @activetariff = Number data.currentTariff
    @emit "activetariff", Number @activetariff

    @tariff1totalusage = Number data.tariffOneTotalUsage
    @emit "tariff1totalusage", Number @tariff1totalusage

    @tariff2totalusage = Number data.tariffTwoTotalUsage
    @emit "tariff2totalusage", Number @tariff2totalusage

    @tariff3totalredelivery = Number data.tariffThreeTotalRedelivery
    @emit "tariff3totalredelivery", Number @tariff3totalredelivery

    @tariff4totalredelivery = Number data.tariffFourTotalRedelivery
    @emit "tariff4totalredelivery", Number @tariff4totalredelivery

    @totalgasusage = Number data.totalGasUsage
    @emit "totalgasusage", Number @totalgasusage

getActualusage: -> Promise.resolve @actualusage
getActivetariff: -> Promise.resolve @activetariff
getTariff1totalusage: -> Promise.resolve @tariff1totalusage
getTariff2totalusage: -> Promise.resolve @tariff2totalusage
getTariff3totalredelivery: -> Promise.resolve @tariff3totalredelivery
getTariff4totalredelivery: -> Promise.resolve @tariff4totalredelivery 
getTotalgasusage: -> Promise.resolve @totalgasusage

plugin = new Smartmeter
return plugin

p1meterdata.js =>

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var util = require("util");
var events = require("events");

var openSerialPort = function (opts, callback) {
console.log('serialport options ');
console.log(opts);

// Setup a SerialPort instance
var sp = new SerialPort(opts.portName, {
    baudRate: opts.baudRate,
    dataBits: opts.dataBits,
    parity: opts.parity,
    stopBits: opts.stopBits,
    flowControl: opts.flowControl,
    parser: serialport.parsers.readline("!")
}, false);

sp.open(function () {
    console.log('- Serial port is open');
    sp.on('data', callback);
});

return sp;

};

// Returns result from applying regex to data (string)
var returnRegExResult = function (data, regex) {
var result = data.match(regex);

if (result != undefined) {
    return result[1];
} else {
    return undefined;
}

}; // returnRegExResult

var P1DataStream = function (opts) {
console.log('P1DataStream opts ');
console.log(opts);

var self = this;
self.opts = opts;

var listener = function (data) {

    var tariffOneTotalUsage = returnRegExResult(data, /^1-0:1\.8\.1\(0+(\d+\.\d+)\*kWh\)/m);
    var tariffTwoTotalUsage = returnRegExResult(data, /^1-0:1\.8\.2\(0+(\d+\.\d+)\*kWh\)/m);
    var tariffThreeTotalRedelivery = returnRegExResult(data, /^1-0:2\.8\.1\(0+(\d+\.\d+)\*kWh\)/m);
    var tariffFourTotalRedelivery = returnRegExResult(data,  /^1-0:2\.8\.2\(0+(\d+\.\d+)\*kWh\)/m);
    var currentTariff = returnRegExResult(data, /^0-0:96.14.0\(0+(.*?)\)/m);
    var currentUsage = returnRegExResult(data, /^1-0:1.7.0\((.*?)\*/m);
    var totalGasUsage = returnRegExResult(data, /^0-1:24\.2\.1\(\d+S\)\(0+(\d+\.\d+)\*m3\)/m);

    var dataGram = {
        tariffOneTotalUsage: tariffOneTotalUsage * 1,
        tariffTwoTotalUsage: tariffTwoTotalUsage * 1,
        tariffThreeTotalRedelivery: tariffThreeTotalRedelivery * 1,
        tariffFourTotalRedelivery: tariffFourTotalRedelivery * 1,
        currentTariff: currentTariff * 1,
        currentUsage: currentUsage * 1000,
        totalGasUsage: totalGasUsage * 1
    };

    console.log('Raw data received: ' + data);
    console.log('Parsed data: ');
    console.log(dataGram);

    self.emit("data", dataGram);
};

openSerialPort(self.opts, listener);
events.EventEmitter.call(self);

};

util.inherits(P1DataStream, events.EventEmitter);

module.exports = P1DataStream;

Getting no log

Hi,
tried to install the plugin, but it does not work for me. To see what is wrong I tried to get a log file via

npm install
chmod +x logP1.js
./logP1.js

The console responses that logP1.js does not exist.

With vzlogger I am receiving data.

[Nov 05 00:00:00][main] vzlogger v0.6.0 based on heads/master-0-g462c3077bd from Sun, 30 Oct 2016 15:07:12 +0100 started.
[Nov 05 00:00:00][mtr0] Creating new meter with protocol sml.
[Nov 05 00:00:00][mtr0] Meter configured, enabled.
[Nov 05 00:00:00]       New meter initialized (protocol=sml)
[Nov 05 00:00:00]       Have 1 meters.
[Nov 05 00:00:00][main] log level is 15
[Nov 05 00:00:00][main] daemon=0, local=0
[Nov 05 00:00:00]       Process not  daemonized...
[Nov 05 00:00:00]       Opened logfile /home/pi/volkszaehler/vzlogger/log/vzlogger.log
[Nov 05 00:00:00][push] No pushDataServer defined.
[Nov 05 00:00:00][]     ===> Start meters
[Nov 05 00:00:00][mtr0] Meter connection established
[Nov 05 00:00:00][mtr0] Meter thread started
[Nov 05 00:00:00][mtr0] Meter is opened. Starting channels.
[Nov 05 00:00:00][mtr0] Number of readers: 32
[Nov 05 00:00:00][]     Startup done.
[Nov 05 00:00:00][mtr0] Config.daemon: 0
[Nov 05 00:00:00][mtr0] Config.local: 0
[Nov 05 00:00:02][mtr0] Got 4 new readings from meter:
[Nov 05 00:00:02][mtr0] Reading: id=1-0:1.8.0*255/ObisIdentifier:1-0:1.8.0*255 value=3661100.90 ts=1509836402024
[Nov 05 00:00:02][mtr0] Reading: id=1-0:1.8.1*255/ObisIdentifier:1-0:1.8.1*255 value=3661100.90 ts=1509836402024
[Nov 05 00:00:02][mtr0] Reading: id=1-0:1.8.2*255/ObisIdentifier:1-0:1.8.2*255 value=0.00 ts=1509836402024
[Nov 05 00:00:02][mtr0] Reading: id=1-0:16.7.0*255/ObisIdentifier:1-0:16.7.0*255 value=763.70 ts=1509836402024
[Nov 05 00:00:02][mtr0] Stopped reading. 
[Nov 05 00:00:02][]     Server stopped.
[Nov 05 00:00:02][]     Trying to delete curlSessionProvider...
[Nov 05 00:00:02][]     deleted curlSessionProvider

I checked the p1meterdata.js file there I found this line:
var currentUsage = returnRegExResult(data, /^1-0:1.7.0\((.*?)\*/m);
This is what I'm interested in:
1-0:1.7.0\((.*?)\*/m);

I'm not familar with js, how can I change the existing code from p1meterdata.js to get the value from this line:
1.8.0*255/ObisIdentifier:1-0:1.8.0*255 value=3661100.90

Currently I read the value this way from the log via logWatcher Plugin of Pimatic:
1-0:1.8.0\x2a255\x20value=(.+)

auto-update sqlite3 want higher peerDependencies

I update Pimatic with the GUI and run up multiples errors. One was that the peerDependencies in package.json was to low. I updated it to below and reinstall the plugging. Only then it was working. it seems that the plugin don't like pimatic 0.9...

"peerDependencies": {
"pimatic": ">=0.8.0 <1.0.0"

I remove sqlite3 with sudo rm -rf /home/pi/pimatic-app/node_modules/sqlite3
and then installed manualy in sudo su with sudo npm install sqlite3.

It was nevewracking but when it was a succes it feels like a triompf! :)

If you nead more logging let me know.

No Data in Pimatic

Hello,
I use your plugin with this setup:
{
"id": "smartmeter",
"class": "Smartmeterdevice",
"name": "Smartmeter Strom",
"serialport": "/dev/ttyAMA0",
"baudRate" : 9600,
"dataBits" : 7,
"parity" : "even",
"stopBits" : 1,
"flowControl" : true
},

My electric meter gives with cat /dev/ttyAMA0 following information:

/ISk5MT671-0001

1-0:0.0.0*255(331300-5033124)

1-0:1.8.1*255(033238.2842)

1-0:96.5.5*255(80)

0-0:96.1.255*255(39225479)
!

There is only the meter reading 1-0:1.8.1*255(033238.2842) what means 33238.2842 kWh interesting.

Now your plugin shows in my Pimatic installation no data.

Hope you can help me.

Best regards
Andre

P1 smartmeter variables are not being logged

Hello,

I am using the plugin and it works like a charm!

But i want to see my usage for the day and week.

I have a clean install with the smart meter connected to USB0 and i'm getting the data.

The config:

"devices": [
{
"id": "smartmeter",
"class": "Smartmeterdevice",
"name": "Smartmeter",
"serialport": "/dev/ttyUSB0",
"baudRate": 9600,
"dataBits": 7,
"parity": "even",
"stopBits": 1,
"flowControl": true
},

But the database is not logging any variable.

How can i let pimatic log those values?

Thank you

Gasmeter not logging

Hi All,

I'm struggling to get my gasmeter working, energy consumption is working correctly.

Output from smartmeter:

---BEGIN--
0DA4
/XMX5LGBBFG1009264202

1-3:0.2.8(42)
0-0:1.0.0(160206093352W)
0-0:96.1.1(4530303331303033313732393931323135)
1-0:1.8.1(000022.940*kWh)
1-0:1.8.2(000035.495*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(00.349*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00001)
0-0:96.7.9(00000)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00000)
0-0:96.13.1()
0-0:96.13.0()
1-0:31.7.0(002*A)
1-0:21.7.0(00.349*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303235303033333236333939303135)
0-1:24.2.1(160206090000W)(00060.913*m3)
---END----

In p1meterdata.js I have this regex;
var gasTotalUsage = returnRegExResult(data, /^0-1:24\.2\.1\(\d+[SW]\)\((\d+\.\d+)\*m3\)/m);

As far I can test the regex is working: https://regex101.com/r/kY1pE6/1

The status of gas usage is saying "Unknown" , any suggestions were to look ? I think i'm missing something.

Can't get it working

Hello,

I also want to read the data from the p1 port.
The cable to the smartmeter works under windows, but on the raspberry pi the data on the therminal isn't readable.

pi@raspberrypi:~ $ sudo cat /dev/ttyUSB0 ▒KMP5▒KA6U00▒5▒5▒▒▒3▒▒▒ ▒ 0-0:96.▒.▒(▒0▒B▒▒365530303▒353▒353▒3▒3▒333▒3▒▒▒ ▒-0:▒.▒.▒(033▒9.▒▒▒▒▒▒詍 ▒-0:▒.▒.▒(03▒▒6.60▒▒▒▒詍 ▒-0:▒.▒.▒(00000.000▒▒▒詍 ▒-0:▒.▒.▒(00000.000▒▒▒詍 0-0:96.▒▒.0(000▒▒▒ ▒-0:▒.▒.0(0000.09▒▒ש▒ ▒-0:▒.▒.0(0000.00▒▒ש▒ 0-0:96.▒3.▒(▒▒ 0-0:96.▒3.0(▒▒ 0-▒:▒▒.▒.0(3▒▒ 0-▒:96.▒.0(3▒3▒3▒303▒353▒3▒30303▒3▒3▒3▒353▒3▒▒▒ 0-▒:▒▒.3.0(▒60▒0▒▒▒0000▒(0▒▒(60▒(▒▒(0-▒:▒▒.▒.▒▒(▒3▒▒ (053▒3.669▒▒ !▒

Also on pimatic in the log I get a list of errors.

error [pimatic-log-reader]: ENOENT, open '/dd_extern/tmp/conso.log' 20:05:16error [pimatic-log-reader]: ENOENT, open '/dd_extern/tmp/conso.log' 20:05:16error [pimatic]: Could not get attribute value of Électricité.Compteur: Expected variable consoelec.tick_elec to have a numeric value. 20:05:16error [pimatic]: Could not get attribute value of Gaz.Compteur: Expected variable consogaz.tick_gaz to have a numeric value. 20:05:15error [pimatic]: Could not get attribute value of Gaz.Conso_inst: Expected variable consogaz.cons_gaz_inst to have a numeric value. 20:05:15error [pimatic]: Could not get attribute value of Gaz.Conso_jour: Could not parse expression 20:05:13error [pimatic]: Could not get attribute value of Électricité.Conso_jour: Could not parse expression 20:05:06error [pimatic]: Error loading device smartmeter: Error parsing /home/pi/pimatic-app/node_modules/pimatic-smartmeter/node_modules/serialport/package.json: Unexpected end of input

Settings in pimatic
"id": "smartmeter", "class": "Smartmeterdevice", "name": "Smartmeter", "serialport": "/dev/ttyUSB0", "baudRate": 9600, "dataBits": 7, "parity": "even", "stopBits": 1, "flowControl": true

Who can give me a hint to solve this problem.
Thank you in advance.

Baud rate

Hi nice work on the plugin.
My meter uses a different baud rate, could you make the baud rate a config option aswel?

{
  "plugin": "smartmeter",
  "serialport": "/dev/ttyUSB0",
  "baudrate": 115200
}

EDIT my meter also uses 8N1 :(
maybe other options aswel so more people will be able to use it
baudRate: 115200,
dataBits: 7,
parity: 'even',
stopBits: 1,
flowControl: true,

No data on Raspberry

Hai Saberone,

Today I connected a CH340 USD-Serial converter to my Raspberry Pi B. Using the command CU I see a lot of blanc spaces and in Pimatic all I get is 0 Watt etc. When I connect the convertor to my PC and using Putty I get readable data on my screen.

The smartmeter is a Kaifa MA105. The settings in the device settings are:
"id": "smartmeter",
"class": "Smartmeterdevice",
"name": "Smartmeter",
"serialport": "/dev/ttyUSB0",
"baudRate": 115200,
"dataBits": 8,
"parity": "none",
"stopBits": 1,
"flowControl": true

I don't know what I'm doing wrong. Your help is needed!

Regards,
David

gastotalusage not filled

I have an Itron smartmeter for Gas. It looks like it transfers its data to the my Landis+Gyr smartmeter for Electra (which is connected to Raspberry Pi with Pimatic). Electra readings are correctly populated, however I miss the gas readings. When checking the output I do see it appearing:

1-3:0.2.8(42)
0-0:1.0.0(170224182239W)
0-0:96.1.1(4530303330303033373236343938353136)
1-0:1.8.1(000014.005kWh)
1-0:1.8.2(000036.177
kWh)
1-0:2.8.1(000000.000kWh)
1-0:2.8.2(000000.000
kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.886kW)
1-0:2.7.0(00.000
kW)
0-0:96.7.21(00002)
0-0:96.7.9(00000)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:52.32.0(00000)
1-0:72.32.0(00001)
1-0:32.36.0(00000)
1-0:52.36.0(00000)
1-0:72.36.0(00000)
0-0:96.13.1()
0-0:96.13.0()
1-0:31.7.0(002A)
1-0:51.7.0(000
A)
1-0:71.7.0(003A)
1-0:21.7.0(00.349
kW)
1-0:41.7.0(00.011kW)
1-0:61.7.0(00.526
kW)
1-0:22.7.0(00.000kW)
1-0:42.7.0(00.000
kW)
1-0:62.7.0(00.000kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303139333430333231303838373136)
0-1:24.2.1(170224180000W)(00026.135
m3)
!B184
/XMX5LGBBFG1012751414

Next line from above looks like my gas reading:

0-1:24.2.1(170224180000W)(00026.135*m3)

Can you check or tell me how I can make sure that it is populated into the gasmeter2.gastotalusage attribute.

Problems with node 0.10.24

Some people have problems with serialport 2.0.6 on the older node version. While for others it works fine.

Could you create a separate branch for pimatic 0.9.x ? and publish both to npm. One for pimatic 0.8 and one for 0.9.

0.8 needs serialport 1.4.5:

"dependencies": {
    "serialport": "~1.4.5"
  },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.