Created
January 13, 2024 13:45
-
-
Save Donkfather/06b6a8d584abcaeda471717469af19fe to your computer and use it in GitHub Desktop.
shelly_1plus_pump_control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let debounceTimer | |
Shelly.addEventHandler(function (event) { | |
console.log(event.name, event.info.event) | |
if (event.name === "input" && event.info.event === "toggle") { | |
let newState = event.info.state | |
Shelly.call("KVS.GetMany",'*', function(kvs,errc, errm) { | |
if(errc) { | |
console.error(errc, errm) | |
return | |
} | |
let LTTime = JSON.parse(kvs.items.lttime.value) | |
let LTState = JSON.parse(kvs.items.ltstate.value) | |
let ToggleDebounce = JSON.parse(kvs.items.toggle_debounce.value) | |
let ttl = event.now - LTTime | |
console.log(LTTime, ' | ', LTState,' | ', ToggleDebounce,' | ', event.now-LTTime) | |
if(ttl <= ToggleDebounce) { | |
Timer.clear(debounceTimer) | |
debounceTimer = Timer.set(ttl*1000, false, function() { | |
Shelly.call('Switch.Set', { | |
id: 0, | |
on: newState, | |
}) | |
Shelly.call('KVS.Set', {key:'lttime', value: event.now + ttl}) | |
Shelly.call('KVS.Set', {key:'ltstate', value:newState}) | |
}) | |
return | |
} | |
Shelly.call("Switch.Set", { | |
id: 0, | |
on: newState, | |
}) | |
Shelly.call('KVS.Set', {key:'lttime', value:event.now}) | |
Shelly.call('KVS.Set', {key:'ltstate', value:newState}) | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It throttles the output