Přidat Plus1PM.js

main
Jan Beníček 2023-12-19 13:48:20 +00:00
commit f7fa753945
1 changed files with 53 additions and 0 deletions

53
Plus1PM.js Normal file
View File

@ -0,0 +1,53 @@
let startMonitor = false;
let lastRun = false;
let aEnergy = 0;
Shelly.addEventHandler(function (event, user_data) {
if (event.component ==="switch:0")
{
//print(JSON.stringify(event));
if (event.info.event === "toggle") {
if (event.info.state) {
startMonitor = true;
eAccumulator = 0;
} else {
startMonitor = false;
}
print("Monitor: " + startMonitor);
}
}
}, null);
Shelly.addStatusHandler(function (event, user_data)
{
//print(JSON.stringify(event));
if (typeof event.delta.aenergy !== "undefined")
{
if (startMonitor || lastRun)
{
lastRun = startMonitor;
Shelly.call
(
"KVS.Get", { key: "mWh" }, function (result, code, msg, ud)
{
aEnergy = Number(result.value);
KVS_Set("mWh", (aEnergy + event.delta.aenergy.by_minute[0]));
print("Consumed: " + ((aEnergy + event.delta.aenergy.by_minute[0]) / 1000) + "Wh");
KVS_Set("Consumed", ((aEnergy + event.delta.aenergy.by_minute[0]) / 1000) + "Wh -- !Set mWh to 0 for measure reset!");
},
null
);
}
}
}, null);
function KVS_Set (keyd, datad)
{
Shelly.call(
"KVS.Set", { key: keyd, value: datad },
function (result, code, msg, ud) {},
null
);
}