Rule not always working

Hi,
i don´t have a wall switch to switch the light for my stairs. If someone switches light in the room before stairs, then stairs will be switched on, too.

But it is not wirking all the time. Sometime it works, sometimes the stair lights stay off.

Here are my rules:

rule "Stufenlicht Treppe OG ein"
when
    Item Licht_EG_Flur received update or
    Item Licht_OG_Flur received update
then
    if (Licht_EG_Flur.state==ON) {
        if (Licht_OG_Stufenlicht.state==OFF) {
            sendCommand(Licht_OG_Stufenlicht, ON)
        }    
    }
    if (Licht_OG_Flur.state==ON) {
        if (Licht_OG_Stufenlicht.state==OFF) {
            sendCommand(Licht_OG_Stufenlicht, ON)
        }    
    }
end


rule "Stufenlicht Treppe OG aus"
when
    Item Licht_EG_Flur received update or
    Item Licht_OG_Flur received update
then
    if (Licht_EG_Flur.state==OFF && Licht_OG_Flur.state==OFF) {
        sendCommand(Licht_OG_Stufenlicht, OFF)
    }
end

rule "Stufenlicht Treppe KG ein"
when
    Item Licht_EG_Flur received update or
    Item Licht_KG_Flur received update
then
    if (Licht_EG_Flur.state==ON) {
        if (Licht_KG_Stufenlicht.state==OFF) {
            sendCommand(Licht_KG_Stufenlicht, ON)
        }    
    }
    if (Licht_KG_Flur.state==ON) {
        if (Licht_KG_Stufenlicht.state==OFF) {
            sendCommand(Licht_KG_Stufenlicht, ON)
        }    
    }
end


rule "Stufenlicht Treppe KG aus"
when
    Item Licht_EG_Flur received update or
    Item Licht_KG_Flur received update
then
    if (Licht_EG_Flur.state==OFF && Licht_KG_Flur.state==OFF) {
        sendCommand(Licht_KG_Stufenlicht, OFF)
    }
end

I changed for testing “received update” to “changed” - but still it was not working all the time.

Can someone help me? Why is this not working all the time?

how do the “Licht_*G_Flur” change their values? Are theese states really “updated” or are theese “commands”? So you should switch to “received command”:
Item <item> received command [<command>]
Greetings

Licht_*G_Flur is a light-switch.

It is a switch item and i switch light with a wall switch. State can be on or off.

It is not working with:

received update
changed
received command

when
    Item Licht_EG_Speis received command or
    Item Licht_EG_WC_Spots received command
then

not working

i don’t understand what “not working” means.
First of all: Check the Busevents and show us what happens when you toggle the wall switch (which shall be the trigger for the rules).

Hello Helloween

Can you provide some more information?
OH Version, Binding, which things are behind the items…

I recommend to use the condition "Item Licht_* changed to ON.
So you save one of your if conditions.

At @spy0r mentioned…Check if your item receives an update on the bus.

I had a similar issue with an fibaro double switch (zWave), which only sent information for one of 2 channels to the bus.

Regards
Michael

If i switch on the Licht_EG_Flur, the Licht_OG_Treppenlicht ist not switching on.

Only Light_EG_Flur is on then.

If i press button on openhab-sitemap, it shows on or off in the log-file. If i press the separate button for Licht_OG_Stufenlicht, the light in the stairs is switched on at once. There i can also see on or off in the log-file.

I only have wall switches for Licht_*G_Flur, not so for *-Stufenlicht". “Stufenlicht” should always switch on if Licht_Flur will switch on.

How do you switch on the “Licht_EG_Flur”? Via openHAB item or wall switch?
If via wall switch… what is the status of your OH Item?

Does your rule work, if you switch the OH Item?

I can switch Licht_EG_Flur with wall switch and with openhab. Both is working, same behaviour.

Now i changed the rule to “changed to ON” instead of “receiving update”. On my first few tries it wasn´t working. Both lights switched on, but “Steufenlicht” was not switched to off if both lights are off.

But after a few tries now it works… Strange…

Same rule for another light is working for weeks without any problems…

rule "Licht Eingang EG ein"
when
    Item Licht_EG_Speis received update or
    Item Licht_EG_WC_Spots received update
then
    if (Licht_EG_Speis.state==ON) {
        if (Licht_EG_Eingang.state==OFF) {
            sendCommand(Licht_EG_Eingang, ON)
        }    
    }
    if (Licht_EG_WC_Spots.state==ON) {
        if (Licht_EG_Eingang.state==OFF) {
            sendCommand(Licht_EG_Eingang, ON)
        }    
    }
end


rule "Licht Eingang EG aus"
when
    Item Licht_EG_Speis received update or
    Item Licht_EG_WC_Spots received update
then
    if (Licht_EG_Speis.state==OFF && Licht_EG_WC_Spots.state==OFF) {
        sendCommand(Licht_EG_Eingang, OFF)
    }
end

This was working from the beginning.

But the rules for my stair-lights (Treppenlight) was not working like it shopuld be.

Now i changed to this and i will keep an eye ont his… I will report back, if it will fail in future again.

rule "Stufenlicht Treppe OG ein"
when
    Item Licht_EG_Flur changed to ON or
    Item Licht_OG_Flur changed to ON
then
    if (Licht_OG_Stufenlicht.state==OFF) {
        sendCommand(Licht_OG_Stufenlicht, ON)
    }    
    if (Licht_OG_Stufenlicht.state==OFF) {
        sendCommand(Licht_OG_Stufenlicht, ON)
    }    
end


rule "Stufenlicht Treppe OG aus"
when
    Item Licht_EG_Flur changed to OFF or
    Item Licht_OG_Flur changed to OFF
then
    if (Licht_EG_Flur.state==OFF && Licht_OG_Flur.state==OFF) {
        sendCommand(Licht_OG_Stufenlicht, OFF)
    }
end

rule "Stufenlicht Treppe KG ein"
when
    Item Licht_EG_Flur changed to ON or
    Item Licht_KG_Flur changed to ON
then
    if (Licht_KG_Stufenlicht.state==OFF) {
        sendCommand(Licht_KG_Stufenlicht, ON)
    }    
    if (Licht_KG_Stufenlicht.state==OFF) {
        sendCommand(Licht_KG_Stufenlicht, ON)
    }    
    
end


rule "Stufenlicht Treppe KG aus"
when
    Item Licht_EG_Flur changed to OFF or
    Item Licht_KG_Flur changed to OFF
then
    if (Licht_EG_Flur.state==OFF && Licht_KG_Flur.state==OFF) {
        sendCommand(Licht_KG_Stufenlicht, OFF)
    }
end

I’m glad to help you.

Let us know, if some problems come back.

regards

Maybe if Licht_Stufenlicht has no status - like after a restart of openhab, then i think the rule will not work, because

if (Licht_OG_Stufenlicht.state==OFF) {

(or ==on) will be false.

Can this be the answer? But my knx wall switches get the right status, even after a complete restart of knx and openhab. LED on the wall switch will change color, after a few seconds when all is restarting. red=light off, green=light on

But openhab will not get this information? Openhab will first get information about the state of the switches when i change their state for the first time?

Or will openhab be informed from knx after restart? Is openhab reading all states of the switches in my items file after restart?

Do you use any persistence?
If not, I recommend to implement a “Initializing” Rule, which checks all items if they are uninizialized

if (Lueftung.state == Uninitialized) {
	Lueftung.postUpdate(OFF)
}

In my early beginning I triggered this to all of my items on regulary basis

System started or
Time cron "* * /1 * * ?"

Every single item must be initialized (OH1) or have another state as “NULL” (OH2)…
When you start OH, they are all uninitialized. After the first switch they get their status (ON/OFF).

1 Like

I use rrd4j - but only for temperature and things like this. Not for state of switches.

What will be the benefit of a rule, which checks all items for uninitialized state? And what will be, if a light will be powered on, but switch is uninitialised and so the rule will give the switch the state “off”?

Is Lueftung in your exymple above the name of an item or the name of a group?

You have never uninitialized items and your ruleset works :wink:

The light goes off.

In my Case “Lueftung” is a virtual Switch, a single item.

Do you need to check the previous state at all? It should not matter if you send an ‘ON’ if the switch is already ON.

I thought, this would cause less commands to send and so this would be better?

But if this should not matter, i will remove it.

You could do this test:

if (Licht_KG_Stufenlicht.state!=ON) {
    sendCommand(Licht_KG_Stufenlicht, ON)
}

which will work, even if the state is uninitialized.

Thanks, that sounds better. But i installed MapDB and persist all my rollershutters, lights and so on with this. So i never get uninitialised any more (in therory :wink: )

But i will change my rules to this.