Do not execute a Rule

Every rule must have its own when-then-end. You cannot combine rules like that.

but if i want to insert in if stantment a condition?
I explain me:

if LivingRoom_Light2.state == ON i want to waiting for the state of LivingRoom_Light2 change to OFF.
When this become OFF i want to do something.

How can i do it?

With two rules, like you showed us, but with each rule having a rule-when-then-end

Ok but if i want to do the same without the when-then-end in the same rule, is there an alternative way to waiting for LivingRoom_Light2 became off in the if stantment?

OK, this is going nowhere. For the experts in this community (or me) to really help you, let’s take a step back:

  1. Spend time describing what you want to accomplish (the end goal) instead of dropping a few lines of code and asking ‘why doesn’t it work’. Their time is valuable too… :sunglasses:
  2. Read the documentation (again), expecially about the rules language.
  3. Read the answers to your questions thoroughly (especially from @rossko57).

I’m sure this community is able to help you accomplish what you want in no time.

ok Sorry.
I’m a solution.

Now I have an error.

rule "chiusura"
    Item LivingRoom_Light1 changed to ON
    var Number x = 0
	var Number y = 0
	var Number z = 0


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

    if(DimmerCam.state instanceof Number)
        x = ((DimmerCam.state as Number) * 0.24).intValue

		// y è la variabile che ci dice quanti secondi ci mancano 
		// per chiudere totalmente la serranda

             z = (Percentuale.state).intValue              


 logWarn("Alarm", "Quanto vale z? {}", Percentuale.state)			

	         if (z == 0) {
             z == 24                        
             logInfo("AVVISO", "LA SERRANDA E' GIA' TUTTA ABBASSATA")                      


             if (z <= x) {
        	 y = (z - x).intValue 


	         z = y 

			 Percentuale.state = z 

    tApertura = createTimer(now.plusSeconds(x)) [|


2019-03-23 09:47:28.290 [ome.event.ItemCommandEvent] - Item ‘LivingRoom_Light1’ received command ON

2019-03-23 09:47:28.424 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2019-03-23 09:47:29.103 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘chiusura’: ‘intValue’ is not a member of ‘org.eclipse.smarthome.core.types.State’; line 35, column 18, length 28

==> /var/log/openhab2/events.log <==

2019-03-23 09:47:52.499 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from ON to OFF

Why is this code not correct:

z = (Percentuale.state).intValue

Percentuale is an item type number

In other parts of your rule, you have used (item.state as Number)
That seems to work, no?

A Number type Item is not the same as a variable of class Number.
The state of an Item is it’s state, not automatically a Number even when the Item is of type Number.
I know that’s confusing, but you must draw a clear distinction between Items and ‘ordinary’ variables.

Many of your problems so far have been about that.
Items are not variables and you cannot treat them as variables.

This work without problems

this code work

rule "Scendi"


	//Every weekday at 21:19 hours
	Time cron "00 02 00 ? * MON-SUN *"
     logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)
var Number y = 0

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

    createTimer(now.plusSeconds(24)) [|


		    y = (Percentuale.state).intValue
            logWarn("Alarm", "The {} valore di y in ap automat.", Percentuale.state)
            createTimer(now.plusSeconds(y)) [|



if (LivingRoom_Light2.state == OFF) {


	//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

It is not clear.
I use the same sintax


1 Like

I solved

Glad you got it sorted out!