Difference Between Command and Manual - How To?

Hi,

I have a Nodn In Wall Module to switch my light on or off additionally to the old-schooled wall switch. This works perfectly fine with openHAB and my rules.
So I press the old wall switch, the Nodon switches the light on and informs openHAB about the state change. Same other way round- I use the wall switch and Nodon switches off. I can see every action in openHAB and I can switch the light on or off from openHAB.
To save energy I have coded my rule to switch the light off after three minutes (if not switched off by the wall switch).
Nearly perfect!
JFYI here the current rule:

var Timer timer = null
rule "Vorratsraum"
when
        Item Schalter_EG_Vorratsraum_Licht changed
then
        if (Schalter_EG_Vorratsraum_Licht.state == ON )
        {
                timer = createTimer(now.plusMinutes(3),
                [ | {
                        Schalter_EG_Vorratsraum_Licht.sendCommand(OFF)
                } ] )
        } else {
                if (timer !== null) {
                        timer.cancel
                        timer = null
                }
        }
end

Now I want to install a motion sensor additionally. It should switch the light on when motion is detected and switch it off when no motion is detected for a while- but when the light was switched on by the wall switch it should stay on at least for the above configured three minutes (and not immediately when noch motion is detected). But if the light was switched on by a motion it should immediately switch off when motion is gone.

So I need to differentiate between the manual “switch-on” and the automated “switch-on”.

But how do I do this as the Nodon is a single switch and just changes it states no matter if it was by command or by wall switch.

So I was thinking of using the “Item received command” but it will be the same in both cases.

Anyone having a clue how to reach this goal?

Thanks!

/KNEBB

Hi, I foudn a solution for this appears to be working fine for the first test:

var Timer timer = null
var manual = 0

rule "Bewegungsmelder Vorratsraum ON"
when
        Item Bewegungsmelder_EG_Vorratsraum changed to ON
then
        if (Schalter_EG_Vorratsraum_Licht.state === OFF ) {
                // keine manuelle Betätigung liegt vor --> EIN
                Schalter_EG_Vorratsraum_Licht.sendCommand(ON)
        }
end

rule "Bewegungsmelder Vorratsraum OFF"
when
        Item Bewegungsmelder_EG_Vorratsraum changed to OFF
then
        if (manual === 0 ) {
                // keine manuelle Betätigung liegt vor --> AUS
                Schalter_EG_Vorratsraum_Licht.sendCommand(OFF)
        }
end


rule "Wandschalter Vorratsraum"
when
        Item Schalter_EG_Vorratsraum_Licht changed to ON
then
        // manuell oder automatisch?
        if (Bewegungsmelder_EG_Vorratsraum.state === OFF) {
                manual = 1
                timer = createTimer(now.plusMinutes(3),
                [ | {
                        Schalter_EG_Vorratsraum_Licht.sendCommand(OFF)
                        manual = 0
                } ] )
        }
end

Only use === and !== with null

Ah, ok. Thanks. I will fix it.

I was not aware.

/KNEBB