I’ve used this rule from quite some time, where my bathroom fan starts blowing when someone starts showering.
First i have two items containing to old and the new humidity:
rule "Update Hum Badkamer"
when
Item Sensor_Hum_BadkamerZ changed
then
Sensor_Hum_Oud.postUpdate(Sensor_Hum_Nieuw.state.toString)
Sensor_Hum_Nieuw.postUpdate(Sensor_Hum_BadkamerZ.state.toString)
end
Then this values are compared in a new rule:
rule "Badkamer Fan"
when
Item Sensor_Hum_Nieuw received update
then
var Number Humnew = Sensor_Hum_Nieuw.state as DecimalType
var Number Humold = Sensor_Hum_Oud.state as DecimalType
if((Schakel_Fan_Itho.state == OFF) && ((Humnew-Humold) > 5)) {
logInfo("rules", "Badkamer FAN aan")
sendCommand(Schakel_Fan_Itho, ON)
Thread::sleep(2700000)
sendCommand(Schakel_Fan_Itho, OFF)
}
end
I know that it’s not right to use the Thread::sleep for so long time inside a rule. So i want to change the rule, that when the value get low again, under the 90(the sensor is quite slow, 90 will take more than one hour) so I changed the last part:
else if ((Schakel_Fan_Itho.state == ON) && (Humnew < 90 )) {
logInfo("rules", "Badkamer FAN uit!")
sendCommand(Schakel_Fan_Itho, OFF)
}
end
But with this part, the fan is getting ON en OFF the first minutes before it reached 90%, off course. Is it possible to do this last part, but only when the humidity is going down and not when it’s rising.
I’m also in the (slow) proces of migrating rules to Jython. I’m not a programmer so i can only copy/paste and see whats working and not. I couple of light rules are already working. Changing this rule to Jython got me to this point:
@rule("Badkamer hum update", description="update de luchtvochtigheid", tags=["ventilator", "badkamer"])
@when("Item Sensor_Hum_BadkamerZ received update")
def Update_Sensor_Hum(event):
Update_Sensor_Hum.log.info("De luchtvochtigheid wordt geupdate")
events.postUpdate("Sensor_Hum_Oud", items["Sensor_Hum_Nieuw"])
events.postUpdate("Sensor_Hum_Nieuw", items["Sensor_Hum_BadkamerZ"])
@rule("Badkamer FAN aanzetten", description="Als er iemand gaat douchen, de ventilator aanzetten", tags=["ventilator", "badkamer"])
@when("Item Sensor_Hum_Nieuw received update")
def Schakel_FAN__Itho_Aanzetten(event):
Schakel_FAN__Itho_Aanzetten.log.info("De badkamer fan aanzetten")
if items["Schakel_FAN_Itho"] == OFF and (items["Sensor_Hum_Nieuw"] - items["Sensor_Hum_Oud"] > DecimalType(5))
events.sendCommand("Schakel_Fan_Itho", "ON")
Now i need to make this working first and than add the part of the rule that it will shutdown the fan when the humidity drops below 90. Can someone put me in the right direction?