Het script waarmee ik bezig ben werkt tot waar ik in het script aangeef dat ik een network request failed krijg. Ik kan in dat geval alleen homeyscript herstarten om weer verder te kunnen. Waarna exact hetzelfde gebeurt als ik het script weer start. Ik heb getracht wat wachttijden in te vullen, maar dat lost niets op. Herstarten van Homey lost het ook niet op.
Ligt het aan het script dat ik schrijf, belast ik de cpu te veel? zo heftig is dit script toch niet?
function getDaysInMonth(year, month)
{
return new Date(year, month, 0).getDate();
}
function toMonthName(monthNumber)
{
const date = new Date();
date.setMonth(monthNumber);
return date.toLocaleString('en-US',
{
month: 'long',
});
}
const date = new Date();
const currentYear = date.getFullYear();
console.log('This year is: '+currentYear);
const currentMonth = date.getMonth() + 1;
console.log('This month is: '+currentMonth);
const currentMonthTwoDigits = ("0" +currentMonth).slice(-2);
console.log('This Month with two digits: ' +currentMonthTwoDigits);
const daysInCurrentMonth = getDaysInMonth(currentYear, currentMonth);
console.log('Days in current month: ' +daysInCurrentMonth);
const currentDay = new Date().getDate();
console.log('What daynumer is is today: ' +currentDay);
const currentDayTwoDigits = ("0" +currentDay).slice(-2);
console.log('This day with two digits: ' +currentDayTwoDigits);
//fill in yourself these variables
const id = '1590338';//Fill in between ' ' the Id of your SolarEdge
const apiKey = 'xx';// Fill in between ' 'your Solaredge Api key
const installYear = 2020;//Fill in installation year of your Solar Panels
const installMonth = 7;//Fill in installation month of your Solar Panels
const installMonthTwoDigits = ("0" +installMonth).slice(-2);
console.log('Instal month with two digits: ' +installMonthTwoDigits);
const installDay = 23;//Fill in installation day of your Solar Panels
const installDayTwoDigits = ("0" +installDay).slice(-2);
console.log('Instal day with two digits: ' +installDayTwoDigits)
const manualUpdate = false;//Fill in true if you want to retrieve the data for the daylight prognosis
const degeneration = 0.004;// Fill in the SolarDegeneration per year
const latitude = 53.033548;//Fill in latitude in decimal degrees South add a '-' in front of the degrees
const longitude = -5.661103;//Fill in longitude in decimal degrees, For East add a '-' in front of the degrees
monthUpdate = global.get('monthUpdate')//before running this script for the first time make a new script wirh the following sentence: global.set('monthUpdate', false);
var production = [0,0,0,0,0,0,237,814,619,265,177,76,163,297,474,785,803,962,870,702,555,369,155,96,131,297,739,787,915,980,902];
var count = 0
while(count <= (currentYear - installYear))
{
global.set('productionWithMonthAndYear'+count , []);
await wait(1000)
count++
}
var count = 0
var number = 0
while (((count * 12)) < (Math.ceil(production.length / 12)) * 12)
{
var productionYear = production.slice(count * 12,(count * 12) + 12)
global.set('productionYear' +number , productionYear);
console.log('productionYear' +number +' = : ' +productionYear)
var productionWithMonthAndYear = global.get('productionYear' +number);
global.set('productionWithMonthAndYear' +number , productionWithMonthAndYear);
//console.log('productionWithMonthAndYear' +number +' = : ' +productionWithMonthAndYear)
await wait(1000)
count++
number++
}
var count = 0
var number = 0
while(count <= (currentYear - installYear))
{
productionWithMonthAndYear = global.get('productionWithMonthAndYear' +number)
productionWithMonthAndYear = productionWithMonthAndYear.map(a => "'" +('' +(installYear + count)).slice(-2) +'(' +a +')');
monthLetters = ['01','02','03','04','05','06','07','08','09','10','11','12']
var count1 = 0
var arrayLength = (productionWithMonthAndYear.length -1)
console.log('array length is: ' +arrayLength)
while(count1 <= arrayLength)
{
productionWithMonthAndYear.splice(count1,1,'' +monthLetters[count1] +productionWithMonthAndYear[count1]);
global.set('productionWithMonthAndYear' +number , productionWithMonthAndYear);
await wait(300)
count1++
console.log(productionWithMonthAndYear)
}
await wait(500)
count++
number++
}
await wait(5000)
var count = 0
var teller = 1
var arrayIndex = 0
var number = 0
var temporarily = new Array();
//Vanaf hier krijg ik steeds een Network request failed
while(count <= (currentYear -installYear));
{
var productionYearFirst = global.get('productionYear' +count);
//var productionYearSecond = global.get('productionYear' +(count + 1));
console.log('productionYearFirst is : ' +productionYearFirst +' Lengte van deze array is: ' +productionYearFirst.length )
//console.log('productionYearSecond is : ' +productionYearSecond +' Lengte van deze array is: ' +productionYearSecond.length )
//var productionWithMonthAndYearFirst = global.get('productionWithMonthAndYear' +count);
//var productionWithMonthAndYearSecond = global.get('productionWithMonthAndYear' +(count + 1));
//console.log('productionWithMonthAndYearFirst is : '+productionWithMonthAndYearFirst +' Lengte van deze array is: ' +productionWithMonthAndYearFirst.length )
//console.log('productionWithMonthAndYearSecond is : '+productionWithMonthAndYearSecond +' Lengte van deze array is: ' +productionWithMonthAndYearSecond.length )
}
//var count = 0
//var teller = 1
//var arrayIndex = 0
//var number = 0
//var temporarily = new Array();
//while(count <= (currentYear -installYear));
//{
//var productionYearFirst = global.get('productionYear' +count);
//var productionYearSecond = global.get('productionYear' +(count + 1));
//console.log('productionYearFirst is : ' +productionYearFirst +' Lengte van deze array is: ' +productionYearFirst.length )
//console.log('productionYearSecond is : ' +productionYearSecond +' Lengte van deze array is: ' +productionYearSecond.length )
//var productionWithMonthAndYearFirst = global.get('productionWithMonthAndYear' +count);
//var productionWithMonthAndYearSecond = global.get('productionWithMonthAndYear' +(count + 1));
//console.log('productionWithMonthAndYearFirst is : '+productionWithMonthAndYearFirst +' Lengte van deze array is: ' +productionWithMonthAndYearFirst.length )
//console.log('productionWithMonthAndYearSecond is : '+productionWithMonthAndYearSecond +' Lengte van deze array is: ' +productionWithMonthAndYearSecond.length )
//while(arrayIndex <= 11)
//{
//if (productionWithMonthAndYearFirst.length > 0 && productionWithMonthAndYearSecond.length > 0 )
//{
//temporarily.push(''+productionWithMonthAndYearFirst[arrayIndex] +' kWh' +'\t' +'\t' +productionWithMonthAndYearSecond[arrayIndex] +' kWh(' +(productionYearSecond[arrayIndex] - productionYearFirst[arrayIndex]) +')' + '\r\n')
//console.log(''+temporarily[arrayIndex])
//await wait(1000)
//arrayIndex++
//}
//else
//{
//temporarily.push(''+productionWithMonthAndYearFirst[arrayIndex] +' kWh' + '\r\n')
//console.log(''+temporarily[arrayIndex])
//await wait(1000)
//arrayIndex++
//}
//}
//global.set('result' +number , temporarily);
//result = global.get('result' +number)
//console.log('Result'+number +' is ' +result)
//var productionYearFirst = [];
//var productionYearSecond = [];
//var productionWithMonthAndYearFirst = [];
//var productionWithMonthAndYearSecond = [];
//var temporarily = [];
//await wait(1000)
//teller++
//number++
//count++
//}