Help with verification light rule

Why? Why not start from when the Item that triggers the relay to turn on/off receives a command?

Your stated problem is you want to know whether the button press on the screen actually happened or not so when you arrive the door won’t be closed.

Well, the first thing that happens is the Item associated with the opener button receives a command. You can trigger a Rule based on that event.

This is the absolute earliest point in the process and that is what you want.

So trigger a Rule when that Item receives the command to turn on your light, send your alert message or whatever. Immediately after this point the door should be in motion.

Most people use just two reed sensors to detect the position of the door. They use two either on the doorway or on the rod. One sensor at the bottom and one sensor at the top and the magnet on the door or chain. When the bottom one is closed then you know the door is closed. If the bottom one goes to open then you know the door is in motion. When the top one goes to closed you know the door is open. And so on.

So far no timing is required.

The only place where timing is required is if you do not trust that the relay will actually trip after you tell it to. In that case you can set a timer to check after a second. But this is optional and only needed if you don’t trust the relay.

var Timer garageDoorTimer = null

rule "Garage Door Triggered"
when
    Item DoorTrigger received command
then
    // DoorTrigger is linked to the physical device so we know the relay has triggered at this point
    
    // turn on your alert light
    GarageLight.sendCommand(ON)

    // send an alert message
    sendPushoverMessage(pushoverBuilder("Garage door was triggered!", "GalaxyS7", 1))

    // set a timer to make sure the door actually starts to open/close
    garageDoorTimer = createTimer(now.plusSeconds(1), [ |
        if(GarageDoorSensors.state != OPEN) sendPushoverMessage(pushoverBuilder("Garage door didn't start moving!", "GalaxyS7", 1))
        garageDoorTimer = null
    ])
end

rule "Garage Door Sensors Changed"
when
    Member of GarageDoorSensors changed
then
    if(triggeringItem.state == NULL) return;

    // If there is a Timer then we know the door was just triggered. Since one of the sensors changed state 
    // we know the door is in motion so cancel the Timer
    garageDoorTimer?.cancel

    val name = triggeringItem.name
    val st       = triggeringItem.state

    var status = "NA"

    switch name {
        "GarageDoorBottom": status = if(st == OPEN) "OPENING" else "CLOSED"
        "GarageDoorTop": status = if(st == OPEN) "CLOSING" else "OPEN"
    }

    // door has stopped moving
    if(status == "CLOSED" || status == "OPEN") {
        GarageLight.sendCommand(OFF)
    }

    sendPushoverMessage(pushoverBuilder("Garage door status = " + status + "!", "GalaxyS7", 1))

end

I hear you Rich… And I do not disagree. Triggering a rule from the push button item can work.
I have been looking at the rule above… Need to convert if to my items though… I´ll be back!

Rich… I´m trying to study the above rule… But I have some problems.

I now have two sensors connected to the garagedoor, One at start and one at end. It´s wireless Open/Closed sensores. Which mean, when the garagedoor is at either end, one of the sensores will report Closed, and the other will report Open.
I believe the rule for getting the notification light would be rather simple now:

If sensor1 or sensor2 = Open, then switch ON notification light, (virtuel item).

Does it makes sense?
I just dont know how to make this rule when having more than one sensor.

If I understand correctly, when the door is not moving (i.e. fully open or fully closed) then one of the sensors will be CLOSED. When the door is moving then both of the sensors will be OPEN. Given this you know:

if(bottom.state == CLOSED) // door is closed
else if(top.state == CLOSED) // door is open
else if(bottom.state == OPEN and top.state == OPEN) // door is moving or partially open

Furthermore you know that when bottom goes from CLOSED to OPEN that the door is opening and when the top goes from CLOSED to OPEN that the door is closing.

To answer your specific question, this means that you turn on your light when both sensors are OPEN, not just one of them.

1 Like

Ahh, correct…My mistake. I meant, sensor1 AND sensor2 ofcouse :blush:

Exactly!
Will give it a try later tonight… Thx Rich!

Hmm, I thought I could nail this one… But I´m stuck in an error I have no idea why

This is the rule sofar:

// Rule for status notification (light) of the Garagedoor

rule "Garageport moving"
when
		Item garage_reedrelay changed to ON       // ReedRelay ON
	then
		if(GaragePortSwitch1Status.state == CLOSED) // Garagedoor is fully closed
	garageport_movinglight.sendCommand(OFF)   //confirm and set Light to OFF

		else if(GaragePortSwitch2Status.state == CLOSED) // Garagedoor is fully open
	garageport_movinglight.sendCommand(ON)   //confirm and set Light to ON

	else if(GaragePortSwitch1Status.state == OPEN and GaragePortSwitch2Status.state == OPEN) // door is moving or partially open

	garageport_movinglight.sendCommand(ON)   //both sensors are OPEN set Light to ON.
end

// Items switches
// garage_reedrelay		- Reedrelay to activate garagedoor motor 
// GaragePortSwitch1Status 	- Bottom sensor
// GaragePortSwitch2Status 	- Top sensor
// garageport_movinglight 	- Virtuel item, control light for door open or on the move.
// garageportBottom 		- Virtuel item, control light for door fully closed
// garageportTop 		- Virtuel item, controle light for door fully open.

The error I get:

2018-07-27 00:14:06.344 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'garageport_moving.rules' has errors, therefore ignoring it: [13,48]: missing ')' at 'and' [13,89]: mismatched input ')' expecting 'end'
else if(GaragePortSwitch1Status.state == OPEN && GaragePortSwitch2Status.state == OPEN)

Yeah, I found a simular example from another tread, and changed the and to &&. Then the error was gone.

But it doesn´t seem like the rule is working. The control light (garageport_movinglight) does not change state at all. I ran out of time last night, so I´ll look at it again tonight with some log entries.

This is very strange…
The rule isn´t running for some reason…
This is the trigger going ON:

2018-07-27 18:54:11.525 [ome.event.ItemCommandEvent] - Item 'garage_reedrelay' received command ON

And from there… Nothing… Yes, the port is on the move, but the rule is not doing anything.
Maybe I got this all wrong… Here is my latest try:

// Rule for status notification (light) of the Garagedoor

rule "Garageport moving"
when
		Item garage_reedrelay changed to ON       // ReedRelay ON

then
 logInfo("garageport.status", "Reedrelay activated.")
		if(GaragePortSwitch1Status.state == CLOSED) // Garagedoor is fully closed
    {
	garageport_movinglight.sendCommand(OFF)   //confirm and set Light to OFF
	garageportBottom.sendCommand(OFF)
 logInfo("garageport.status", "garageport is fully Closed.")
    }
		else if(GaragePortSwitch2Status.state == CLOSED) // Garagedoor is fully open
    {
	garageport_movinglight.sendCommand(ON)   //confirm and keep Light to ON
	garageportTop.sendCommand(ON)
 logInfo("garageport.status", "garageport is fully Open.")

    }
		else if(GaragePortSwitch1Status.state == OPEN && GaragePortSwitch2Status.state == OPEN) // door is moving or partially open
    {
	garageport_movinglight.sendCommand(ON)   //both sensors are OPEN set Light to ON.
	garageportBottom.sendCommand(OFF)
	garageportTop.sendcommand(OFF)
 logInfo("garageport.status", "garageport is On the move.")
    }
end


//Items switches
//garage_reedrelay		- Reedrelay to activate garagedoor motor 
//GaragePortSwitch1Status 	- Bottom sensor
//GaragePortSwitch2Status 	- Top sensor
//garageport_movinglight 	- Virtuel item, control light for door open or on the move.
//garageportBottom 		- Virtuel item, control light for door fully closed
//garageportTop 		- Virtuel item, controle light for door fully open.

Does garage_reedrelay ever go to OFF? You have it set to only trigger the Rule when garage_reedrelay changes state. If it doesn’t change back to OFF, you can either write something to set it to OFF or change your Rule trigger to received command.

It never went OFF…
I made a mistake defining the items from the IHC controller. I had to change it to Contact insted…
Also I seem to have exchanged the two sensors… Small mistake :slight_smile:

The rule is now firing, but I get a send command error:

2018-07-27 22:06:59.806 [ome.event.ItemCommandEvent] - Item 'garage_bryggers_NV' received command ON
2018-07-27 22:07:00.106 [vent.ItemStateChangedEvent] - garage_reedrelay changed from CLOSED to OPEN
2018-07-27 22:07:00.126 [INFO ] [thome.model.script.garageport.status] - Reedrelay activated.
2018-07-27 22:07:00.168 [ome.event.ItemCommandEvent] - Item 'garageport_movinglight' received command ON
2018-07-27 22:07:00.174 [ome.event.ItemCommandEvent] - Item 'garageportBottom' received command OFF
2018-07-27 22:07:00.174 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garageport moving': 'sendcommand' is not a member of 'org.eclipse.smarthome.core.library.items.SwitchItem'; line 26, column 2, length 30
2018-07-27 22:07:00.496 [vent.ItemStateChangedEvent] - garage_reedrelay changed from OPEN to CLOSED

This is my rebuild item file:

Contact trigger_reedrelay	"Garage Open/close garagedoor"			<contact>					 {ihc="16679515"}
Switch garageport_movinglight	"Garageport is moving [%s]"			<light>							
Switch garageportBottom		"Garageport is fully open [%s]"			<light>							
Switch garageportTop		"Garageport is fully closed [%s]"		<light>							

And this is the rules file:

// Rule for status notification (light) of the Garagedoor

rule "Garageport moving"
when
		Item trigger_reedrelay changed from CLOSED to OPEN   // ReedRelay ON

then
 logInfo("garageport.status", "Reedrelay activated.")
		if(GaragePortSwitch2Status.state == CLOSED) // Garagedoor is fully closed
    {
	garageport_movinglight.sendCommand(OFF)   //confirm and set Light to OFF
	garageportBottom.sendCommand(OFF)
 logInfo("garageport.status", "garageport is fully Closed.")
    }
		else if(GaragePortSwitch1Status.state == CLOSED) // Garagedoor is fully open
    {
	garageport_movinglight.sendCommand(ON)   //confirm and keep Light to ON
	garageportTop.sendCommand(ON)
 logInfo("garageport.status", "garageport is fully Open.")

    }
		else if(GaragePortSwitch1Status.state == OPEN && GaragePortSwitch2Status.state == OPEN) // door is moving or partially open
    {
	garageport_movinglight.sendCommand(ON)   //both sensors are OPEN set Light to ON.
	garageportBottom.sendCommand(OFF)
	garageportTop.sendcommand(OFF)
 logInfo("garageport.status", "garageport is On the move.")
    }
end


//Items
//garage_reedrelay		- Reedrelay to activate garagedoor motor 
//GaragePortSwitch2Status 	- Bottom sensor
//GaragePortSwitch1Status 	- Top sensor
//garageport_movinglight 	- Virtuel item, control light for door open or on the move.
//garageportBottom 		- Virtuel item, control light for door fully closed
//garageportTop 		- Virtuel item, controle light for door fully open.

I´m not quite sure why it complaints about the send command.

Ahh found a typo mistake in the rule… sendcommand, has to be sendCommand (capital C).

@rlkoshak I think I need some help here, again :smile:

This has been driving me nuts for the last few hours. But I believe I might have found the reason why the rule is not working fully.
I think the sensors are having some flickering, which might confuse the rule. I wonder if it could be solved with some timing in between sendCommands, very short timings though… Just about 1 second.
Or could there be another reason.

This is my rule as it looks right now. Most of it works, but the control lights doesn´t quite follow the rule when the garagedoor is on the move. Second, when the garagedorr is fully open, even though the sensors2 is closed, the control light does not turn on, until the garagedoor is activated again, and starts moving…
I can tell from the log there are some OPEN,CLOSE , OPEN,CLOSE from the same sensor in a very shot time, (less than 400ms) which is why I think it is flickering, and why I think the rule doesn´t acutally catch the right state of the sensors.

Does it make any sense?

// Rule for status notification (light) of the Garagedoor

rule "Garageport moving"
when
		Item trigger_reedrelay changed from CLOSED to OPEN   // ReedRelay ON

then
 			logInfo("garageport.status", "Reedrelay activated.")
	if(GaragePortSwitch1Status.state == CLOSED && GaragePortSwitch2Status.state == OPEN) // Garagedoor is fully closed
    {
	garageport_movinglight.sendCommand(OFF)   //confirm and set Light to OFF
	garageportBottom.sendCommand(ON)
			 logInfo("garageport.status", "garageport is fully Closed.")

    }
		else if(GaragePortSwitch2Status.state == CLOSED && GaragePortSwitch1Status.state == OPEN) // Garagedoor is fully open
    {
	garageport_movinglight.sendCommand(OFF)   //confirm and set Light to OFF
	garageportTop.sendCommand(ON)
 			logInfo("garageport.status", "garageport is fully Open.")

    }
		else if(GaragePortSwitch1Status.state == OPEN && GaragePortSwitch2Status.state == OPEN) // door is moving or partially open
    {
	garageport_movinglight.sendCommand(ON)   //both sensors are OPEN set Light to ON.
	garageportBottom.sendCommand(OFF)
	garageportTop.sendCommand(OFF)
 			logInfo("garageport.status", "garageport is On the move.")
    }
end


//Items
//trigger_reedrelay		- Reedrelay to activate garagedoor motor 
//GaragePortSwitch1Status 	- Bottom sensor
//GaragePortSwitch2Status 	- Top sensor
//garageport_movinglight 	- Virtuel item, control light for door open or on the move.
//garageportBottom 		- Virtuel item, control light for door fully closed
//garageportTop 		- Virtuel item, controle light for door fully open.

Btw… I did not mix up the sensors after all as written in previous message. I think the flickering confused me, as well as it confuses the rule now :slight_smile:

Regarding a timing, I have no idea how to create a timing, and right now I dont have a proper suggestion of where to place the timings. But it might be worth a try.

I strongly recommend using VSCode with the openHAB extension.

sendCommand

Case matters.

Use meaningful names for your Items. Instead of GaragePortSwitch1Status, which has very little information in it to tell you what it is, use a name like GaragePortBottomSensor. Always strive to write code that does not require a secret decoder ring to understand what everything is. It not only helps us on the forum figure out what is going on, it will help future Kim understand the code he’s written a year from know when you have no recollection what you wrote or why.

Also, I’ve no idea what garageportBottom is.

Show me the logs.

Timing could be an issue but it has nothing to do with the sensor flapping. It is because the rule is triggering and it immediately starts running. Because you are triggering the based on the relay the rule starts running before the door has had the opportunity to actually move far enough to change state in time for use in the rule.

I’d recommend changing the trigger of the rule to trigger on the sensors, not the relay. Then you know the door has started/stopped moving because the sensor changed state.

The Rule becomes somewhat simpler as well. If you put the sensors into a Group then the Rule could be something like:

rule "Garageport moving"
when
    Member of GarageportSensors changed
then

    // default to the door is moving
    var moving = true
    var lightState = ON

    // If either sensor is OPEN then the door is not moving
    if(GaragePortBottomSensor.state == OPEN || GaragePortTopSensor.state == OPEN) {
        moving = false
        lightState = OFF
    }

    // Figure out if the door is fully open or fully closed or on the move
    var message = "on the move"
    if(GaragePortBottomSensor.state == OPEN) message = "fully closed"
    if(GaragePortTopSensor.state == OPEN) message = "fully open"

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

Hmm, you´re right…
I will recreate this from scratch using more meaningfull items names. And ofcouse, using the sensors to trigger the rule insted. It makes sense.

Comments:

    // default to the door is moving
    var moving = true
    var lightState = ON

Why default to the door is moving? Shouldn´t this be default to not moving, since the goal is to state, wether the garageport is moving or not? (and if it has reach its end).

Second comment:

    // If either sensor is OPEN then the door is not moving
    if(GaragePortBottomSensor.state == OPEN || GaragePortTopSensor.state == OPEN) {
        moving = false
        lightState = OFF
    }

This is wrong. If either sensor is OPEN, it means the door has reach the opposit end, either Top end or bottom. Or the garageport is on the move, then both sensors will be OPEN.

Third comment:

    // Figure out if the door is fully open or fully closed or on the move
    var message = "on the move"
    if(GaragePortBottomSensor.state == OPEN) message = "fully closed"
    if(GaragePortTopSensor.state == OPEN) message = "fully open"

Due to the wrong statement in second comment, this will be wrong as well. If GaragePortBottomSensor is OPEN, then the garageport is NOT fully closed. Garageport is either moving or has reach the top, (fully open).

I tried rebuild the rule, but things are not as logic as I thought it would be :frowning:
Light goes ON but not OFF.

This is my edited rule (not working though).
Notice the itemsnames change, and logic description at the bottom… I hope I will remember :slight_smile:

/ Rule for status notification (light) of the GaragePort

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"
    if(GaragePortTopSensor.state == CLOSED) message = "fully open"

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


// Items
// Group GaragePortSensors	- Group Top and Bottom sensors.
// GaragePortBottomSensor 	- Bottom sensor
// GaragePortTopSensor	 	- Top sensor
// GaragePortMovingLight 	- Virtuel item, control light for door open or on the move.
// GaragePortBottomLight	- Virtuel item, control light for door has reached the bottom (fully closed)
// GaragePortTopLight 		- Virtuel item, controle light for door has reached the top (fully open).
//
// Logic:
// When Garageport is fully closed and not moving, GaragePortBottomSensor will be CLOSED and GaragePortTopSensor will be OPEN. 
// When Garageport is fully open, GaragePortTopSensor will be CLOSED and GaragePortBottomSensor will be OPEN. 
// When Garageport on the move, both sensors wil be OPEN, untill garageport reach the end, then either GaragePortTopSensor or GaragePortBottomSensor will be CLOSED, depending on direction.

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