Rule: when item "changed" works when item "changed to OFF" doesn't [SOLVED] when item "changed to 0"

why does this script never fire:

rule "Powder Room fan after light timer"
when
	Item PowderRoom changed to OFF
then
	logInfo("INFO","Powder room: Powder room was turned off, turning on fan...")
	sendCommand(PowderRoomFan, ON)
	if(PowderRoomTimer == null) {
		PowderRoomTimer = createTimer(now.plusMinutes(2), [|
			sendCommand(PowderRoomFan, OFF)
			PowderRoomTimer = null
	])
    } else {
	PowderRoomTimer.reschedule(now.plusMinutes(2))
    }
end

yet this one does (where to only change is removing the “to OFF”):

rule "Powder Room fan after light timer"
when
	Item PowderRoom changed
then
	logInfo("INFO","Powder room: Powder room was turned off, turning on fan...")
	sendCommand(PowderRoomFan, ON)
	if(PowderRoomTimer == null) {
		PowderRoomTimer = createTimer(now.plusMinutes(2), [|
			sendCommand(PowderRoomFan, OFF)
			PowderRoomTimer = null
	])
    } else {
	PowderRoomTimer.reschedule(now.plusMinutes(2))
    }
end

I only want it to fire when “changed to OFF”.

I don’t know if it matters but PowderRoom is an insteonplm dimmer, defined in item file as:

Dimmer PowderRoom "Powder Room" (jt) {insteonplm="1F.80.29:F00.00.01#dimmer"}

Openhab2 12/28/2015 build, insteon PLM 1.8

Item PowderRoom changed from ON to OFF

should work. I have only been around openHAB for a couple months, I really have not found a complete set of documentation showing the methods for each object type.

1 Like

Rule Triggers might be missing something?

1 Like

I would think it would work too but as soon as I go from
Item PowderRoom changed
(works)

to anything like
Item PowderRoom changed from ON to OFF

or
Item PowderRoom changed to OFF

it doesn’t work.

Is it something to do with it being a dimmer?

Maybe but how else can I tell if a dimmer is off?

A Dimmer has a value between 0 and 100 percent A value of 0 is equivalent to OFF. Sending an ON/OFF value to a Dimmer will convert ON=100 or OFF=0 before storing the value.

I’ve tried
When
Item PowderRoom changed to 0

Is that what you are suggesting?
Or?

Item PowderRoom changed ==0

Don’t think I tried that.

Yeah that’s what I was kind of thinking, sorry was on my iphone earlier so only managed a one line reply.

I think @steve1 is right. But if a state set by openHAB for a dimmer is ‘0’, is that the same as ‘OFF’ when a rule is looking at it?

I can vouch for ‘when changed from ON to OFF’ as being very usable and useful. So why isn’t this one working? I’ve only ever done it on switches and virtual switches, not dimmers.

My workaround would be to use a virtual switch to store the previous state and test if it is anything other than ‘1’ when the switch PowderRoom changes perhaps.

I’ll take your iphone one liners!

Based upon your “Yeah that what I was thinking
” I RE-tried:

When
     Item PowderRoom changed to 0

and it works.

This time I made sure everything else was running errorless then introduced your idea and it works great.

Clearly, I did something wrong with my first attempt - lot’s of moving parts and chasing ghosts.
Thanks for taking the time to lend a beginner a hand.

I can’t get this to fire: Item DiningRoom_Light changed
It’s a dimmer bulb as well.

It never fires
i want to catch manual on/off at the switch
thoughts?