I finally got my Fibaro sensor working, but I have an issue with the rule. When the temp in my office gets above 78 and I’m in the office, it turns on the office fan (at 50% speed) for only a couple of minutes. Are there any glaring errors in my rule below?
var Timer fan_timer = null
rule "Office Motion Sensor"
when
Item Alarm_Office received update
then
if(Temp_Office.state > 78){
logInfo("Movement", "Office motion tripped and high temp")
sendCommand(OfficeFan, 50)
fan_timer = createTimer(now.plusMinutes(15)) [|
sendCommand(OfficeFan,OFF)
fan_timer = null
]
}
end
I’d say the problem is that through this:
Item Alarm_Office received update
the rule is triggered every time the sensor changes from OPEN to CLOSE. this will send a command to the fan each time(which it could interpret as “turn off” the second time). it will also (re)create the timer on each run, so the time until fan turns off can kinda vary…like a lot
You should probably add a check if the timer is not already set to the beginning of the rule:
rule "Office Motion Sensor"
when
Item Alarm_Office received update
then
// we want to do stuff only if timer is not already set...
if (fan_timer == null){
//your stuff in here...
}
end
and/or think of another method of determining if your in the office. For example, in my living room i check if either:
Well, we already have above an example of how to check if a timer is already running (by looking for null). So there is then a choice, to cancel it and make anew, or to reschedule it. They’d be good keywords in a search.