Dimitar Posted May 7 Share Posted May 7 Example how to read data from 3 Pro EM meters measuring the consumption on the 3 different zones and script which is run on Pro3EM with ADD-ON to EV Charger which disconnects (EV charging) for 30 min if the total power (represented by the consuming value on the right of the picture) is above a certain value. A JScript which can do that: // Configuration var deviceIPs = ['192.168.3.102', '192.168.3.246', '192.168.0.240']; // Add your device IPs here const switchOff = 2000 ; // Total power in W above this device will switch off output // Function to read data from a single Shelly Pro3EM function readEMData(ip, callback) { Shelly.call( "http.get", { url: "http://" + ip + "/rpc/EM.GetStatus?id=0" }, function (response, error_code, error_message) { if (response && response.message && response.code === 200) { var data = JSON.parse(response.body); var total_power = Math.round(data.total_aprt_power); callback(null, total_power); // Pass the total power to the callback } else { callback("Error: " + response.message, null); } } ); } // Function to calculate the total power from multiple devices function calculateTotalPower(ips) { var totalPower = 0; var count = 0; ips.forEach(function(ip) { readEMData(ip, function(err, power) { if (err) { print(err); // Handle the error, for example by logging it } else { totalPower += power; } count++; // Check if all requests are processed if (count === ips.length) { print("Total power: " + totalPower + " W"); if (totalPower > switchOff) { Shelly.call("Switch.set", {'id': 100, 'on': false}); print("Switch OFF!"); } } }); }); } // Execution: Timer.set(5000 /* ms */, true /* repeating */, function () { calculateTotalPower(deviceIPs); } ); Then you need to set Auto-ON in the Add-on relay: As a last step do not forget to set a script to start when device boot. With firmware 1.4, All pro devices will support virtual components. This will allow to monitor total consumption from the Shelly App and control the max power. I will update this script when this new feature are available. 2 Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.