Skip to content

Instantly share code, notes, and snippets.

@pedroserrudo
Last active May 8, 2025 13:34
Show Gist options
  • Save pedroserrudo/9dd8dac719172ac67b4b9e1a86d5999e to your computer and use it in GitHub Desktop.
Save pedroserrudo/9dd8dac719172ac67b4b9e1a86d5999e to your computer and use it in GitHub Desktop.
This gets date from shelly 3 phase em and pushs to Charge HQ using the Push API, I have solar/battery on phase C which Im attempting to extrapulate the discharge
let url = "https://api.chargehq.net/api/public/push-solar-data";
let apiKey = "apikey";
function sendToChargeHQ() {
let emStatus = Shelly.getComponentStatus("em:0", 0);
console.log("A:",emStatus.a_act_power)
console.log("A aprt:",emStatus.a_aprt_power)
console.log("B:",emStatus.b_act_power)
console.log("B aprt:",emStatus.b_aprt_power)
console.log("C:",emStatus.c_act_power)
console.log("C aprt:",emStatus.c_aprt_power)
let a = emStatus.a_act_power;
let b = emStatus.b_act_power;
let c = emStatus.c_act_power;
//battery_discharge_kw = (emStatus.c_aprt_power * emStatus.c_pf) / 1000;
//console.log("battery power", battery_discharge_kw);
let phasePowers = [a, b, c];
// Consumption: total power being used (always positive, even if some phases export)
let consumption_kw = (Math.max(a, 0) + Math.max(b, 0) + Math.max(c, 0)) / 1000;
// Net import: only positive sum of all phases (if net is positive)
let totalActPower = a + b + c;
let net_import_kw = totalActPower > 0 ? totalActPower / 1000 : 0;
// Production: stays 0
let production_kw = 0;
// Exported: sum of all negative powers
let exported_kw = (Math.min(a, 0) + Math.min(b, 0) + Math.min(c, 0)) / 1000 * -1; // make positive
// Imported: sum of all positive powers
let imported_kw = (Math.max(a, 0) + Math.max(b, 0) + Math.max(c, 0)) / 1000;
let payload = {
"apiKey": apiKey,
"siteMeters": {
"consumption_kw": consumption_kw,
"net_import_kw": net_import_kw,
"production_kw": 0,
"exported_kwh": exported_kw,
"imported_kwh": imported_kw,
//"battery_discharge_kw": battery_discharge_kw
}
};
//print(payload)
let payloadString = JSON.stringify(payload);
Shelly.call(
"http.post",
{
url: url,
body: payloadString,
headers: {
"Content-Type": "application/json"
},
},
function(resp) {
//print("Webhook response: ", resp);
}
);
}
Timer.set(60000, true, sendToChargeHQ);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment