Hi,
I have a standard CCT LED controller connected via a Phoscon gateway.
Using the deconz binding I can without any issues control the LED via openHAB using the following 2 items:
Number Farbtemperatur_Kueche
"Farbtemperatur LED Küche"
{ channel="deconz:colortemperaturelight:phoscon-gw:Kuechenschrank:color_temperature" }
Dimmer Helligkeit_LED_Kueche
"Helligkeit LED Küche"
(gKuechenLED)
{ channel="deconz:colortemperaturelight:phoscon-gw:Kuechenschrank:brightness" }
The color temperature is stored and expected in Kelvin by the deconz binding
With the brightness channel I am also able to switch on/off the lights.
However, I want to control the LED only via homekit using the respective binding and now there are some problems. I was able to make it work somehow but I am not sure whether I am doing this correctly.
- Homekit expects color temperatures in Mired instead of Kelvin
- Homekit expects a dedicated “On/Off state” variable of
Switch
type to switch lights on/off (it does not acceptDimmer
types)
The items now look as follows:
Group gKuechenLED
"LED Küchenschrank"
{homekit="Lighting"}
Switch Kueche_LED_SyncTimer
{expire="5s,command=OFF"}
Number Farbtemperatur_Kueche_homekit
"Farbtemperatur LED Küche für Homekit"
(gKuechenLED)
{ homekit="Lighting.ColorTemperature" [minValue=147, maxValue=455] }
Number Farbtemperatur_Kueche
"Farbtemperatur LED Küche"
{ channel="deconz:colortemperaturelight:phoscon-gw:Kuechenschrank:color_temperature" }
Dimmer Helligkeit_LED_Kueche
"Helligkeit LED Küche"
(gKuechenLED)
{ channel="deconz:colortemperaturelight:phoscon-gw:Kuechenschrank:brightness",
homekit="Lighting.Brightness"
}
Switch Status_LED_Kueche
"Status LED Küche"
(gKuechenLED)
{ homekit="Lighting.OnState" }
I need a mechanism which switches off/on the LEDs based on the “OnState” variable.
Apparently I need to synchronize the dependent items but I have no idea how this is safely done.
What I am doing right now looks as follows. Could you please tell me whether this makes sense or is complete rubbish? I use a sync timer and some sleep commands to make sure that items only get updated when the referenced item was changed by the user. By this I want to avoid an infinite loop of items changing each other. Does this make sense?
rule "Lichter: Status LED Küche in Homekit aktualisieren"
when Item Helligkeit_LED_Kueche changed
then
logInfo("Lichter: Status LED Küche in Homekit aktualisieren", "Helligkeit_LED_Kueche changed to " + Helligkeit_LED_Kueche.state)
if(Kueche_LED_SyncTimer.state == ON)
return;
if ((Helligkeit_LED_Kueche.state as Number).intValue > 0) {
Status_LED_Kueche.sendCommand(ON)
} else {
Status_LED_Kueche.sendCommand(OFF)
}
Kueche_LED_SyncTimer.sendCommand(ON)
Thread::sleep(2000)
end
rule "Lichter: LED Küche in deconz einschalten"
when Item Status_LED_Kueche changed
then
logInfo("Lichter: LED Küche in deconz einschalten", "Status_LED_Kueche changed to " + Status_LED_Kueche.state)
if(Kueche_LED_SyncTimer.state == ON)
return;
if(Status_LED_Kueche.state == ON) {
Helligkeit_LED_Kueche.sendCommand(100)
} else {
Helligkeit_LED_Kueche.sendCommand(0)
}
Kueche_LED_SyncTimer.sendCommand(ON)
Thread::sleep(2000)
end