node-echonet-liteを用いて太陽光発電、蓄電池、エコキュートから情報を取得する
公開されているサンプルを参考に、Node.jsで実装
詳細やエアコンからの情報取得についてはこちらを参照
太陽光発電
//Solar
function getOperationStatus_Solar(address, eoj) {
var esv = 'Get';
var prop = [
{ 'epc': 0x80, 'edt': null }, // ON/OFF
{ 'epc': 0xE0, 'edt': null } // 発電量
];
el.send(address, eoj, esv, prop, (err, res) => {
console.log('[Solar] @' + address);
console.log(' Err : ' + err);
console.log(' ESV : ' + res['message']['esv']);
var vStatus = '';
var vWatt = '';
for (let element of res['message']['prop']){
//console.dir(element);
var epc = element['epc'];
var edt = element['edt'];
if (epc === 0x80) {
vStatus = (edt['status'] ? 'on' : 'off');
//saveToFile(dataDIR+"/solar@"+address+"_Power",desc);
console.log(' Power : ' + vStatus);
}else if (epc === 0xE0) {
vWatt = element['buffer'][0]*256 + element['buffer'][1];
//saveToFile(dataDIR+"/solar@"+address+"_Generate",num);
console.log(' Electric generate : ' + vWatt + '[W]');
} else{
console.dir(element);
}
}
});
getOperationStatus_Battery(address);
}
蓄電池
//Battery
function getOperationStatus_Battery(address) {
var esv = 'Get';
var eoj = new Array(0x2,0x7d,1);
var prop = [
{ 'epc': 0x80, 'edt': null }, // ON/OFF
{ 'epc': 0xA0, 'edt': null }, //
{ 'epc': 0xA1, 'edt': null }, //
{ 'epc': 0xA2, 'edt': null }, //
{ 'epc': 0xA3, 'edt': null }, //
{ 'epc': 0xA4, 'edt': null }, //
{ 'epc': 0xA5, 'edt': null }, //
{ 'epc': 0xCF, 'edt': null }, //
{ 'epc': 0xD3, 'edt': null }, //
{ 'epc': 0xE4, 'edt': null }, //
{ 'epc': 0xE5, 'edt': null } //
];
el.send(address, eoj, esv, prop, (err, res) => {
console.log('[Battery] @' + address);
console.log(' Err : ' + err);
console.log(' ESV : ' + res['message']['esv']);
var vStatus = "";
var vEffectiveCapacity_charge = "";
var vEffectiveCapacity_disCharge = "";
var vChargeableCapacity = "";
var vDischargeableCapacity = "";
var vCapacity_charge = "";
var vCapacity_discharge = "";
var vOutput = "";
var vMode = "";
var vBatteryLevel = "";
var vDeterioration = "";
for (let element of res['message']['prop']){
//console.dir(element);
var epc = element['epc'];
var edt = element['edt'];
if (epc === 0x80) {
vStatus = (edt['status'] ? 'on' : 'off');
//saveToFile(dataDIR+"/battery@"+address+"_Power",desc);
console.log(' Power : ' + vStatus);
} else if (epc === 0xA0) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vEffectiveCapacity_charge = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_EffectiveCapacity_charge",num);
console.log(' AC実効容量(充電) : ' + vEffectiveCapacity_charge + '[Wh]');
} else if (epc === 0xA1) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vEffectiveCapacity_disCharge = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_EffectiveCapacity_discharge",num);
console.log(' AC実効容量(放電) : ' + vEffectiveCapacity_disCharge + '[Wh]');
} else if (epc === 0xA2) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vChargeableCapacity = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_ChargeableCapacity",num);
console.log(' AC充電可能容量 : ' + vChargeableCapacity + '[Wh]');
} else if (epc === 0xA3) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vDischargeableCapacity = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_DischargeableCapacity",num);
console.log(' AC放電可能容量 : ' + vDischargeableCapacity + '[Wh]');
} else if (epc === 0xA4) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vCapacity_charge = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_Capacity_charge",num);
console.log(' AC充電可能量(現時点での) : ' + vCapacity_charge + '[Wh]');
} else if (epc === 0xA5) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vCapacity_discharge = num0 + num1 + num2 + num3;
//saveToFile(dataDIR+"/battery@"+address+"_Capacity_discharge",num);
console.log(' AC放電可能量(現時点での) : ' + vCapacity_discharge + '[Wh]');
} else if (epc === 0xD3) {
var num0 = element['buffer'][0]<<24;
var num1 = element['buffer'][1]<<16;
var num2 = element['buffer'][2]<<8;
var num3 = element['buffer'][3];
vOutput = num0 + num1 + num2 + num3;
if (vOutput > 0xC4653601 ){
vOutput = vOutput - 0x100000000a;
}
//saveToFile(dataDIR+"/battery@"+address+"_Output",num);
console.log(' 瞬間充放電電力計測値 : ' + vOutput + '[W]');
} else if (epc === 0xCF) {
vMode = element['buffer'][0];
switch(vMode){
case 0x41:
vMode = "急速充電";
break;
case 0x42:
vMode = "充電";
break;
case 0x43:
vMode = "放電";
break;
case 0x44:
vMode = "待機";
break;
case 0x45:
vMode = "テスト";
break;
case 0x46:
vMode = "自動";
break;
case 0x48:
vMode = "再起動";
break;
case 0x49:
vMode = "実効容量再計算処理";
break;
case 0x40:
vMode = "その他";
break;
default:
}
//saveToFile(dataDIR+"/battery@"+address+"_Mode",desc);
console.log(' Mode : ' + vMode);
} else if (epc === 0xE4) {
vBatteryLevel = element['buffer'][0];
//saveToFile(dataDIR+"/battery@"+address+"_BatteryLevel",desc);
console.log(' 蓄電池残量 : ' + vBatteryLevel + "[%]");
} else if (epc === 0xE5) {
vDeterioration = element['buffer'][0];
//saveToFile(dataDIR+"/battery@"+address+"_Deterioration",desc);
console.log(' 劣化状態 : ' + vDeterioration + "[%]");
} else{
console.dir(element);
}
}
});
}
エコキュート
//Ecocute
function getOperationStatus_EcoCute(address, eoj) {
var esv = 'Get';
var prop = [
{ 'epc': 0x80, 'edt': null }, // ON/OFF
{ 'epc': 0xB2, 'edt': null }, // 炊き上げ中
{ 'epc': 0xC3, 'edt': null }, // 給湯中
{ 'epc': 0xE1, 'edt': null } // 残湯量
];
el.send(address, eoj, esv, prop, (err, res) => {
console.log('[EcoCute] @' + address);
console.log(' Err : ' + err);
console.log(' ESV : ' + res['message']['esv']);
var vStatus = "";
var vHotWaterMake = "";
var vHotWaterOutput = "";
var vHotWaterVolume = "";
for (let element of res['message']['prop']){
//console.dir(element);
var epc = element['epc'];
var edt = element['edt'];
if (epc === 0x80) {
vStatus = (edt['status'] ? 'on' : 'off');
console.log(' Power : ' + vStatus);
//saveToFile(dataDIR+"/ecocute@"+address+"_Power",desc);
} else if (epc === 0xB2) {
hotWaterMake = element['buffer'][0];
if (vHotWaterMake === 0x41) {
vHotWaterMake = 1;
console.log(' Hot water : making (' + vHotWaterMake + ')');
//saveToFile(dataDIR + "/ecocute@" + address + "_HotWaterMake", "making");
}else if (hotWaterMake === 0x42){
vHotWaterMake = 0;
console.log(' Hot water : not making (' + vHotWaterMake + ')');
//saveToFile(dataDIR + "/ecocute@" + address + "_HotWaterMake", "not making");
}
} else if (epc === 0xC3) {
vHotWaterOutput = element['buffer'][0];
if (vHotWaterOutput === 0x41) {
vHotWaterOutput = 1;
console.log(' Hot water : output (' + vHotWaterOutput + ')');
//saveToFile(dataDIR + "/ecocute@" + address + "_HotWaterOutput", "output");
}else if (vHotWaterOutput === 0x42){
vHotWaterOutput = 0;
console.log(' Hot water : no output (' + vHotWaterOutput + ')');
//saveToFile(dataDIR + "/ecocute@" + address + "_HotWaterOutput", "no output");
}
} else if (epc === 0xE1) {
vHotWaterVolume = element['buffer'][0]*256 + element['buffer'][1];
console.log(' Hot water volume : ' + vHotWaterVolume + '[l]');
//saveToFile(dataDIR + "/ecocute@" + address + "_HotWaterVolume", num);
} else{
console.dir(element);
}
}
});
}
コメントを投稿