commit f7fa75394573237d1db9249247b98311727c39d7 Author: Jan Beníček Date: Tue Dec 19 13:48:20 2023 +0000 Přidat Plus1PM.js diff --git a/Plus1PM.js b/Plus1PM.js new file mode 100644 index 0000000..057d415 --- /dev/null +++ b/Plus1PM.js @@ -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 + ); +} \ No newline at end of file