IKEA Trådfri - OH to link 3 groups together

Hi.

While I am not new to OH I am new to OH2.
It has been a long time since I fiddled with this but now I have a need for OH2 for the following setup:

I have 6 spots of the IKEA Trådfri smartlight system.
I have 3 remotes and 1 Gateway.

All 6 spots are to used in the the hallway and I needs to link the three remotes to all 6 spots. Knowing that I cannot do that I will make groups of two spots for each remote and intends to use OH to control the other two groups.

1: Is this possible? Can OH2 catch both color, dimm and ON/OFF commands?
2: I will need to build rules for this. Is there a simple way to do it? Can I catch a state on any of the bulbs and update the other bulbs by simply passing the state to all bulbs in the groups except the 1(2 - the second in same Group will get the same state due to being in the same group) which is set by the remote?

I have not yet played around with the bulbs but I read somewhere that only on/off events from the remotes are advertised by the IKEA GW why the rules should trigger on state changes on the bulbs instead of commands/events from the remotes.
It would have been better and more solid to react on the remote events and then have OH control the bulbs in one big group.

Hi kerasit,

have a look at the documentation. Depending on which bulbs you own, you can control brightness and color temperature with the Tradfri binding using a Dimmer item. The brightness channel can be used for switching the bulbs ON or OFF using a Switch item. No rule is necessary. You are able to control each bulb on its own or together in one or more user defined groups.

It is not possible to catch and react to events of the Tradfri remotes. The gateway doesn’t send events if a remote is used. We currently suppose the remotes to sends their signals directly to the bulbs.

Hi Chrisroph.

Thank you for your reply.

I have three remotes which needs to be used. Cant I catch the State of the first two bulbs being set through the gw not the remote commands?

A: I press the “up” button on first remote.

B: the bulbs reacts and dimmers up.

C: the GW advertices the new state of the bulbs and OH Can now react om this event.

D: OH rule reads the new State of bulb one and two and sends the same state as command to bulb 3,4,5 and 6.

Is this not possible then?

That is possible (assuming that all Trådfri bulbs are member of the group gTradfri):

rule "Tradfri"
when 
	Item tradfri_bulb1_brightness changed 
then
	Thread::sleep(600)
	sendCommand(gTradfri, tradfri_bulb1_brightness.state)
end
1 Like

Yes, of course. That is possible. You will need a rule which watches the brightness channel of one bulb in the first group. This rule should updates all other bulbs. An example

demo.items

Group:Dimmer First
Group:Dimmer Second

Dimmer Light1 (First) { channel="tradfri:0100:mygateway:<BULBID1>:brightness" }
Dimmer Light2 (First) { channel="tradfri:0100:mygateway:<BULBID2>:brightness" }
Dimmer Light3 (Second) { channel="tradfri:0100:mygateway:<BULBID3>:brightness" }
Dimmer Light4 (Second) { channel="tradfri:0100:mygateway:<BULBID4>:brightness" }

demo.rules

rule "Update bulbs"
when
    Item Light1 changes
then
    sendCommand(Light3, Light1.state)
    sendCommand(Light4, Light1.state)
end

Please be aware that this examples may contain errors or typos, I wrote it down untested.

//EDIT: changed syntax of demo groups and items

1 Like

Thank you both.

So I have created the following:

traadfri.tiems

Group:Dimmer First_Bright
Group:Dimmer Second_Bright
Group:Dimmer Third_Bright
Group:Dimmer First_Color
Group:Dimmer Second_Color
Group:Dimmer Third_Color

Dimmer Light1_Bright <First_Bright> { channel=“tradfri:0100:mygateway:Bulb11:brightness” }
Dimmer Light2_Bright <First_Bright> { channel=“tradfri:0100:mygateway:Bulb22:brightness” }
Dimmer Light3_Bright <Second_Bright> { channel=“tradfri:0100:mygateway:Bulb33:brightness” }
Dimmer Light4_Bright <Second_Bright> { channel=“tradfri:0100:mygateway:Bulb44:brightness” }
Dimmer Light5_Bright <Third_Bright> { channel=“tradfri:0100:mygateway:Bulb55:brightness” }
Dimmer Light6_Bright <Third_Bright> { channel=“tradfri:0100:mygateway:Bulb66:brightness” }

Dimmer Light1_Color <First_Color> { channel=“tradfri:0220:mygateway:Bulb1:color_temperature” }
Dimmer Light2_Color <First_Color> { channel=“tradfri:0220:mygateway:Bulb2:color_temperature” }
Dimmer Light3_Color <Second_Color> { channel=“tradfri:0220:mygateway:Bulb3:color_temperature” }
Dimmer Light4_Color <Second_Color> { channel=“tradfri:0220:mygateway:Bulb4:color_temperature” }
Dimmer Light5_Color <Third_Color> { channel=“tradfri:0220:mygateway:Bulb5:color_temperature” }
Dimmer Light6_Color <Third_Color> { channel=“tradfri:0220:mygateway:Bulb6:color_temperature” }

default.rules

//Brightness

rule “Update Second and Third bulb brightness”
when
Item Light1_Bright changed
then
sendCommand(Second_Bright, Light1_Bright.state)
sendCommand(Third_Bright, Light1_Bright.state)
end

rule “Update Third and First bulb brightness”
when
Item Light3_Bright changed
then
sendCommand(First_Bright, Light3_Bright.state)
sendCommand(Third_Bright, Light3_Bright.state)
end

rule “Update First and second bulb brightness”
when
Item Light5_Bright changed
then
sendCommand(First_Bright, Light5_Bright.state)
sendCommand(Second_Bright, Light5_Bright.state)
end

//Colour
rule “Update Second and Third bulb Colour”
when
Item Light1_Color changed
then
sendCommand(Second_Color, Light1_Color.state)
sendCommand(Third_Color, Light1_Color.state)
end

rule “Update Third and First bulb Colour”
when
Item Light3_Color changed
then
sendCommand(First_Color, Light3_Color.state)
sendCommand(Third_Color, Light3_Color.state)
end

rule “Update First and second bulb Colour”
when
Item Light5_Color changed
then
sendCommand(First_Color, Light5_Color.state)
sendCommand(Second_Color, Light5_Color.state)
end

The above rules has an error:
“Cannot convert form state to String”. But that is the whole point right?

Is it correct that in order to control both brightness and color I needs to create it as two seperate items per each bulb? One for each channel?

Regarding your .items file: You haven’t assigned the different lights to groups. The correct syntax is:

Group:Dimmer First_Bright
...
Dimmer Light1_Bright (First_Bright) { channel=“tradfri:0100:mygateway:Bulb11:brightness” }
Dimmer Light2_Bright (First_Bright) { channel=“tradfri:0100:mygateway:Bulb22:brightness” }
...

The <> are used to assign the item Light1_Bright the icon First_Bright.
Thus the group config isn’t correct, the rules aren’t able to work.

Yes, it is correct, that you have to create two separate items for brightness and color.

1 Like

I changed the syntax if my examples above.

You can try to append a .toString after the state in each sendCommand line in the rules.

1 Like

That seemed to do the trick. Thank you both.

So I will also need to make two things for each bulb in the .things file, right?

Glad to hear. You are welcome.

No, it’s one thing with two channels (which are linked to items).
Have a look at the documentation.

Ok. My solution now looks like this:

.things

Bridge tradfri:gateway:mygateway [ host="xxx.xxx.xxx.xxx", code="MyCode" ] {   
    0220 Bulb1 [ id=65537 ]
    0220 Bulb2 [ id=65538 ]
    0220 Bulb3 [ id=65539 ] 
    0220 Bulb4 [ id=65540 ] 
    0220 Bulb5 [ id=65541 ] 
    0220 Bulb6 [ id=65542 ]    
}

.items:

Group:Dimmer First_Bright
Group:Dimmer Second_Bright
Group:Dimmer Third_Bright
Group:Dimmer First_Color
Group:Dimmer Second_Color
Group:Dimmer Third_Color

Dimmer Light1_Bright (First_Bright) { channel="tradfri:0100:mygateway:Bulb1:brightness" }
Dimmer Light2_Bright (First_Bright) { channel="tradfri:0100:mygateway:Bulb2:brightness" }
Dimmer Light3_Bright (Second_Bright) { channel="tradfri:0100:mygateway:Bulb3:brightness" }
Dimmer Light4_Bright (Second_Bright) { channel="tradfri:0100:mygateway:Bulb4:brightness" }
Dimmer Light5_Bright (Third_Bright) { channel="tradfri:0100:mygateway:Bulb5:brightness" }
Dimmer Light6_Bright (Third_Bright) { channel="tradfri:0100:mygateway:Bulb6:brightness" }
Dimmer Light1_Color (First_Color) { channel="tradfri:0220:mygateway:Bulb1:color_temperature" }
Dimmer Light2_Color (First_Color) { channel="tradfri:0220:mygateway:Bulb2:color_temperature" }
Dimmer Light3_Color (Second_Color) { channel="tradfri:0220:mygateway:Bulb3:color_temperature" }
Dimmer Light4_Color (Second_Color) { channel="tradfri:0220:mygateway:Bulb4:color_temperature" }
Dimmer Light5_Color (Third_Color) { channel="tradfri:0220:mygateway:Bulb5:color_temperature" }
Dimmer Light6_Color (Third_Color) { channel="tradfri:0220:mygateway:Bulb6:color_temperature" }

Notice that it is now pointing on the same thing for each channel.

.rules

//Brightness

rule "Update Second and Third bulb brightness"
when
    Item Light1_Bright changed
then 
    sendCommand(Second_Bright, Light1_Bright.state.toString)
    sendCommand(Third_Bright, Light1_Bright.state.toString)
end

rule "Update Third and First bulb brightness"
when
    Item Light3_Bright changed
then
    sendCommand(First_Bright, Light3_Bright.state.toString)
    sendCommand(Third_Bright, Light3_Bright.state.toString)
end

rule "Update First and second bulb brightness"
when
    Item Light5_Bright changed
then
    sendCommand(First_Bright, Light5_Bright.state.toString)
    sendCommand(Second_Bright, Light5_Bright.state.toString)
end

//Colour
rule "Update Second and Third bulb Colour"
when
    Item Light1_Color changed
then 
    sendCommand(Second_Color, Light1_Color.state.toString)
    sendCommand(Third_Color, Light1_Color.state.toString)
end

rule "Update Third and First bulb Colour"
when
    Item Light3_Color changed
then
    sendCommand(First_Color, Light3_Color.state.toString)
    sendCommand(Third_Color, Light3_Color.state.toString)
end

rule "Update First and second bulb Colour"
when
    Item Light5_Color changed
then
    sendCommand(First_Color, Light5_Color.state.toString)
    sendCommand(Second_Color, Light5_Color.state.toString)
end

You have to change the brightness item definition to

Dimmer Light1_Bright (First_Bright) { channel="tradfri:0220:mygateway:Bulb1:brightness" }
...

Because you declared your things as 0220 devices. 0220 is the thing type for a Colour Temperature Light and 0100 for a Dimmable Light (where you can’t change color temperature) of the Trådfri series.

I don’t think toString is necessary (I tested my example), but if it works…

1 Like

Thx to Christoph and cweitkamp the following is a working example of how to zone bulbs and multiple remotes to work as one shared zone (6 IKEA Trådfri spots with three different remotes in this setup).

Additionally I am experimenting with the remotes ON/OFF (IKEA trådfri groups) for avoiding switching on full power and wake our daughter.

.things

Bridge tradfri:gateway:mygateway [ host="xxx.xxx.xxx.xxx", code="MyCode" ] {   
    0220 Bulb1 [ id=65537 ]
    0220 Bulb2 [ id=65538 ]
    0220 Bulb3 [ id=65539 ] 
    0220 Bulb4 [ id=65540 ] 
    0220 Bulb5 [ id=65541 ] 
    0220 Bulb6 [ id=65542 ]
    group tradfri_group_Hall1 [ id=140891 ]
    group tradfri_group_Hall2 [ id=140892 ]
    group tradfri_group_Hall3 [ id=140893 ]  
}

.items

Group:Dimmer All_Bright
Group:Dimmer All_Color

Group:Dimmer FirstSecond_Bright (All_Bright)
Group:Dimmer FirstThird_Bright (All_Bright)
Group:Dimmer SecondThird_Bright (All_Bright)
Group:Dimmer FirstSecond_Color (All_Color)
Group:Dimmer FirstThird_Color (All_Color)
Group:Dimmer SecondThird_Color (All_Color)

Group:Dimmer First_Bright (FirstSecond_Bright, FirstThird_Bright)
Group:Dimmer Second_Bright (FirstSecond_Bright, SecondThird_Bright)
Group:Dimmer Third_Bright (FirstThird_Bright, SecondThird_Bright)
Group:Dimmer First_Color (FirstSecond_Color, FirstThird_Color)
Group:Dimmer Second_Color (FirstSecond_Color, SecondThird_Color)
Group:Dimmer Third_Color (FirstThird_Color, SecondThird_Color)

Group:Switch:OR(ON,OFF) FirstSecond
Group:Switch:OR(ON,OFF) FirstThird
Group:Switch:OR(ON,OFF) SecondThird

Group:Switch:OR(ON,OFF) First (FirstSecond, FirstThird)
Group:Switch:OR(ON,OFF) Second (FirstSecond, SecondThird)
Group:Switch:OR(ON,OFF) Third (FirstThird, SecondThird)

Dimmer Light1_Bright (First_Bright) { channel="tradfri:0220:mygateway:Bulb1:brightness" }
Dimmer Light2_Bright (First_Bright) { channel="tradfri:0220:mygateway:Bulb2:brightness" }
Dimmer Light3_Bright (Second_Bright) { channel="tradfri:0220:mygateway:Bulb3:brightness" }
Dimmer Light4_Bright (Second_Bright) { channel="tradfri:0220:mygateway:Bulb4:brightness" }
Dimmer Light5_Bright (Third_Bright) { channel="tradfri:0220:mygateway:Bulb5:brightness" }
Dimmer Light6_Bright (Third_Bright) { channel="tradfri:0220:mygateway:Bulb6:brightness" }

Dimmer Light1_Color (First_Color) { channel="tradfri:0220:mygateway:Bulb1:color_temperature" }
Dimmer Light2_Color (First_Color) { channel="tradfri:0220:mygateway:Bulb2:color_temperature" }
Dimmer Light3_Color (Second_Color) { channel="tradfri:0220:mygateway:Bulb3:color_temperature" }
Dimmer Light4_Color (Second_Color) { channel="tradfri:0220:mygateway:Bulb4:color_temperature" }
Dimmer Light5_Color (Third_Color) { channel="tradfri:0220:mygateway:Bulb5:color_temperature" }
Dimmer Light6_Color (Third_Color) { channel="tradfri:0220:mygateway:Bulb6:color_temperature" }

Switch Ligth1 (First) { channel="tradfri:group:mygateway:tradfri_group_Hall1:group_state" }
Switch Ligth2 (Second) { channel="tradfri:group:mygateway:tradfri_group_Hall2:group_state" }
Switch Light3 (Third) { channel="tradfri:group:mygateway:tradfri_group_Hall3:group_state" }

.rules

//Brightness

rule "Update Second and Third bulb brightness"
when
    Item Light1_Bright changed
then 
    sendCommand(SecondThird_Bright, Light1_Bright.state.toString)
    //sendCommand(Third_Bright, Light1_Bright.state.toString)
end

rule "Update Third and First bulb brightness"
when
    Item Light3_Bright changed
then
	sendCommand(FirstThird_Bright, Light3_Bright.state.toString)
    //sendCommand(Third_Bright, Light3_Bright.state.toString)
end

rule "Update First and second bulb brightness"
when
    Item Light5_Bright changed
then
    sendCommand(FirstSecond_Bright, Light5_Bright.state.toString)
    //sendCommand(Second_Bright, Light5_Bright.state.toString)
end


//Colour
rule "Update Second and Third bulb Colour"
when
    Item Light1_Color changed
then 
    sendCommand(SecondThird_Color, Light1_Color.state.toString)
    //sendCommand(Third_Color, Light1_Color.state.toString)
end

rule "Update Third and First bulb Colour"
when
    Item Light3_Color changed
then
	sendCommand(FirstThird_Color, Light3_Color.state.toString)
    //sendCommand(Third_Color, Light3_Color.state.toString)
end

rule "Update First and second bulb Colour"
when
    Item Light5_Color changed
then
    sendCommand(FirstSecond_Color, Light5_Color.state.toString)
    //sendCommand(Second_Color, Light5_Color.state.toString)
end

//On / off
rule "Turn on / off all bulbs when Trådfri group 1 command"
when
	Item First received command
then
	val today = now
	val startOfDay = (today.millis - today.getMillisOfDay)
	val triggerTime = startOfDay + 79200000
	if(receivedCommand == ON && today.millis >= triggerTime) {
		All_Bright.sendCommand("50")
	}
	else {
		SecondThird.sendCommand(receivedCommand)
	}
	
end

rule "Turn on all bulbs when Trådfri group 2 command"
when
	Item Second received command
then
val today = now
	val startOfDay = (today.millis - today.getMillisOfDay)
	val triggerTime = startOfDay + 79200000
	if(receivedCommand == ON && today.millis >= triggerTime) {
		All_Bright.sendCommand("50")
	}
	else {
		FirstThird.sendCommand(receivedCommand)
	}
end

rule "Turn on all bulbs when Trådfri group 3 command"
when
	Item Third received command
then
val today = now
	val startOfDay = (today.millis - today.getMillisOfDay)
	val triggerTime = startOfDay + 79200000
	if(receivedCommand == ON && today.millis >= triggerTime) {	
		All_Bright.sendCommand("50")
	}
	else {
		FirstSecond.sendCommand(receivedCommand)
	}
end

Please be aware that I have no sitemap here because the scope of my own solution is not to control the devices (light bulbs) from a smartphone or other device but simply to enable the use of multiple remotes to control the same light bulbs.

Each remote is paired with two bulbs hence the first, second and third groups.

I expects that IKEA will release more features to the IKEA Trådfri Gateway in the future whereas one of them will be to zone or link several remotes and light sources together either by doing what this solution does through OH2 directly as a setup in the gateway or by using the gateway as virtual bulbs which the remotes binds to and then by configuration can do the trick without any delay thus tricking the remotes to believe they are controlling a device directly.

If I had a ZigBee dongle I would have used a ZigBee binding to try to do this very trick (act like a virtual device) and react to the remotes directly to have OH completely control the bulbs.
If someone can build a specialised ZigBee binding working like that it could completely remove the need of the gateway entirely.

EDIT: Updated with ON/OFF from remotes (group actions).