Skip to content

Commit

Permalink
Merge pull request #38 from JeromeGillard/master
Browse files Browse the repository at this point in the history
Add support for Obis codes `1-0:1.4.0`, `1-0:2.4.0`, `1-0:1.6.0`, `1-0:2.6.0`, `0-0:98.1.0`
  • Loading branch information
ruudverheijden authored Nov 19, 2023
2 parents 0271cfa + 63ca614 commit 0750199
Show file tree
Hide file tree
Showing 3 changed files with 626 additions and 1 deletion.
122 changes: 122 additions & 0 deletions lib/parsePacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ function parsePacket(packet) {
}
}
}
},
demand: {
positiveActiveDemand: {
currentDemandPeriod: {
reading: null,
unit: null
},
maximumDemand: {
timestamp: null,
reading: null,
unit: null
}
},
negativeActiveDemand: {
currentDemandPeriod: {
reading: null,
unit: null
},
maximumDemand: {
timestamp: null,
reading: null,
unit: null
}
},
maximumDemandLastMonths: {
count: null,
months: null
}
}
},
gas: {
Expand Down Expand Up @@ -394,6 +422,54 @@ function parsePacket(packet) {
parsedPacket.electricity.fuseThreshold.unit = 'A';
break;

/*
* Demands mappings, seen in Belgian peak tariff with meterType FLU5\253770234_A v50217.
*/
case "1-0:1.4.0": // Positive active demand in a current demand period (A+) [kW]
parsedPacket.electricity.demand = parsedPacket.electricity.demand || {};
parsedPacket.electricity.demand.positiveActiveDemand = parsedPacket.electricity.demand.positiveActiveDemand || {};
parsedPacket.electricity.demand.positiveActiveDemand.currentDemandPeriod = {};
parsedPacket.electricity.demand.positiveActiveDemand.currentDemandPeriod.reading = parseFloat(line.value);
parsedPacket.electricity.demand.positiveActiveDemand.currentDemandPeriod.unit = line.unit;
break;

case "1-0:2.4.0": // Negative active demand in a current demand period (A-) [kW]
parsedPacket.electricity.demand = parsedPacket.electricity.demand || {};
parsedPacket.electricity.demand.negativeActiveDemand = parsedPacket.electricity.demand.negativeActiveDemand || {};
parsedPacket.electricity.demand.negativeActiveDemand.currentDemandPeriod = {};
parsedPacket.electricity.demand.negativeActiveDemand.currentDemandPeriod.reading = parseFloat(line.value);
parsedPacket.electricity.demand.negativeActiveDemand.currentDemandPeriod.unit = line.unit;
break;

case "1-0:1.6.0": // Positive active maximum demand (A+) total [kW]
parsedPacket.electricity.demand = parsedPacket.electricity.demand || {};
parsedPacket.electricity.demand.positiveActiveDemand = parsedPacket.electricity.demand.positiveActiveDemand || {};
parsedPacket.electricity.demand.positiveActiveDemand.maximumDemand = {};
parsedPacket.electricity.demand.positiveActiveDemand.maximumDemand.timestamp = _parseTimestamp(line.value);
const padmdVal = _parseLine(line.obisCode + lines[i].substring(24));
parsedPacket.electricity.demand.positiveActiveDemand.maximumDemand.reading = parseFloat(padmdVal.value);
parsedPacket.electricity.demand.positiveActiveDemand.maximumDemand.unit = padmdVal.unit;
break;

case "1-0:2.6.0": // Negative active maximum demand (A-) total [kW]
parsedPacket.electricity.demand = parsedPacket.electricity.demand || {};
parsedPacket.electricity.demand.negativeActiveDemand = parsedPacket.electricity.demand.negativeActiveDemand || {};
parsedPacket.electricity.demand.negativeActiveDemand.maximumDemand = {};
parsedPacket.electricity.demand.negativeActiveDemand.maximumDemand.timestamp = _parseTimestamp(line.value);
const nadmdVal = _parseLine(line.obisCode + lines[i].substring(24));
parsedPacket.electricity.demand.negativeActiveDemand.maximumDemand.reading = parseFloat(nadmdVal.value);
parsedPacket.electricity.demand.negativeActiveDemand.maximumDemand.unit = nadmdVal.unit;
break;

case "0-0:98.1.0": // Maximum demand - Active energy import of the last 13 months
const mdaeil13m = _parseMaximumDemandLastMonths(lines[i]);
if(mdaeil13m != -1){
parsedPacket.electricity.demand = parsedPacket.electricity.demand || {};
parsedPacket.electricity.demand.maximumDemandLastMonths = parsedPacket.electricity.demand.maximumDemandLastMonths || {};
parsedPacket.electricity.demand.maximumDemandLastMonths = mdaeil13m;
}
break;

/*
* Handling anything not matched so far
*/
Expand Down Expand Up @@ -505,6 +581,52 @@ function _parsePowerFailureEventLog(value) {
return output;
}

/**
*
* @param value : the capture buffer. Example:
* 0-0:98.1.0(10)(1-0:1.6.0)(1-0:1.6.0)(230201000000W)(230129181500W)(05.380*kW)(230301000000W)(230210183000W)(05.769*kW)(230401000000S)(230312180000W)(06.309*kW)(230501000000S)(230410180000S)(05.310*kW)(230601000000S)(230506184500S)(04.369*kW)(230701000000S)(230610071500S)(05.253*kW)(230801000000S)(230727003000S)(04.364*kW)(230901000000S)(230824173000S)(04.689*kW)(231001000000S)(230923121500S)(04.278*kW)(231101000000W)(231014121500S)(05.416*kW)
*/
function _parseMaximumDemandLastMonths(value) {
const split = value.substring(0, value.length-1).split(")(");
if (split[0] && split[1]) {
let output = {
count: parseInt(split[0].substring(11)),
months: []
};
//console.log("_parseMaximumDemandLastMonths", split, "output", output);

// Loop the buffer structure: timestamp)(timestamp)(value*unit)...
for (let i = 0; i < split.length;) {
if(split[i] == "0-0:98.1.0(10" || split[i] == "1-0:1.6.0"){
i++;
continue;
}
else {
try{

const monthEntry = {
month: _parseTimestamp(split[i]),
timestamp: _parseTimestamp(split[i+1]),
value: parseFloat(split[i+2].split('*')[0]),
unit: split[i+2].split('*')[1],
}
//console.log("monthEntry", split[i], monthEntry);
output.months.push(monthEntry);
} catch (ex){
// something is wrong here
}
i+=3;
}
}
return output;
}
else
{
return -1;
}

}

/**
* Parse hourly readings, which is used for gas, water, heat, cold and slave electricity meters
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "p1-reader",
"version": "2.0.4",
"version": "2.0.5",
"description": "Node.js package for reading and parsing data from the P1 port of a Smart Meter",
"main": "main.js",
"author": "Ruud Verheijden",
Expand Down
Loading

0 comments on commit 0750199

Please sign in to comment.