IKEA Trådfri remote dimming

Hi

I have an IKEA Trådfri remote, and i can see I need to make a rule if i should use the buttons because i only have one number item called Dimmer Switch State

My item receives the following codes if i press the buttons, X is a different number from 1-5 for each button.

INITIAL_PRESSED X002
HOLD X001
LONG RELEASED X003

I’m thinking if i press and hold a button it should send a dimming up/down to an item. and i short press should turn on/off the item.

Has anyone done a rule to get this to work with dimming and on/off switch?

I don’t fully understand your post.

To my knowledge, the Trådfri 5-button remote does not report its button presses to openHAB through the Trådfri binding. Nor does any of the other Trådfri sensors (dimmers, motion sensors). Only state changes for actuators (lamps, control outlets, blinds) are reported.

Hence, the only way to create a rule in openHAB is to detect whether a controllable thing changed. In practice, that means a light bulb, a control outlet or a blind.

For Trådfri lights, there are 2 or 3 channels that will be reported, which you can use in your rules:

  • on/off (ON or OFF state)
  • dimmer value (percentage between 0 and 100)
  • color spectrum or color temperature (also percentage between 0 and 100)

For Trådfri control outlets, there is only one channel:

  • on/off (ON or OFF state)

I don’t know the Trådfri blinds since I don’t have them at home. I expect there will be dimmer value channel (position as percentage value), a battery level channel and low battery channel.

For instance, the kitchen cabinet lights are dimmable but have a fixed color temperature. They are defined as follows (replace gwa0b1c2d3e4f5 with the ThingUID from your Trådfri gateway):

// Warm-white, dimmable
Switch	Kitchen_Light_Toggle	 "Kitchen countertop"	<light>	(gHome_GF_Kitchen, gLight)	 ["Lighting", "Switchable"]	{
	channel="tradfri:0100:gwa0b1c2d3e4f5:65560:brightness"
}
Dimmer	Kitchen_Light_Dimmer	"Kitchen countertop [%d %%]"	<light>	(gHome_GF_Kitchen, gDimmer)	 ["Lighting", "Switchable"]	{
	channel="tradfri:0100:gwa0b1c2d3e4f5:65560:brightness"
}

In your rules, you could then check things like:

// Rules DSL:
rule "Kitchen Cabinet Light goes ON"
when Item Kitchen_Light_Toggle changed to ON
then
    // Rule code here
end

or:

# JSR223 Jython:
@rule("Kitchen Cabinet Light goes ON")
@when("Item Kitchen_Light_Toggle changed to ON")
def Rule_KitchenCabinetLightGoesOn(event):
    # Rule code here

Hi

Sorry for the missing details, I use the DECONZ binding in this binding I can see the remotes, and see there state like in the Hue Binding.

I have made a dimmer rule and got it to work. I can post it later today.

1 Like

I have made a rule to get my remote to dim it works fine, but is there a better way to restart my rule or a way to continue to send INCREASE/DECREASE on butten press, now i need to restart my rule with item DimmingTimer not the prefect solution

var Number dimmer = 0

/* IKEA Remote Rules */
rule IKEA_Remote



when
Channel "deconz:switch:13e1e66e:buttonevent" triggered or
Item DimmingTimer changed to ON

then
DimmingTimer.sendCommand(OFF)

if (IkeaTrDfriRemote_Button.state == 2002)
//if (receivedEvent.getEvent() == "2002")
	{
    if (hue_spejl_switch.state == OFF) 
    			{
    			hue_spejl_switch.sendCommand(ON)	//Tænd Toilet
    			}
    				else
    					{
						hue_spejl_switch.sendCommand(OFF)	//Sluk Toilet
						} 
	} 

  if (IkeaTrDfriRemote_Button.state == 4002)
//if (receivedEvent.getEvent() == "4002")
	{
    if (hue_gang_brightness.state == 0) 
    			{
    			hue_gang_brightness.sendCommand(50)	//Tænd ganglys
    			}
    				else
    					{
						hue_gang_brightness.sendCommand(0)	//Sluk ganglys
						} 
	}
	
if (IkeaTrDfriRemote_Button.state == 4001) //langt tryk ØV  
     {
     	if (dimmer == 1)
     	{
     	hue_gang_brightness.sendCommand(INCREASE)	//hæv lysstyrken
     	Thread::sleep(500)
     	DimmingTimer.sendCommand(ON)	
     	}
     		else if (dimmer == 0)
     		{
     		hue_gang_brightness.sendCommand(DECREASE)	//Sænk lysstyrken
    		Thread::sleep(500)
     		DimmingTimer.sendCommand(ON)	
     		}
      }

if (IkeaTrDfriRemote_Button.state == 4003)	//Release langt tryk
		if (dimmer == 1)
		{	
		dimmer = 0	
		}
	else
		{
		dimmer = 1
		}
	
	
	
end
2 Likes

I did fix the issue with a timer

`

//Regler for IKEA Remote I gang

var Number dimmer_ov = 0 		// Op/ned status ØV
var Number dimmer_oh = 0 		// Op/ned status ØH
var Number dimto = 0			//Send ny lysværdi
var Number Uplevel = 5			//% op
var Number Downlevel = -5		//& ned
var Timer timer = null			//timer til stining
val int fade = 250				//tid mellem hver stining
var Number state_ov = 50		//Start niveau ØV
var Number state_oh = 50		//Start niveau ØH


/* IKEA Remote Rules */
rule IKEA_Remote



when
Channel "deconz:switch:13e1e66e:buttonevent" triggered


then
//ov = hue_gang_brightness.name


//var trigger = receivedEvent.getEvent()
//state = (receivedEvent.getEvent)
//if (IkeaTrDfriRemote_Button.state == 2002)
switch(receivedEvent.getEvent())

{
	
case "2002":		//Tryk NV
	{
    if (hue_spejl_switch.state == OFF) 
    			{
    			hue_spejl_switch.sendCommand(ON)	//Tænd Toilet
    			}
    				else
    					{
						hue_spejl_switch.sendCommand(OFF)	//Sluk Toilet
						} 
	} 

case "4001":		//langt tryk ØV 
 
     {
     	dimto = hue_gang_brightness.state
 		
     	if (dimmer_ov == 1)
     		{
     			timer = createTimer(now.plusSeconds(0),//Starts immediately 
     				[ |   
            		dimto = dimto + Uplevel
            		if (dimto <=100 && IkeaTrDfriRemote_Button.state == 4001)
            			{
            			hue_gang_brightness.sendCommand(dimto)	//hæv lysstyrken	
                		timer.reschedule(now.plusMillis(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                            return;
            				}
        			])
    			}
     	 if (dimmer_ov == 0)
     			{
     			timer = createTimer(now.plusSeconds(0),//Starts immediately 
     				[ |   
            		dimto = dimto + Downlevel
            		if (dimto >=10 && IkeaTrDfriRemote_Button.state == 4001)
            			{
            			hue_gang_brightness.sendCommand(dimto)	//hæv lysstyrken	
                		timer.reschedule(now.plusMillis(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                         	return;
            				}
        			])
    			}
     			
     			
     	}

case "4002": 		//Tryk ØV
	{
    if (hue_gang_brightness.state == 0) 
    			{
    			hue_gang_brightness.sendCommand(state_ov)	//Tænd ganglys
    			}
    				else
    					{
						hue_gang_brightness.sendCommand(0)	//Sluk ganglys
						} 
	}
     	     			
case "4003":		// Langt tryk slip ØV
{     			
		state_ov = hue_gang_brightness.state
		if (dimmer_ov == 1)
		{	
		dimmer_ov = 0

		}
	else
		{
		dimmer_ov = 1
		}
}	

case "5001":		//langt tryk ØH 
 
     {
     	dimto = CT60x60Panel_Brightness.state
 		
     	if (dimmer_oh == 1)
     		{
     			timer = createTimer(now.plusSeconds(0),//Starts immediately 
     				[ |   
            		dimto = dimto + Uplevel
            		if (dimto <=100 && IkeaTrDfriRemote_Button.state == 5001)
            			{
            			CT60x60Panel_Brightness.sendCommand(dimto)	//hæv lysstyrken	
                		timer.reschedule(now.plusMillis(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                            return;
            				}
        			])
    			}
     	 if (dimmer_oh == 0)
     			{
     			timer = createTimer(now.plusSeconds(0),//Starts immediately 
     				[ |   
            		dimto = dimto + Downlevel
            		if (dimto >=10 && IkeaTrDfriRemote_Button.state == 5001)
            			{
            			CT60x60Panel_Brightness.sendCommand(dimto)	//hæv lysstyrken	
                		timer.reschedule(now.plusMillis(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                         	return;
            				}
        			])
    			}
     			
     			
     	}

case "5002": 		//Tryk ØH
	{
    if (CT60x60Panel_Brightness.state == 0) 
    			{
    			CT60x60Panel_Brightness.sendCommand(state_oh)	//Tænd 60x60 ganglys
    			}
    				else
    					{
						CT60x60Panel_Brightness.sendCommand(0)	//Sluk 60x60 ganglys
						} 
	}
	
case "5003":		// Langt tryk slip ØH
{     			
		state_oh = CT60x60Panel_Brightness.state
		if (dimmer_oh == 1)
		{	
		dimmer_oh = 0	
		}
	else
		{
		dimmer_oh = 1
		}
}	
		
}	
end
3 Likes

HI there,

old post but I will try to “capture” it :wink:

I have the deCONZ stick as well and everything is working fine. At the moment the “logic” is in the deCONZ web app - dimmers etc.

From your experience is it better to switch the sensor and switch handling to openhab as a rule or to leave it in the deCONZ app?

I guess you have more controll in openhab but I am unsure at the moment.

Any hints would be be greatly appreciated

Thanks for your code snippet @zamzon I have a slightly different Tradfri Remote Control. And for Dimming I’m using up and down buttons. To make it work with OH3 I needed to change it a bit. E.g. plusMillis() not working anymore.


var Number dimmerSchlafenStep = 5		
var Number dimmerSchlafenSollwert
var Timer timer = null
val int fade = 250*1000*1000 // How fast new dimming value is sent [nano seconds]

rule "Schlafzimmer LED Stripe Tradfri Rule"
when
//EG_Tradfri_Remote2
   Channel "deconz:switch:00212E065747:5c0272fffe981d8e011000:buttonevent" triggered
then
        var HSBType currentState = EG_Schlafen_RGBW_Streifen_Color.state as HSBType
        // var DecimalType new_H = currentState.hue + 6
        // var PercentType new_S = currentState.saturation + 5
        var PercentType EG_Schlafen_RGBW_Streifen_Color_Brightness = currentState.brightness
    switch(receivedEvent) {

        //ON (I) -> Spiegelbeleuchtung An/Aus
        case "1002": {
            if (EG_Schlafen_Steckd1.state == ON){
                sendCommand(EG_Schlafen_Steckd1, OFF);
            } else {
                sendCommand(EG_Schlafen_Steckd1, ON);
            }
        }
        //OFF (O) -> Led Streifen An/Aus
        case "2002": {
            if (EG_Schlafen_RGBW_Streifen_Color_Brightness == 0){
                sendCommand(EG_Schlafen_RGBW_Streifen_Color, ON);
            } else {
                sendCommand(EG_Schlafen_RGBW_Streifen_Color, OFF);
            }
        }
        //DIMMING UP Press
        case "1001": {
     	    dimmerSchlafenSollwert = EG_Schlafen_RGBW_Streifen_LedW.state	
     		{
     			timer = createTimer(now().plusSeconds(0),//starts immediately 
     				[ |   
            		dimmerSchlafenSollwert = dimmerSchlafenSollwert + dimmerSchlafenStep
            		if (dimmerSchlafenSollwert <=100 && dimmerSchlafenSollwert >= 0 && EG_Schlafen_Tradfri_Remote2_Button.state == 1001)
            			{
            			EG_Schlafen_RGBW_Streifen_LedW.sendCommand(dimmerSchlafenSollwert)	//set stripe to new dimming value	
                		timer.reschedule(now().plusNanos(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                            return;
            				}
        			])
    			}
        }
        //DIMMING UP Release
        case "1003": {
        }
        //DIMMING DOWN Press
        case "2001": {
     	    dimmerSchlafenSollwert = EG_Schlafen_RGBW_Streifen_LedW.state	
     		{
     			timer = createTimer(now().plusSeconds(0),//starts immediately 
     				[ |   
            		dimmerSchlafenSollwert = dimmerSchlafenSollwert - dimmerSchlafenStep
            		if (dimmerSchlafenSollwert <=100 && dimmerSchlafenSollwert >= 0 && EG_Schlafen_Tradfri_Remote2_Button.state == 2001)
            			{
            			EG_Schlafen_RGBW_Streifen_LedW.sendCommand(dimmerSchlafenSollwert)	//set stripe to new dimming value	
                		timer.reschedule(now().plusNanos(fade)) // reschedule fader
            			} 				
            				else
            				{
                         	timer = null // cancel timer
                            return;
            				}
        			])
    			}
        }
        //DIMMING DOWN Press
        case "2003": {
        }
1 Like