Hi, I got idea to switch off power socket after I switch of the PC. I did check PC usage and choose the limit: if usage less than 100W switch of plug after 1min.
I started with Thread::Sleep but I found out its not good idea, because sometimes I was not able turn PC on because socket read less then 100W and keep switching it off
So I turned into smarter solution: Timer
When usage less than 100W start timer, when again over 100W cancel timer (when you want switch PC again on after you switched it off).
Question: Isnt this script resources hungry, when it keep checking/trigger if timer is not active everytime when power value changed (I change power socket things reading from 2s to 10s) ALL the time while is Power Socket ON?
Any better solution?
Using Openhabian on RPi and TPLink HS110
var Timer TPL3PowerSocketTimer = null
// -- POWER SOCKET CONTROL -----------------------------------------------------
// -----------------------------------------------------------------------------
rule "Power socket low usage PC main OFF"
when
Item TPL3_Power changed
then
// -- less than 100W and switch is ON
if (TPL3_Power.state < 100 && TPL3_Switch.state == ON) {
// -- timer already counting down
if (TPL3PowerSocketTimer !== null) {
logInfo("LogPowerSocket","Power usage less than 100W (" + TPL3_Power.state + "W) on TPL3: TIMER COUNTDOWN RUNNING: " + TPL3PowerSocketTimer)
}
// -- timer not started, start
else {
logInfo("LogPowerSocket","Power usage less than 100W (" + TPL3_Power.state + "W) on TPL3: TIMER STARTED: " + TPL3PowerSocketTimer)
TPL3PowerSocketTimer = createTimer(now.plusMinutes(1), [|
TPL3_Switch.sendCommand(OFF)
TPL3_Switch_Led.sendCommand(OFF)
Thread::sleep(500)
logInfo("LogPowerSocket","Power usage less than 100W (" + TPL3_Power.state + "W) on TPL3: TIMER FINISHED, Socket state: " + TPL3_Switch.state)
TPL3PowerSocketTimer = null
])
}
}
// -- more than 100W
else if (TPL3_Power.state >= 100) {
if (TPL3PowerSocketTimer !== null) {
TPL3PowerSocketTimer.cancel()
TPL3PowerSocketTimer = null
logInfo("LogPowerSocket","Power usage more than 100W (" + TPL3_Power.state + "W) on TPL3: TIMER CANCELED")
}
//else {
// logInfo("LogPowerSocket","Power usage more than 100W (" + TPL3_Power.state + "W) on TPL3: TIMER IS OFF")
//}
}
end