Scene Rule not executed

Hello all,

my openHAB 3 runs on a raspberry pi3. The OS is a openhabian.
I have a problem with a rule. This rule should be for a scene control. When I activate an item in comet visu, a certain light setting should take place.
Here is the rule:

rule "scenes light Wohnzimmer EG"
when
    Item ScenesLightsEGWohnz received command 
then

    switch (ScenesLightsEGWohnz.state) {
        case 1: {
            	Light_EG_Wohnz_TV.sendCommand(OFF)
		Light_EG_Wohnz_Couch.sendCommand(15)
		Light_EG_Wohnz_Mitte.sendCommand(25)
		Light_EG_WohnMitteDimmer_2_Level.sendCommand(OFF)
		Light_EG_Wohnz_Eingang.sendCommand(OFF)
		Light_EG_Essen.sendCommand(OFF)
        }
        case 2: {
        	Light_EG_Wohnz_Eingang.sendCommand(25)
	        Light_EG_Essen.sendCommand(ON)
	        Light_EG_WohnMitteDimmer_2_Level.sendCommand(ON)
                Light_EG_Wohnz_TV.sendCommand(OFF)
		Light_EG_Wohnz_Couch.sendCommand(OFF)
		Light_EG_Wohnz_Mitte.sendCommand(OFF)
		
        }
        case 3: {
            	Light_EG_Wohnz_TV.sendCommand(ON)
		Light_EG_Wohnz_Couch.sendCommand(ON)
		Light_EG_Wohnz_Mitte.sendCommand(ON)
		Light_EG_Wohnz_Eingang.sendCommand(ON)
		Light_EG_Essen.sendCommand(ON)
		Light_EG_WohnMitteDimmer_2_Level.sendCommand(ON)
        }
        case 4: {
            	Light_EG_Wohnz_TV.sendCommand(OFF)
		Light_EG_Wohnz_Couch.sendCommand(OFF)
		Light_EG_Wohnz_Mitte.sendCommand(OFF)
		Light_EG_WohnMitteDimmer_2_Level.sendCommand(OFF)
		Light_EG_Wohnz_Eingang.sendCommand(OFF)
		Light_EG_Essen.sendCommand(OFF)
        }
        default: { 
            logInfo("SceneLightEGWohnzimmer","incorrect state: {}",ScenesLightsEGWohnz.state)
        }
    }
end

When I look in the event log, the item is set to with the status, but the rule doesn’t seem to be called at all.

> 
> 2021-11-25 21:21:29.126 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'I_OG_2_6_Zimmer_HT_ActualTemp' changed from 19.60 °C to 19.50 °C
> 2021-11-25 21:23:43.466 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'ScenesLightsEGWohnz' received command 1
> 2021-11-25 21:23:45.317 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'ScenesLightsEGWohnz' received command 2
> 2021-11-25 21:23:45.320 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ScenesLightsEGWohnz' changed from 1 to 2
> 2021-11-25 21:23:46.657 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'ScenesLightsEGWohnz' received command 3
> 2021-11-25 21:23:46.659 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ScenesLightsEGWohnz' changed from 2 to 3
> 2021-11-25 21:23:48.680 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'ScenesLightsEGWohnz' received command 4
> 2021-11-25 21:23:48.684 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ScenesLightsEGWohnz' changed from 3 to 4

Does anyone have a solution to this problem.

Find out.

when
    Item ScenesLightsEGWohnz received command 
then
    logInfo("test", "My rule has started")

but you haven’t mentioned looking in your openhab.log for that switch-default log?

I’m suspicious of that. You’ll get a state type object there.

I don’t think a state object is going to match integer 1.
Maybe try
switch (ScenesLightsEGWohnz.state as Number)

There is a huge trap here for you though. Your rule is triggered on command, but your switch-case works on Item state. These are two different things, and as you can see in your events log, even if a command does change Item state (and it might not) the state doesn’t change until later in time.
Your rule is probably looking at the “old” state, before the command has taken effect.
That’s okay, if you are interested in the command, then use the command, and ignore the state.

switch (receivedCommand as Number)

The reference to the openhab.log brought the solution. I had partially renamed the items and usually forgot to adjust them.
With the right item names, it works perfectly now.