Control Lights with Insteon Motion Sensor

I am new to OpenHab. I am using all Insteon devices. I have two motion sensors that I would like to use to control dimmers. The idea is when motion is detected the light comes on and remains on until I leave the room. I for testing purposes I have set the Insteon Motion Sensor’s Automatic “Off” Countdown to the minimum 30 seconds.

My current rule looks like this:

    rule "Erin's Office light motion"
        when
            Item Erin_Office_Motion changed to OPEN
        then
            if (Erin_Office_Motion_Timer==null) {
            // motion detected
                sendCommand(Erin_Office_Dimmer, 100)
                logInfo("Erin's Office","Starting timer for turning off the lights")
                Erin_Office_Motion_Timer = createTimer(now.plusMinutes(1))[|
                    logInfo("Erin's Office","Turning lights off")
                    sendCommand(Erin_Office_Dimmer, 0)
                    Erin_Office_Motion_Timer = null 
                ]
            } 
            else { 
                logInfo("Erin's Office", "We have a timer already, rescheduling")
                Erin_Office_Motion_Timer.reschedule(now.plusMinutes(1))
            }
    end

Unfortunately, no matter how much movement there is the timer is never rescheduled. The light constantly turns off and on (so I know the “null” state function is working).

I have also tried this rule:

    rule "Erin's Office light motion"
        when
            Item Erin_Office_Motion received update OPEN
            if (Erin_Office_Dimmer.state < 30 ){
                if (Erin_Office_Motion_Timer != null)
                    {
                        Erin_Office_Motion_Timer.reschedule(now.plusMinutes(Erin_Office_Motion_Timeout))
                        logInfo("Erin's Office - ","Erin's Office Motion timer rescheduled for " + Erin_Office_Motion_Timeout + " minutes")
                    }
                else
                {
                    sendCommand(Erin_Office_Dimmer, 100)
                    logInfo("Erin's Office - ","Erin's Office Motion timer create with " + Erin_Office_Motion_Timeout + " minutes")
                    Erin_Office_Motion_Timer = createTimer(now.plusMinutes(Erin_Office_Motion_Timeout))
                    [|
                        if (Erin_Office_Motion.state ==  OPEN)
                            {
                                Erin_Office_Motion_Timer.reschedule(now.plusMinutes(Erin_Office_Motion_Timeout))
                                logInfo("Erin's Office - ","Erin's Office Motion timer triggered, but rescheduled again for " + Erin_Office_Motion_Timeout + " minutes")
                            }
                        else 
                           {
                                sendCommand(Erin_Office_Dimmer, 0)
                                Erin_Office_Motion_Timer = null
                           }
                       ]
                }
        }
    end

Same thing. The lights come on and turn off when the timer expires. The timer is never rescheduled no matter how much movement there is. Any help would be greatly appreciated.

I have rules that do that, but they are written in python, and would require you to switch to the jsr engine. Not a big deal and totally worth it. I found the xtend rules hard to write and to debug. Let me know if you are interested and I’ll post them.

I have not problems changing to python. I read that the rules execute faster, etc. and was considering the change. But, I do not know how to code in python, xtend, or any other language. I am simply a “tinker”. Thus, I generally reuse the rules found in the wiki and in the forums.

I am interested in seeing your python scripts. (If you have the time, a quick and dirty explanation of how the scripts work would also be helpful.)

Thanks in advance.

I’m not really where I can fully analyze your rule but I have two suggestions.

  1. You may need to cast you state to a DecimalType to compare it. I.e. (Erin_Office_Dimmer.state as DecimalType) < 30

  2. Add lots of logging to see what parts of your rule are executing and what parts are not which might point you in the right direction.