Přidat Plus1PM.js
commit
f7fa753945
|
@ -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
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue