Help with verification light rule

It didn’t matter what the default is as long as by the end you know whether the door is moving or not. I defaulted to moving because the code is more self descriptive in telling you under what conditions the door is consider moving or not. The following is absolutely equivalent.

var moving = false
var lightState = OFF

if(GaragePortBottomSensor.state == CLOSED && GaragePortTopSensor.state == CLOSEF) {
    moving = true
    lightState = ON
}

The condition should test for CLOSED then.

Since you swapped the default around to assuming the door is not moving you need to test that both sensors are OPEN using the and operator &&. It will always be the case that one or the other sensors will be open. If one of the sensors is closed the door is not moving. If both sensors are open the door is moving.

Correct. But I can´t seem to get it to work. The moving light never turns off.

This is the log when doing 3 x activating (pushbutton).

2018-07-29 23:15:22.344 [ome.event.ItemCommandEvent] - Item 'garage_bryggers_NV' received command ON // First push on the pushbutton. Garageport starts moving towards opening.
2018-07-29 23:15:23.024 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from CLOSED to OPEN
2018-07-29 23:15:23.065 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from OPEN to CLOSED
2018-07-29 23:15:23.073 [INFO ] [thome.model.script.garageport.status] - garageport is fully closed
2018-07-29 23:15:23.083 [ome.event.ItemCommandEvent] - Item 'GaragePortMovingLight' received command ON
2018-07-29 23:15:23.106 [ome.event.ItemCommandEvent] - Item 'GaragePortMovingLight' received command ON
2018-07-29 23:15:23.113 [INFO ] [thome.model.script.garageport.status] - garageport is fully closed
2018-07-29 23:15:23.297 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from CLOSED to OPEN
2018-07-29 23:15:23.327 [INFO ] [thome.model.script.garageport.status] - garageport is on the move
2018-07-29 23:15:23.330 [ome.event.ItemCommandEvent] - Item 'GaragePortMovingLight' received command ON

2018-07-29 23:15:26.507 [ome.event.ItemCommandEvent] - Item 'garage_bryggers_NV' received command ON // Second push on the pushbutton. Garageport stops moving (hasn´t reach end).

2018-07-29 23:15:30.584 [ome.event.ItemCommandEvent] - Item 'garage_bryggers_NV' received command ON // Third push on the pushbutton. Garageport starts moving towards closing.
2018-07-29 23:15:36.507 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from OPEN to CLOSED
2018-07-29 23:15:36.535 [ome.event.ItemCommandEvent] - Item 'GaragePortMovingLight' received command ON
2018-07-29 23:15:36.545 [INFO ] [thome.model.script.garageport.status] - garageport is fully closed
2018-07-29 23:15:36.818 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from CLOSED to OPEN
2018-07-29 23:15:36.846 [INFO ] [thome.model.script.garageport.status] - garageport is on the move
2018-07-29 23:15:36.886 [ome.event.ItemCommandEvent] - Item 'GaragePortMovingLight' received command ON
2018-07-29 23:15:36.958 [vent.ItemStateChangedEvent] - GaragePortBottomSensor changed from OPEN to CLOSED
2018-07-29 23:15:36.950 [INFO ] [thome.model.script.garageport.status] - garageport is fully closed

Did you change the || to && in your Rule?

1 Like

I was 99% positive that did change it. I justed checked, and no… it wasn´t changed :frowning:
I have now changed it, and it works like a dream, ofcouse…

Thank you very much Rich.

Oh… btw… This finished rule looks like this, (including some control lights).

rule "Garageport moving"
when
    Member of GaragePortSensors changed
then

    // default to the door is NOT moving
    var moving = false
    var lightState = OFF

    // If either sensor is OPEN then the door IS moving
    if(GaragePortBottomSensor.state == OPEN && GaragePortTopSensor.state == OPEN) {
        moving = true
        lightState = ON
    }

    // Figure out if the door is fully open or fully closed or on the move
    var message = "on the move"
    if(GaragePortBottomSensor.state == CLOSED)	{ 
	message = "fully closed"
	GaragePortBottomLight.sendCommand(ON) 	
   }
 else 

  {	
	GaragePortBottomLight.sendCommand(OFF) 
   }

    if(GaragePortTopSensor.state == CLOSED)	{ 
	message = "fully open"
	GaragePortTopLight.sendCommand(ON) 	
   }
 else 
	{	
	GaragePortTopLight.sendCommand(OFF)	
   }

    // change the status light and send the log.
    GaragePortMovingLight.sendCommand(lightState)
    logInfo("garageport.status", "garageport is " + message)
end