Control a dimmer with a switch

I hope my Question is not too stupid. I try to control a dimmer (FUD61NPN) with a switch (FT55).

  • short press and release in direction 2 shall switch the Dimmer ON
  • short press and release in direction 1 shall switch the Dimmer OFF
  • long press in direction 2 shall start dimming UP and with release the dimming UP shall be stopped.
  • long press in direction 1 shall start dimming DOWN and with release the dimming DOWN shall be stopped

I have OpenHabian 2.5.4-1 running on a Raspberry Pi 4 with an Enocean USB300 Stick and the Enocean Binding.

I have added the Dimmer and the Switch as Things in Paper UI.

In the .items file I have defined the Dimmer.

Dimmer EG_WZ_Stehlampe_Dimmer "Stehlampe Dimmer" {channel="enocean:centralCommand:28511a76:dimmer"}

With the help of other topics I can separate the short presses from the long ones by rules. (only on direction here as example)

rule "FT55 UP Pressed"
when Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR2_PRESSED"
then
   pressDIR2Timestamp= now.millis
   EG_WZ_Stehlampe_Dimmer.sendCommand(INCREASE)
end

rule "FT55 UP Released"
when Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR2_RELEASED"
then
   if(now.millis - pressDIR2Timestamp < 500) 
   {
       // Long PRESS
   
   } else {
      // Short PRESS
      EG_WZ_Stehlampe_Dimmer.sendCommand(100)
   }
end

But I did not yet found a solution how to Start dimming with just the press of the switch and stopp dimming with the release of the switch.

I hope someone can help me with my problem.

Best regards,
Thomas

Sorry if I’m not very good at writing rules, but I’d guess after the button is pressed you create a timer that upon expiry raises the brightness a bit and then re fires the timer and is killed upon receiving button release. There are some threads here that talk about timers that work like this, but I’ve no idea where. Maybe this would help:

https://community.openhab.org/t/design-pattern-expire-binding-based-timers/32634

Ira

1 Like

hi thomas,
did i understand you correct: i suppose you want to use the openhab-app and you want to dimm as long as you touch the button? if so i´m afraid that will not be possible as far as i know. then the only possibillity that i know is to create four buttons: off, on, dimm+ and dimm- (and dimm with each touch a specific value).
best, stefan

I think enocean supports both button-pressed and button-released events, so @Ira outline should be fine.

Pressed to start off a looping timer, which ramps the dimmer this way or that, step by slow step.
Released to cancel and stop the timer.

Hi,

Thank you all. The hint with the Timer was great.
I did not yet understood the Design Pattern. Maybe I have to read it more in detail later on.

@bastler It is a real enocean rockerswitch mounted on the wall.

I tried to set up an Timer to controll the fading.

Here is my final code which works well. Hopefully someone can use it as well.

Definition of the variables:

var Number pressDIR1Timestamp
var Number pressDIR2Timestamp
var int percent = 0
var Timer fade_Timer = null

When the upper direction of the switch is pressed, I set the Timestamps to figure out later on of the switch was pressed long or short. And I start the fade_Timer to Dimm the light on.
As long as the percent value is < 100 AND the timer is not null the timer will be restarted

rule "Taster 4er Terasse Unten, rechts OBEN gedrückt"
when 
   Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR2_PRESSED"
then
   pressDIR2Timestamp= now.millis
   fade_Timer = createTimer(now, [ | 
      if (percent < 100 && fade_Timer !== null) {
         percent = percent + 5
         logDebug("Timer", "Prozentwert {}", percent)
         EG_WZ_Stehlampe_Dimmer.sendCommand(percent)
         fade_Timer.reschedule(now.plusMillis(300))
      }
   ])
end

When the switch will be released, I check with the Timestamp if it was a short press, then the light will turn on with 100%. If it was a long press, I stop the timer by setting it to null so the dimming stopps.

rule "Taster 4er Terasse Unten, rechts OBEN losgelassen"
when 
   Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR2_RELEASED"
then
   fade_Timer = null
   if(now.millis - pressDIR2Timestamp > 500) 
   {
       // Long PRESS
   } else {
      // Short PRESS
      EG_WZ_Stehlampe_Dimmer.sendCommand(ON)
      percent = 100
   }
end

The same just the other way round is for the lower direction.

rule "Taster 4er Terasse Unten, rechts UNTEN gedrückt"
when 
   Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR1_PRESSED"
then 
   pressDIR1Timestamp= now.millis
   fade_Timer = createTimer(now, [ | 
      if (percent > 0 && fade_Timer !== null) {
        percent = percent - 5
         logDebug("Timer", "Prozentwert {}", percent)
        EG_WZ_Stehlampe_Dimmer.sendCommand(percent)
         fade_Timer.reschedule(now.plusMillis(300))
      }
   ])
end

rule "Taster 4er Terasse Unten, rechts UNTEN losgelassen"
when 
   Channel "enocean:rockerSwitch:ff84741e:rockerswitchB" triggered "DIR1_RELEASED"
then
   fade_Timer = null
   if(now.millis - pressDIR1Timestamp > 500) 
   {
       // Long PRESS
   } else {
      // Short PRESS
      EG_WZ_Stehlampe_Dimmer.sendCommand(OFF)
      percent = 0
   }
end

Best regards,
Thomas

1 Like