Rule: change when relais gives contact (sadly active low relais)

Hi,
i have a relais, which is giving a signal for 1 second to open the frontdoor. Sadly this relais is active low. So when i remove power, the relais changes automatically to CLOSED and my door opens…

When i give back the power, the relais changes to OPEN again.

Is there a way to do this with a rule? I want prevent my frontdoor from opening, when the power of the relais is gone.

My current rule is like this:

rule "frontdoor"
	when
		Item Kontakt_Haustuer changed to CLOSED
	then
		Haustuer_Dummy.sendCommand(ON)
end

Is there a way to change the rule, that it only opens, when the contact was only closed for about 500ms? Maybe with timers?

I know, it is not the best way, because if the power is gone only for very short time, the door will open too, but it would be a workaround for the first time, until i can find a better solution for this.

In the rule you can use Thread::sleep(500) then check the condition with an if statement.

I’m not sure how the item Kontakt_Haustuer works. Does this CLOSE then change back to OPEN fast? If so here’s a rule example:

rule "frontdoor"
	when
		Item Kontakt_Haustuer changed to CLOSED
	then
                Thread::sleep(500)
                 if(Kontakt_Haustuer.state != CLOSED) // check the item has changed from CLOSED state
		Haustuer_Dummy.sendCommand(ON)
end

Yes, it closes and opens again about 500ms later.

Can i do this with a timer too?

Yep, you want a timer in the rule or use the Expire binding?

Timer in the rule example:

var Timer doorTimer = null
rule "frontdoor"
	when
		Item Kontakt_Haustuer changed to CLOSED
	then
               doorTimer = createTimer(now.plusSeconds(1), [ | 
               if(Kontakt_Haustuer.state != CLOSED) {
		Haustuer_Dummy.sendCommand(ON)
                doorTimer = null
                }
           ])
end

If one second is to long replace now.plusSeconds with now.plusMilliseconds(500) and adjust the value as needed.

1 Like

Thanks, will test it.

This should work except when you have a power blip (quick on off). Is using a small UPS power supply possible? Just something that will keep the sensor powered for a few minuets, as the rule will only run when the item has changed to OFF.

This will be no rule for very long time. My relais card can send MQTT too. But it isn´t working yet, i don´t get any data into my openhab-item…

See my other post:

When MQTT is working, i can remove the wires from my relais and use only the MQTT data.