Do not execute a Rule

Hi
I have this code:

rule "chiusura"
when 
    Item LivingRoom_Light1 changed to ON 
then
    var Number x = 0
    if(DimmerCam.state instanceof Number)
        x = ((DimmerCam.state as Number) * 0.24).intValue
    tApertura?.cancel
    tApertura = createTimer(now.plusSeconds(x)) [|
        LivingRoom_Light1.sendCommand(OFF)
    ]
end

In the “THEN” i want that the system evoides to execute a rule (ex rule “apertura”).
How do i this?

if(<some condition>) return;
// code to run when condition is false

or

    if(<some condition>) {
        code to run when condition is true
    }
1 Like

and why in this situation is Auto.state always NULL?



rule "Scendi"
when 
	//Every weekday at 21:19 hours
	Time cron "0 02 23 ? * MON-SUN *"
then
     logWarn("Alarm", "The {} orario1", Auto.state)

Auto.state == 0
logWarn("Alarm", "The {} orario2", Auto.state)

    // update item to switch on light here
    LivingRoom_Light1.sendCommand(ON)

end


2019-03-21 23:02:00.471 [WARN ] [eclipse.smarthome.model.script.Alarm] - The NULL orario1

This is a comparison. Try only one = to assign a value

If Auto is a Number Item, you should use Auto.postUpdate(0) to set it. But that will take place outside your rule, if you immediately read the state again it will probably still be the “old” state.

All Items start off as NULL state until something updates them.

1 Like

Is it possible to define a variable that is seen from all rules also if the rules are on more file.rules?
If yes, how?

You can use a so called “virtual item”:

Ah ok
It’s the same that i did

How does PostUpdate(0) works?

Why Auto.state is not 1?

logWarn("Alarm", "The {} dovrebbe essere zero", Auto.state)
if (Auto.state == 0) {
	Auto.state == 1	
	logWarn("Alarm", "The {} dopo messo a 1", Auto.state)
	
	return;
	}

2019-03-22 21:42:40.567 [WARN ] [eclipse.smarthome.model.script.Alarm] - The 0 dovrebbe essere zero

2019-03-22 21:42:40.576 [WARN ] [eclipse.smarthome.model.script.Alarm] - The 0 dopo messo a 1

Come on, this is basic openHAB stuff as seen in every document and example.

Auto.postUpdate(0) is Auto.state = 0. Is it true?

Yep, item.postUpdate(something) sets the Item state.

item.state = something does appear to work, but it is not documented and you should not use it, it might not work next week.

In thjs code

rule "Scendi"
when 
	//Every weekday at 21:19 hours
	Time cron "50 35 22 ? * MON-SUN *"
then
 //    logWarn("Alarm", "The {} all'inizio", Auto.state)
if (LivingRoom_Light2.state == ON) {
    createTimer(now.plusSeconds(24))
	}

     Auto.postUpdate(0) 

Is it correct the if stantment?
I’m not sure of the “(LivingRoom_Light2.state == ON”

Yes.

The timer is incomplete and does nothing.

What do you mean?

rule "Scendi"
when 
	//Every weekday at 21:19 hours
	Time cron "30 51 22 ? * MON-SUN *"
then
     logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)
if (LivingRoom_Light2.state == ON) {
    createTimer(now.plusSeconds(24))
	}

     Auto.postUpdate(0) 

	//dire Auto.postUpdate(0) significa dire che Auto.state == 0. con i numeri si scrive cosi
   //  logWarn("Alarm", "The {} dopo messo a 0", Auto.state)

    // update item to switch on light here
    LivingRoom_Light1.sendCommand(ON)
  
end

When your rule runs (at 22:51 each day), if LivingRoom_Light2 is on at that time, the rule creates a timer that does nothing. I expect it’ll generate an error actually, due to the missing lambda part.

That’s the end of the if() part.

Whether the if() runs or not, Auto will get updated to 0.

1 Like

this is the code complete


    rule "Scendi"
when 
	//Every weekday at 21:19 hours
	Time cron "30 58 22 ? * MON-SUN *"
then
     logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)

	 //
if (LivingRoom_Light2.state == ON) {
    createTimer(now.plusSeconds(24)) [|
        LivingRoom_Light1.sendCommand(ON)
		return;
    ]

	}
//

     Auto.postUpdate(0) 

	//dire Auto.postUpdate(0) significa dire che Auto.state == 0. con i numeri si scrive cosi
   //  logWarn("Alarm", "The {} dopo messo a 0", Auto.state)

    // update item to switch on light here
    LivingRoom_Light1.sendCommand(ON)
  
end


end



ok it works.
thank’s

what is the error in this?

rule "Scendi"
when 
	//Every weekday at 21:19 hours
	Time cron "00 00 20 ? * MON-SUN *"
then
     logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)

	 //
if (LivingRoom_Light2.state == ON) {
	logWarn("Alarm", "The {} dentro", LivingRoom_Light2.state)

when   LivingRoom_Light2 received update 

then
		 Auto.postUpdate(0) 
        LivingRoom_Light1.sendCommand(ON)
		return;
    

	}
end