Shower detection (depends on humidity)

I agree with Bartus, triggering the rule by changes to the humidity rather than periodically would improve its detection speed. And measuring the rate of change would probably work faster too, though that will require more calculations.

From a coding style perspective:

  • avoid primitives where possible; they cause loading delays on RPis and other SBCs
  • since nThreshold is a constant, define it as a val, maybe as a global
  • apply Design Pattern: How to Structure a Rule and you can shrink this Rule down to just 3-4 lines of code
val nThreshold = 68

rule "TakeAShower"
when
    Item GroundFloor_MasterBathroom_Humidity changed
then
    var newState = if(GroundFloor_MasterBathroom_Humidity.averageSince(now.minusMinutes(5)) > nThreshold) ON else OFF

    if(Shower.state != newState) {
        logInfo("TakeAShower", "The shower is now " + newState)
        Shower.sendCommand(newState)
    }
end
1 Like