my wife get sleep between 1 to 2:30,
the power meter is on main switch, when she turn sleep, I shut down nearby electronic (from standby to no power)
I use lot of sleep thread command in my rules and most of them were few minutes, but few can up to 1-2 hours
so when sleep longer than few minutes, should I use Timer?
still the second question, how should catch a status change only during specific period which will better than my current way?
below code I use another way to achieve for long time count down (I want to wait 3 hours after first command, than 10 minutes wait for every changes made)
import java.util.concurrent.locks.ReentrantLock
var java.util.concurrent.locks.ReentrantLock tempLock = new java.util.concurrent.locks.ReentrantLock()
rule "BedRoom AirCon tempeture control"
when
Item Pwr_BedRoom_AirCon changed to ON
then
var Number counter = 180
if (Pwr_BedRoom_AirCon.state == ON) {
Thread::sleep(5000)
AirCon_BedRoom_Toshiba.sendCommand("Toshiba_AirCon_17C")
logInfo("AirCon", "BedR AirCon just turn ON, Current Temp:{} Set BedRoom AirCon Temp:{}",Rpi_BedR_Tempature.state, "17°C")
//logInfo("AirCon", "**>**>>> Bed Room AC auto adjust test")
//logInfo("AirCon", "BedR-Test First ON, Current Temp:{} Set BedRoom AirCon Temp:{}",Rpi_BedR_Tempature.state, "17°C")
if(!tempLock.isLocked){
tempLock.lock()
try {
while (Pwr_BedRoom_AirCon.state == ON){
if (counter == 0){
if (Ham_iphone.state==ON){
if (((Rpi_BedR_Tempature.state >= 23) && (Rpi_BedR_Tempature.state <= 24)) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state)) {logInfo("AirCon", "BedR current Tempature:{}%, Previous Tempature:{}%", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state)}
else if ((Rpi_BedR_Tempature.state < 23) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state) && (AirCon_BedRoom_Toshiba.state.toString != "Toshiba_AirCon_22C")) {AirCon_BedRoom_Toshiba.sendCommand("Toshiba_AirCon_22C") logInfo("AirCon", "BedR current Temp:{}%, Previous Temp:{}%, Set BedRoom AirCon Temp:{}", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state, "22°C")}
else if ((Rpi_BedR_Tempature.state > 24) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state) && (AirCon_BedRoom_Toshiba.state.toString != "Toshiba_AirCon_21C")) {AirCon_BedRoom_Toshiba.sendCommand("Toshiba_AirCon_21C") logInfo("AirCon", "BedR current Temp:{}%, Previous Temp:{}%, Set BedRoom AirCon Temp:{}", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state, "21°C")}
logInfo("AirCon", "BedR-Test current Temp:{}%, Previous Temp:{}%, Temp will not change until 10 Minutes later.", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState().state, counter)
}
else if (Ham_iphone.state==OFF){
if (((Rpi_BedR_Tempature.state >= 24) && (Rpi_BedR_Tempature.state <= 25)) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state)) {logInfo("AirCon", "BedR current Tempature:{}%, Previous Tempature:{}%", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state)}
else if ((Rpi_BedR_Tempature.state < 24) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state) && (AirCon_BedRoom_Toshiba.state.toString != "Toshiba_AirCon_22C")) {AirCon_BedRoom_Toshiba.sendCommand("Toshiba_AirCon_22C") logInfo("AirCon", "BedR current Temp:{}%, Previous Temp:{}%, Set BedRoom AirCon Temp:{}", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state, "22°C")}
else if ((Rpi_BedR_Tempature.state > 24.5) && (Rpi_BedR_Tempature.state != Rpi_BedR_Tempature.previousState(true,"influxdb").state) && (AirCon_BedRoom_Toshiba.state.toString != "Toshiba_AirCon_21C")) {AirCon_BedRoom_Toshiba.sendCommand("Toshiba_AirCon_21C") logInfo("AirCon", "BedR current Temp:{}%, Previous Temp:{}%, Set BedRoom AirCon Temp:{}", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState(true,"influxdb").state, "21°C")}
logInfo("AirCon", "BedR-Test current Temp:{}%, Previous Temp:{}%, Temp will not change until 10 Minutes later.", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState().state, counter)
}
}
if (counter == 0){counter=10}
Thread::sleep(60000)
counter = counter - 1
logInfo("AirCon", "BedR-Test current Temp:{}%, Previous Temp:{}%, Temp will not change until {} Minutes later.", Rpi_BedR_Tempature.state, Rpi_BedR_Tempature.previousState().state, counter)
}} finally {
tempLock.unlock()}
}
}
end