Hello,
I want to add a IKEA Tradfri RGB Bulb (LED2109G6) and a IKEA Switch (LED2109G6) via Zigbee2Mqtt by Text to my OH Installation.
Has anybody examples of the .things , .items , transformation and maybe also some .rule files allready working?
Thanks in advance,
Ingo
Because there was no answer, I tried myself. Maybe it is of interesst for anybody:
copied from the net to put in the “transform” folder:
setTradfriCTstartup.js
(function(x){
var color_temp_stratup = (x * 350) + 150; // 0-100 = 250-454
//var color_temp = (500 - (x * 350)); // 0-100 = 500-100
if(color_temp_stratup > 500) color_temp_stratup = 454
if(color_temp_stratup < 250) color_temp_stratup = 250
var result = new Object();
result.color_temp_startup = color_temp_startup;
return JSON.stringify(result);
})(input)
setZigbeeBrightness.js
(function(x){
var brightness = (x/100)*255;
if(brightness > 255) brightness = 255
if(brightness < 0) brightness = 0
var result = new Object();
result.brightness = brightness;
return JSON.stringify(result);
})(input)
setTradfriCT.js
(function(x){
var color_temp = (x * 2.04) + 250; // 0-100 = 250-454
//var color_temp = (500 - (x * 350)); // 0-100 = 500-100
if(color_temp > 454) color_temp = 454
if(color_temp < 250) color_temp = 250
var result = new Object();
result.color_temp = color_temp;
return JSON.stringify(result);
})(input)
setZigbeeEffect.js
(function(x){
var effectid = x;
var result = new Object();
result.effect = effectid;
return JSON.stringify(result);
})(input)
in the .things file:
// IKEA Tradfri
// IKEA Bulb 01 RGB
Type switch : IKEA_Bulb_01_switch "Ikea_Bulb_01 State" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set", on="ON", off="OFF"]
Type dimmer : IKEA_Bulb_01_brightness "Ikea_Bulb_01 Brightness" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set",transformationPatternOut="JS:setZigbeeBrightness.js"]
Type string : IKEA_Bulb_01_brightnessMove "Ikea_Bulb_01 Brightness Move" [commandTopic="zigbee2mqtt/IKEA_Bulb_01/set/brightness_move"]
Type dimmer : IKEA_Bulb_01_color_temp "Ikea_Bulb_01 Color_Temp" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.color_temp", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set",transformationPatternOut="JS:setTradfriCT.js"]
// Type dimmer : IKEA_Bulb_01_color_temp "Ikea_Bulb_01 Color_Temp" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.color_temp", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set",transformationPatternOut="JS:setZigbeeCT.js"]
Type dimmer : IKEA_Bulb_01_color_temp_start "Ikea_Bulb_01 Color_Temp_start" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.color_temp_startup", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set",transformationPatternOut="JS:setTradfriCTstartup.js"]
Type colorHSB : IKEA_Bulb_01_color "Ikea_Bulb_01 Color" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", commandTopic="zigbee2mqtt/IKEA_Bulb_01/set",transformationPatternOut="JS:HSBtoRGB.js"]
Type number : IKEA_Bulb_01_Link "Ikea_Bulb_01 Link" [stateTopic="zigbee2mqtt/IKEA_Bulb_01", transformationPattern="JSONPATH:$.linkquality"]
// IKEA Switch 01 mobiler Schalter
Type string : IKEA_Switch_01_Action "Ikea Switch 01 Action" [stateTopic="zigbee2mqtt/IKEA_Switch_01", transformationPattern="JSONPATH:$.action"]
Type number : IKEA_Switch_01_Action_Duration "Ikea Switch 01 Action Duration" [stateTopic="zigbee2mqtt/IKEA_Switch_01", transformationPattern="JSONPATH:$.action_duration"]
Type number : IKEA_Switch_01_Battery "Ikea Switch 01 Battery" [stateTopic="zigbee2mqtt/IKEA_Switch_01", transformationPattern="JSONPATH:$.battery"]
Type number : IKEA_Switch_01_Link "Ikea Switch 01 Link" [stateTopic="zigbee2mqtt/IKEA_Switch_01", transformationPattern="JSONPATH:$.linkquality"]
.items
// IKEA Bulb 01 (RGB)
Switch IKEA_Bulb_01_Switch "Ikea Bulb 01: [%s]" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_switch"}
Dimmer IKEA_Bulb_01_Brightness "IKEA Bulb 01: Helligkeit [%.0f]" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_brightness"}
String IKEA_Bulb_01_BrightnessMove "IKEA Bulb 01: Helligkeit Move" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_brightnessMove"}
Number IKEA_Bulb_01_Bright
Number IKEA_Bulb_01_Link "IKEA Bulb 01: Linkquality [%s]" <qualityofservice> (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_Link"}
DateTime IKEA_Bulb_01_lastseen "IKEA Bulb 01: zuletzt gesehen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <time> (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_Link" [profile="timestamp-update"]}
Color IKEA_Bulb_01_Color "IKEA Bulb 01: Farbe" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_color"}
Dimmer IKEA_Bulb_01_Temp "IKEA Bulb 01: FarbTemperatur" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_color_temp"}
Dimmer IKEA_Bulb_01_Temp_Start "IKEA Bulb 01: FarbTemperatur Start" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_color_temp_start"}
// IKEA Switch 01
Number IKEA_Switch_01_Link "IKEA Switch 01: Linkquality [%s]" <qualityofservice> (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Switch_01_Link"}
String IKEA_Switch_01_Action "IKEA Switch 01: Action" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Switch_01_Action"}
Number IKEA_Switch_01_Action_Duration "IKEA Switch 01: Action Duration [%.5f]" (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Switch_01_Action_Duration"}
Number IKEA_Switch_01_Battery "IKEA Switch 01: Battery [%s]" <battery> (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Switch_01_Battery"}
DateTime IKEA_Switch_01_lastseen "IKEA Switch 01: zuletzt gesehen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <time> (IKEA_Bulbs) {channel="mqtt:topic:RaspiMosquitto:ZigBee2MQTT:IKEA_Bulb_01_Link" [profile="timestamp-update"]}
.rules
rule "Ikea Switch 01"
when
Item IKEA_Switch_01_Action received update
then
logInfo("Ikea Switch", "Action: " + IKEA_Switch_01_Action.state)
if (IKEA_Switch_01_Action.state == "on") { // Licht an
sendCommand(IKEA_Bulb_01_Switch,ON)
}
if (IKEA_Switch_01_Action.state == "off") { // Licht aus
sendCommand(IKEA_Bulb_01_Switch,OFF)
}
if (IKEA_Switch_01_Action.state == "brightness_move_down") { // Licht dunkler
sendCommand(IKEA_Bulb_01_BrightnessMove, "-40")
}
if (IKEA_Switch_01_Action.state == "brightness_move_up") { // Licht heller
sendCommand(IKEA_Bulb_01_BrightnessMove, "40")
}
if (IKEA_Switch_01_Action.state == "brightness_stop") { // Licht stop dimming
sendCommand(IKEA_Bulb_01_BrightnessMove, "0")
logInfo("Ikea Switch", "Action: " + IKEA_Switch_01_Action.state)
}
if (IKEA_Switch_01_Action.state == "arrow_left_click") { // Licht stop dimming
logInfo("Ikea Switch", "Action: " + IKEA_Switch_01_Action.state)
var ColorTemp = (IKEA_Bulb_01_Temp.state as Number) - 10
if (ColorTemp < 1) ColorTemp = 0
sendCommand(IKEA_Bulb_01_Temp,ColorTemp)
}
if (IKEA_Switch_01_Action.state == "arrow_right_click") { // Licht stop dimming
logInfo("Ikea Switch", "Action: " + IKEA_Switch_01_Action.state)
var ColorTemp = (IKEA_Bulb_01_Temp.state as Number) + 10
if (ColorTemp > 100) ColorTemp = 100
sendCommand(IKEA_Bulb_01_Temp,ColorTemp)
}
end
Maybe it helps…
1 Like