Hi, hab das Script jetzt noch ein bißchen erweitert und zeige jetzt mehr Werte an.
Das Problem ist wenn ich mehr als 4 Shelly.call() hintereinander aufrufe (zum Updaten der virtuellen Komponenten) kommt immer:
Uncaught Error: Too many calls in progress
Also so gehts nicht:
// Update virtual components
updateVirtualComponent(total_consumption_id, total_consumption);
updateVirtualComponent(total_excess_id, total_excess);
updateVirtualComponent(consumption_id, consumption);
updateVirtualComponent(excess_id, excess);
updateVirtualComponent(current_L1_id, current_L1);
updateVirtualComponent(current_L2_id, current_L2);
updateVirtualComponent(current_L3_id, current_L3);
Hab gelesen das nicht mehr als 4-5 calls gehen?
Habs jetzt umschifft indem ich mehrere Timer zeitversetzt laufen lassen und nie mehr als 2-3 Shelly Calls gleichzeitig ausführe:
// Virtual buttons IDs
let total_consumption_id= 202;
let total_excess_id= 203;
let consumption_id = 200;
let excess_id = 201;
let current_L1_id = 204;
let current_L2_id = 205;
let current_L3_id = 206;
//smartmeter values
let total_consumption;
let total_excess;
let consumption;
let excess;
let current_L1;
let current_L2;
let current_L3;
// URL for the API request
let url = "http://192.168.1.150/getLastData?user=1234&password=1234";
// Function to fetch data from Smartmeter
function fetchSmartmeterData() {
//print("Starting fetch SmartmeterData function");
Shelly.call(
"HTTP.GET",
{"url": url},
function (response) {
if (response && response.code && response.code === 200) {
try{
//print(JSON.stringify(response.body));
total_consumption = Math.round((JSON.parse(response.body)['1.8.0'])/1000);
total_excess = Math.round((JSON.parse(response.body)['2.8.0'])/1000);
consumption = JSON.parse(response.body)['1.7.0'];
excess = JSON.parse(response.body)['2.7.0'];
current_L1 = JSON.parse(response.body)['31.7.0'];
current_L2 = JSON.parse(response.body)['51.7.0'];
current_L3 = JSON.parse(response.body)['71.7.0'];
//print("test " + JSON.parse(response.body)['1.7.0']);
// Update virtual components
//updateVirtualComponent(total_consumption_id, total_consumption);
//updateVirtualComponent(total_excess_id, total_excess);
//updateVirtualComponent(consumption_id, consumption);
//updateVirtualComponent(excess_id, excess);
//updateVirtualComponent(current_L1_id, current_L1);
//updateVirtualComponent(current_L2_id, current_L2);
//updateVirtualComponent(current_L3_id, current_L3);
} catch (e) {
print("Error parsing smartmeter data: " + e.message);
//print("Received data: " + response.body); // Print the actual data received for debugging
}
}
else {
print("Error: HTTP request failed.");
}
}
);
}
// Function to update virtual components
function updateVirtualComponent(component_id, value) {
Shelly.call(
"Number.Set",
{
"id": component_id,
"value": value
},
function(result, error_code, error_message) {
if (error_code !== 0) {
print("An error occurred when updating the virtual component: " + error_message);
} else {
print("Virtual component successfully updated. ID: " + component_id + ", Value: " + value);
}
}
);
}
// Fetch smartmeter data every 10s
Timer.set(10000, true, function () {
print("Timer triggered. Fetching smartmeter data...");
fetchSmartmeterData();
// Update virtual components 1
try{
updateVirtualComponent(total_consumption_id, total_consumption);
updateVirtualComponent(total_excess_id, total_excess);
} catch (e) {
print("Error updating components 1: " + e.message);
}
});
// Update virtual components 2
Timer.set(10500, true, function () {
print("Timer triggered. Updating component 2...");
// Update virtual components 2
try{
updateVirtualComponent(consumption_id, consumption);
updateVirtualComponent(excess_id, excess);
} catch (e) {
print("Error updating components 2: " + e.message);
}
});
// Update virtual components 3
Timer.set(11000, true, function () {
print("Timer triggered. Updating component 3...");
// Update virtual components 3
try{
updateVirtualComponent(current_L1_id, current_L1);
updateVirtualComponent(current_L2_id, current_L2);
updateVirtualComponent(current_L3_id, current_L3);
} catch (e) {
print("Error updating components 3: " + e.message);
}
});
// Initial fetch to verify script is working
print("Initial fetch to verify script is working...");
fetchSmartmeterData();
Alles anzeigen
Gibts da eine elegantere Lösung mit den Shelly Calls?