Dimmer with physical Switch

Hi,
I am new to OpenHab and already did a lot of googling but cannot find a solution for my problem.

I got a dimmer (Homematic) and a physical switch from homematic which got channels for short and long press. Short presses should lead to On/Off and it works fine. Long presses should continously dim the lamp but that’s not working well. Everything is working fine in the UI but not with the physical device.

I tried with this rule:

rule "Spots dunkler"
when
	Item Wandtaster_Button1_Left_Long changed to ON
then
	while(Wandtaster_Button1_Left_Long.state == ON) {	
		if((spotsDimmVal - 10) < 0) {
			spotsDimmVal = 0
		} else {
			spotsDimmVal -= 10
		}	
		sendCommand(Light_Spots, spotsDimmVal)
		Thread::sleep(1000)
	}
end

The problem is, commands don’t get executed before I stop pressing the button. My expected and wished behaviour would be, that while pressing the button, the spots slowly dim until I stop pressing.

Thanks for your help!

For one thing, I would use a much lower sleep. Something in the 100-200 range, not a full second. 1 second is a really long time, particularly when you are debugging.

Beyond that, assuming the Item gets updated the way it is expected then the rule looks OK to me.

Where does spotsDimmVal come from? Maybe you lost some details of your rule. I guess, it should be something like

rule "Spots dunkler"
when
    Item Wandtaster_Button1_Left_Long changed to ON
then
    var Number spotsDimmVal = (Light_Spots.state as DecimalType).intValue
    while(Wandtaster_Button1_Left_Long.state == ON) {
        if((spotsDimmVal - 10) < 0) {
            spotsDimmVal = 0
        }
        else {
            spotsDimmVal -= 10
        }
        sendCommand(Light_Spots, spotsDimmVal)
        Thread::sleep(100)
    }
end

Please consider to use the method in favor of the action. The action sendCommand(string, string) needs a String as input, where the method item.sendCommand(value) does not, so, if using primitives, the action maybe will fail, where the method does not, see sendCommand() Documentation for a very detailed explanation (thank you @rlkoshak)