Hi, meine Powerwall will seit dem letzten Update nicht mehr mit dem Javascript laufen da Tesla nun ein selbstsegniertes Cert. eingebunden hat.
Bekomme immer:
javascript.0 2021-07-11 09:41:00.017 error (1280) Request error: Error: Client network socket disconnected before secure TLS connection was established
javascript.0 2021-07-11 09:41:00.017 error (1280) script.js.common.PowerWall-Abruf: Request PowerWall meldet Fehler: Error: Client network socket disconnected before secure TLS connection was established
Wie kann ich in JS das Certificate erlauben?
Hier das Script:
Quelle & Urheber MeSwissX: https://tff-forum.de/t/powerwall-2-daten-auslesen-per-api/34214/26
Code:
const ipPowerwall = '192.168.1.142';
const userEmail = "thierry@girard.li";
const password = "thgiPowerwall";
var logOn = false;
createState("photovoltaik.PowerWall", 0.0); // Ladezustand PowerWall in %
createState("photovoltaik.PowerWallErrorReported", false);
createState("photovoltaik.PowerWallDown", false);
createState("photovoltaik.powerWall.error", false);
createState("photovoltaik.powerWall.down", false);
createState("photovoltaik.powerWall.battery", 0.0); // Ladezustand PowerWall in %
createState("photovoltaik.powerWall.power_netz", 0.0); // Energie Netz
createState("photovoltaik.powerWall.power_battery", 0.0); // Energie Batterie
createState("photovoltaik.powerWall.power_haus", 0.0); // Energie Haus
createState("photovoltaik.powerWall.power_solar", 0.0); // Energie Photovoltaik
var powerWallErrorReported = 'javascript.0.photovoltaik.PowerWallErrorReported';
var PowerWallDown = 'javascript.0.photovoltaik.PowerWallDown';
getPWCookie();
function getPWCookie() {
const https = require("https");
const cookieUrl = 'https://'+ipPowerwall+'/api/login/Basic';
var request = require("request");
var agentOptions;
var agent;
agentOptions = {
host: ipPowerwall
, port: '443'
, path: '/api/login/Basic'
, rejectUnauthorized: false
};
agent = new https.Agent(agentOptions);
var headers = { 'Content-Type': 'application/json' };
var dataString = '{"username": "customer","email": "'+userEmail+'","password":"'+password+'"}';
var options = {
url: cookieUrl,
method: 'POST',
headers: headers,
body: dataString,
agent: agent
};
request(options, function (error, response, body) {
// if (err) log(JSON.stringify(err));
// if (resp) log(JSON.stringify(resp));
if (!error && response.statusCode == 200) {
// if(logon) { log('powerWall_Cookie_login_success') };
try {
var json = JSON.parse(body);
var token = json.token;
getPWDataNew(token);
} catch (e) {
if (e instanceof SyntaxError) {
log("json parse error: " + e);
} else {
log("json parse error - other: " + e);
}
}
} else {
log('Request PowerWall meldet Fehler: ' + error, 'error');
if (getState(powerWallErrorReported).val === false) {
setState(powerWallErrorReported,true);
//pushover
sendTo('pushover.0', {
message: 'PowerWall Error',
title: 'POWERWALL',
priority: 1,
sound: 'magic'
});
}
}
});
}
function getPWDataNew(token) {
const https = require("https");
const urlBatterySoe = 'https://'+ipPowerwall+'/api/system_status/soe';
const urlAggregates = 'https://'+ipPowerwall+'/api/meters/aggregates';
var request = require("request");
var agentOptions;
var agent;
agentOptions = {
host: ipPowerwall
, port: '443'
, path: '/'
, rejectUnauthorized: false
};
agent = new https.Agent(agentOptions);
var headers = {
'Content-Type': 'application/json',
'Cookie' : 'AuthCookie='+token
};
var optionsBatterySoe = {
url: urlBatterySoe,
method: 'GET',
headers: headers,
agent: agent
};
var optionsAggregates = {
url: urlAggregates,
method: 'GET',
headers: headers,
agent: agent
};
request(optionsBatterySoe, function (error, response, body) {
// if (error) log(JSON.stringify(error));
// if (response) log(JSON.stringify(response));
if (!error && response.statusCode == 200) {
// if (logon) {log('powerWall readout success!!')};
setState(powerWallErrorReported,false);
setState(PowerWallDown,false);
if (body) {
batteryPercentage(body);
}
} else {
log('powerWall battery readout Fehler: ' + error, 'error');
}
});
request(optionsAggregates, function (error, response, body) {
// if (error) log(JSON.stringify(error));
// if (response) log(JSON.stringify(response));
if (!error && response.statusCode == 200) {
// if (logon) {log('powerWall readout success!!')};
if (body) {
aggregatesVerarbeiten(body);
}
} else {
log('powerWall aggregates readout Fehler: ' + error, 'error');
}
});
}
// analyse PowerWall Battery Percentage
function batteryPercentage(result) {
try {
var json = JSON.parse(result);
var ladungPowerWall = Number(json.percentage);
if (logOn) log("PowerWall Ladezustand: " + ladungPowerWall + " %");
setState("javascript.0.photovoltaik.PowerWall"/*PowerWall Ladezustand in %*/,ladungPowerWall);
} catch (e) {
if (e instanceof SyntaxError) {
log("json parse error: " + e);
} else {
log("json parse error - other: " + e);
}
}
}
// analyse PowerWall aggregates
function aggregatesVerarbeiten(result) {
try {
var json = JSON.parse(result);
var sitePower = Number(json.site.instant_power);
var batteryPower = Number(json.battery.instant_power);
var loadPower = Number(json.load.instant_power);
var solarPower = Number(json.solar.instant_power);
setState('photovoltaik.powerWall.power_netz',sitePower);
setState('photovoltaik.powerWall.power_battery',batteryPower);
setState('photovoltaik.powerWall.power_haus',loadPower);
setState('photovoltaik.powerWall.power_solar',solarPower);
if (logOn) log("PowerWall site: " + sitePower + ' battery: ' + batteryPower + ' load: ' + loadPower + ' solar: ' + solarPower);
} catch (e) {
if (e instanceof SyntaxError) {
log("json aggregates parse error: " + e);
} else {
log("json aggregates parse error - other: " + e);
}
}
}
// Startet das Skript alle 1 minuten neu
schedule("* * * * *", function() {
getPWCookie();
});
Hoffe ihr könnt mir helfen