@paul53
Sehr gut. Erfolgreich getestet. Dann nur der Vollständigkeit halber nochmal das ganz Skript
const url = 'hier die komplette URL eintragen';
const path = '0_userdata.0.Solar.';
const idLeistung = path + 'Leistung';
const idEnergie = path + 'Energie';
var Leistung = {
"axisLabels": ["8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"],
"graphs": [{
"data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"type": "line",
"yAxis_min": 0,
"yAxis_max": 10,
"yAxis_step": 1,
"yAxis_position": "left",
"yAxis_appendix": " kW",
"datalabel_show": false
}
]
};
var Energie = {
"axisLabels": ["8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"],
"graphs": [{
"data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"type": "line",
"yAxis_min": 0,
"yAxis_max": 10,
"yAxis_step": 1,
"yAxis_position": "left",
"yAxis_appendix": " kWh",
"datalabel_show": false
}
]
};
if(!existsState(idLeistung)) createState(idLeistung, JSON.stringify(Leistung), {type: 'string', name: 'Leistung', role: 'table'});
if(!existsState(idEnergie)) createState(idEnergie, JSON.stringify(Energie), {type: 'string', name: 'Energie', role: 'table'});
schedule('5 7-19 * * *', function() {
request(url, function (error, response, result) {
if(error) log(error, 'error');
else {
let obj = JSON.parse(result);
if(obj.status) log('Fehler: ' + obj.status, 'warn');
else {
let data = obj.data;
Leistung.axisLabels = [];
Leistung.graphs[0].data = [];
Energie.axisLabels = [];
Energie.graphs[0].data = [];
for(let entry in data) {
let time = formatDate(parseInt(entry), 'hh');
Leistung.axisLabels.push(time);
Energie.axisLabels.push(time);
Leistung.graphs[0].data.push(data[entry][0]);
Energie.graphs[0].data.push(data[entry][1]);
}
setState(idEnergie, JSON.stringify(Energie), true);
setState(idLeistung, JSON.stringify(Leistung), true);
}
}
});
});