In a rule wait for a item change its status

Hi,
inside a rule i need to wait few seconds until a group of item chaged its status and then go ahead in rule execution.
How can i perform this?

Regards

Marco

This feels like the approach is wrong but I’ve not enough information to know for sure.

If all you need to do is wait a few seconds all you need to do is:

Thread::sleep(5000) // sleep for five seconds
// do stuff

However, if you need to wait until your other items reach a certain state:

while(MyItem1.state != ON && MyItem2.state != ON){
    Thread::sleep(500) // sleep half a second
}
// do stuff

Please note with the above while loop, if MyItem1 and MyItem2 are never both ON the loop will never exit.

Personally, I would do something like this:

rule "My Rule"
when
    Item MyItem0 changed to ON or // the Item that triggers your current rule
    Item MyItem1 changed to ON or
    Item MyItem2 changed to ON
then
    if(MyItem0.state == ON && MyItem1.state == ON && MyItem2.state == ON) {
        // do stuff only if all three Items are ON
    }
end

This rule gets triggered when ever any of your three Items change but only does something when all reach the desired state.

Hi Rich,
thanks for suggestion. I’ll try the third way.
I have anothe question related to this. One of my item have to a Standard value like ON or OPEN, but have a string status line “Modect”, can I use this syntax?

when
Item MyItem0 changed to “Modect”

That is a really good question. I see nothing in the documentation to say that wouldn’t work. But I’ve not seen an example anywhere of someone using that type of trigger.

Give it a try and see if it works. Let us know one way or the other.

Just a small hint for this:

rule "My Rule"
when
    Item MyItem0 changed to ON or // the Item that triggers your current rule
    Item MyItem1 changed to ON or
    Item MyItem2 changed to ON
then
    if(MyItem0.state == ON && MyItem1.state == ON && MyItem2.state == ON) {
        // do stuff only if all three Items are ON
    }
end

You should remove each to ON or it will never turn off, if you change one or all to OFF.

This is the rule:

`rule "Antifurto Gestione Luce Ingresso - Accendi"
when
	Item gpCamModeAll_NoRoof changed to Monitor or
	Item ANTIFURTO_STATO changed from CLOSED to OPEN //Disinserito
then

	if ((gpCamModeAll_NoRoof.state == "Monitor") && (ANTIFURTO_STATO.state == OPEN)) {
		INGRESSO_LUCE.sendCommand(ON)		
	}
end`

I’ll test in next hours

I think you might be wrong here. The rule is evaluated when any of (MyItemN) changes to ON and only then. The THEN clause checks for all ON at evaluation/execution time. There is nothing preventing any of the items being switched to OFF outside the scope of this rule.

1 Like

Ah excuse me. I thought it should be changed to OFF in any other case. But now I see there is no else clause as well.

there is another rule that handle the switchoff

1 Like

There was a bug which limited the possibility to evaluate a string as a condition, but apparently it has been fixed.

The bug was that what you are referring to would only work without the quotes around the string. This is great, except that you could not have string contents with a space or some other special characters. You can find the original post talking about the subject here.

@marcolino7 : any update on your use of …

@steve1 is looking to close a bug on the subject, and I just want to make sure that this has been fixed.

I did in another way, so I not used it.

Regards

OK. Thanks for the update.

Greg Eva
geva@ge-volution.eu geva@ge-volution.eu
www.gE-volution.eu
France : +33 4 81 68 09 64
Canada : +1 226 476 1192
iNum : +833 51 00 09 90 28 81

Hello could you help me with a rule,
I’m getting a false positive with pir sensors.
It could solve, if you wait for 5 seconds the ON status of the PIR, to change the ITEM to ON solves the problem.
But I don’t know how to do it.
thank you

First of all, open an new thread rather than reopening a 4 year old one.

See how the Timer is used in Generic Presence Detection. That’s exactly what you need to do.

1 Like