Dimmer with 1-Button KNX, Slider in openHAB, MQTT Aktor

Hello All,
is it possible to set the position of a Slider within openHAB by pressing a KNX-Button short or long to control a Dimmer.
Dimmer might be a MQTT-Arduino which outputs a PWM or any other device.
Has anybody done something before (the catching of the press-time and controlling the slider with it)?

Ingo
ps. I tried this for some time in Fhem now, and I’m about to give up

Should be easy in OH :slight_smile:

First if you want to measure the time between press and release, you have to configure the button to send one telegram when pressed and one telegram when released. (ON and OFF)

Secondly you have to write a rule. I have one to test the on-time of bathroom light:

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command
import org.joda.time.DateTime

var long StartTime_Bath = 0
var long runtime_Bath = 0
var long StopTime_Bath = 0 

rule "Bad Dauer"
when
    Item Light_GF_Bath received command
then
    if(receivedCommand==ON) {
            StopTime_Bath = 0
            StartTime_Bath = now.millis
        }
    else if(receivedCommand==OFF) {
            runtime_Bath = (now.millis - StartTime_Bath)
            logInfo("GF_Bath",now + ": StartTime_Bath= " + StartTime_Bath + "; runtime_Bath= " + runtime_Bath)
        StartTime_Bath = 0
    }
end

I use runtime_Bath to decide for the time lag of the ventilator, so you could use this value to decide for the dimmer value.

But maybe an easier way will last also:

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command
import org.joda.time.DateTime

var Timer myTimer = null

rule "Short-Long Press"
when
    Item Light_GF_Bath received command
then
    if(receivedCommand==ON) 
        myTimer = createTimer(now.plusMillis(500))[|
            MyDimmer.sendCommand(50)]
    else if(receivedCommand==OFF && myTimer!=null) {
        myTimer.cancel 
        myTimer = null
        MyDimmer.sendCommand(75)
    }
end

This rule starts a timer (myTimer) which will set MyDimmer to 50% after 0.5 secs, but if you release the button before the Timer expires, MyDimmer is set to 75% and the Timer is canceled.
Maybe 0.5 secs is a bit short though.
I remember a even more complex rule, which allowed to discern between single, double and tripple click. It even contained a serial switch, so the first step was light1 on, the second step was light1 off but light2 on, the third step was both lights on, the fourth step was both lights off. You should find this example in the german forum.

Thanks for the quick reply!
Those “rules” look like “normal” programming language (instead of Perl). I will give it a trie.

Would it work, to set up openHAB and Fhem and KNXd on the same Raspi? any Idea?
Thanks,
Ingo