KNX-Switch to dim of zigbee light bulb

I want to dim my zigbee light bulb with a knx switch.

The connection openHAB / zigbee / knx works fine (with a lot of things). With a “switch configuration” of the light bulb, everything works fine. My problem is the configuration as a dimmer.

The light bulb is a zigbee device from ikea.

UID: zigbee:device:d541f83264:60b647fffe3f4937
label: Zigbee_Kueche_Unterschrank_30w
thingTypeUID: zigbee:device
configuration:
  zigbee_macaddress: 60B647FFFE3F4937
bridgeUID: zigbee:coordinator_ember:d541f83264
channels:
  - id: 60B647FFFE3F4937_1_dimmer
    channelTypeUID: zigbee:switch_level
    label: "DIMMABLE_LIGHT: Level Control"
    description: null
    configuration:
      zigbee_reporting_polling: 900

I have created the following knx-thing, too.

UID: knx:device:knx_zigbee_platzhalter
label: KNX für Zigbee-Verbindung
thingTypeUID: knx:device
configuration:
  pingInterval: 600
  readInterval: 0
  fetch: false
bridgeUID: knx:ip:knxGateway
channels:
  - id: knx_unterschrank_kueche_dimmer
    channelTypeUID: knx:dimmer-control
    label: KNX Unterschrank Kueche Dimmer
    description: null
    configuration:
      increaseDecrease: 1/3/30
      switch: 1/1/30+1/2/30

I have to items, one switch an one dimmer:

Thing an item are linked:

The knx part look like so:
image
image

The event in the knx bus:
image
image

…it is my first dimmer in knx :wink:

Any ideas?
Best regards,
Daniel

It’s looking like you are close to the finishing line :slight_smile:

  1. the knx push button. To control a dimmer you will need short and long press and the common way is to use a dimmer configuration. If you want to get a feedback (you should…) you will need three GA (as you have already done). Please be aware that there are two ways to do relative dimming (i.e. control the dimmer through push buttons) in knx, the one option is start-stop-dimming, this is, send a start telegram when long press is detected and a stop telegram when release from long press is detected. so two telegrams per dimming. the other option is to send cyclic telegrams as long as the long press is detected and stop sending the telegram when release is detected. You’ll have to configure this in the push button controller. If you want to use start-stop-dimming, you’ll have to configure this in the openHAB channel by setting the frequency parameter. openHAB then will create the INCREASE/DECREASE command repeatedly as long as the stop telegram was not received.
    Both options are valid, but you have to chose one of them and you have to configure both sides the same way (knx push button and openHAB knx dimmer channel).
  2. openHAB dimmer-control channel.
    openHAB will receive telegrams on all GA set in the channel, but it will only send the status to the first GA. As your label is “RM” for 1/2/30, I guess this is the feedback GA, so this has to be the first GA in the dimmer-control switch parameter, not the second.
  3. There are some dimmers which may understand INCREASE/DECREASE directly, but the most common way to control dimmers in openHAB nowadays is to use absolute dimming (i.e. send a percent value to the dimmer, not an INCREASE/DECREASE). So please check wether the zigbee dimmer can be controlled by INCREASE/DECREASE directly. If not, you will have to use a rule like this:
rule "relative dimming"
when
    Item knx_unterschrank_kueche_dimmer received command
then
    switch(receivedCommand) {
        case ON       : zigbee_unterschrank_kueche_dimmer.sendCommand(ON)
        case OFF      : zigbee_unterschrank_kueche_dimmer.sendCommand(OFF)
        case INCREASE : zigbee_unterschrank_kueche_dimmer.sendCommand((zigbee_unterschrank_kueche_dimmer.state as Number) + 5)
        case DECREASE : zigbee_unterschrank_kueche_dimmer.sendCommand((zigbee_unterschrank_kueche_dimmer.state as Number) - 5)
    }
end

This rule will use 20 steps from 0 to 100.

Thanks for your detailled answer!

My GAs are:
1/1/30 switch (“schalten”)
1/2/30 feedback (“RM” = Rückmeldung)
1/3/30 dimm

In the group monitor it look’s like this:
(switch on; 2x dimn down; switch off)
image

2):
In the application from the knx sensor “Gira Testsensor 3” i choosed “dimmen” for “Wippe 3”. Now the sensor differentiates between a short and a long press (“Zeit zwischen schalten und dimmen”). With it you can configure GAs for “Schalten” (switch) and “Dimmen” (dimm).

Where to put the feedback GA? “Schalten” (switch) or “Dimmen”?
(see screenshot above in my first posting)

i changed this like so

  - id: knx_unterschrank_kueche_dimmer
    channelTypeUID: knx:dimmer-control
    label: KNX Unterschrank Kueche Dimmer
    description: null
    configuration:
      increaseDecrease: 1/3/30
      switch: 1/2/30+1/1/30

The dimmer/thing uses percent values like this:

Item 'Zigbee_Kueche_Unterschrank_10w' changed from 96 to 54

I try to implement it with a rule. I have to figure out details:
“knx_unterschrank_kueche_dimmer” is a chanell of a thing (not an item). I have to find out the notation, i cannot choose the channel within the gui.

Best regards
Daniel

You’ll have to use two different Items for the knx and zigbee parts (if the dimmer doesn’t accept INCREASE/DECREASE commands).

lgtm :slight_smile:

Yepp, seems to be start-stop-dimming. So please add frequency: 300 for to enable openHAB to create INCREASE/DECREASE commands every 300 Milliseconds as long as the button is pressed.

I made further progress:

I created a rule wich handles INCREASE/DECREASE events. That is working fine:

var dimmValue;

if (event.itemCommand.toString() == 'INCREASE') {
  dimmValue = items.getItem('Zigbee_Kueche_Unterschrank_10w').numericState + 5;
  items.getItem('Zigbee_Kueche_Unterschrank_10w').sendCommand(dimmValue);
} else if (event.itemCommand.toString() == 'DECREASE') {
  dimmValue = items.getItem('Zigbee_Kueche_Unterschrank_10w').numericState - 5;
  items.getItem('Zigbee_Kueche_Unterschrank_10w').sendCommand(dimmValue);
}

(i used blockly)

There are 2 problems left:

  • it is very sluggish
  • the gira tastsensor (knx switch) does not show the rigth status; the feedback is missing

What is the right place for the feedback GA? “Schalten” (switch) or “Dimmen” in ETS?
image

I created an “knx item” for the gira tastsensor (knx switch). This is my configuration:

The Zigbee-Thing:

The KNX-Thing:

I tried it out only with a switch without dimming. This is working correctly, very fast and with correct feedback status.

Maybe the zigbee channel doesn’t send an ON/OFF state when it’s dimmed. You could add a
myknxitem.postUpdate(ON) whenever the
Zigbee_Kueche_Unterschrank_10w.state is not 0 and a myknxitem.postUpdate(OFF) when it’s 0.

That makes no difference, i see this in the log

Item 'KNX_fur_ZigbeeVerbindung_KNX_Unterschrank_Kueche_Dimmer' changed from 0 to 100

But the status led of gira tastsensor remains off.

I think it is a problem in knx: whith the same openHAB / zigbee configuration, but when tastsensor is configured as switch (not dimmer), everything works fine! (status led on tastsensor is correct, too. And everything works very fast.)

What is the right place for the feedback GA? “Schalten” (switch) or “Dimmen” in ETS?

The wall switch is rocker switch. Anyway, the only difference to a button is there are separate buttons for on/brighter and off/darker.
If setting the rocker as a switch, there is only one KO and this is a Bit. 0 is OFF, 1 is ON (per default). And if there is a LED this can be configured to be the same state as the KO itself.
If setting the button as a dimmer, there are two KO, one is switch (and control LED, 1-Bit) the other is relative dimming (4-Bit). So there is no real option to put the state to another KO.
Exception: Some knx buttons have discrete KO for the LED as an Option.
And keep in mind that sometimes you have to extra configure that a LED is used at all.

ok, that’s clear now! Sorry for the confusion and thanks for your patience! :see_no_evil:
I’m learning a lot theses days :smile:

To summarize the current status:

ETS/KNX:
The knx switch “Gira Tastsensor 3” is configured as dimmer. The status led uses the group adress of switching (“Funktion der Status LED = Statusanzeige (des Schaltobjekts)”)

Things and assigned Items

Zigbee-Bulb


There ist only one Zigbee-Channel, a “DIMMABLE LIGHT: Level Control”.
I assigned two openHAB-Items: One item with type “Switch” an another with type “Dimmer”.

KNX placeholder thing

channels:
  - id: knx_unterschrank_kueche_dimmer
    channelTypeUID: knx:dimmer-control
    label: KNX Unterschrank Kueche Dimmer
    description: null
    configuration:
      increaseDecrease: 1/3/30
      frequency: 300
      switch: 1/2/30+1/1/30

Here i assigned one Item, the Swich-Item!

So far (actually) no rules!

what works

  • switch on/off with knx sensor
  • switch on/off with openHAB-Items
  • dimming with openHAB-Items
  • status led knx sensor and openHAB-Items (both directions)
  • everything very fast without any delay

What is not working
Dimming with the knx sensor is not working. But the events are recieved!
When i press long “ON” at the knx sensor, i can see the following log events in openHAB:

2024-02-24 13:19:00.192 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'kueche_Unterschrank_Switch' received command INCREASE
2024-02-24 13:19:00.410 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 46 to 44
2024-02-24 13:19:01.409 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 44 to 41

When i press long “OFF” at the knx sensor:

2024-02-24 13:22:22.594 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'kueche_Unterschrank_Switch' received command DECREASE
2024-02-24 13:22:22.801 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 41 to 39
2024-02-24 13:22:23.800 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 39 to 36

The INCREASE event is ok, but the percent value decreases (46 → 41).

When i use the item dimmer in openhab, i’m observing a strange behavior, too. There are alway two events. But the at the end the state is correct. For example one “click” on the dimmer control in openHAB:

2024-02-24 13:28:20.991 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Zigbee_Kueche_Unterschrank_10w' received command 63
2024-02-24 13:28:21.107 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 36 to 63
2024-02-24 13:28:21.213 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 63 to 38
2024-02-24 13:28:22.214 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 38 to 63

Perhaps now the nex step is to reactivate my rule, i will see…

Do not link two Items to any channel, you don’t need to.
A Dimmer item can always also act as a Switch Item (i.e. you can send ON and OFF commands and you can get OnOffType in rules if you need to)
Instead, use two channels (i.e. zigbee:…:level and knx:…:dimmer-control), two Dimmer Items (i.e. one for zigbee, one for knx) and two rules.

Let’s say kitchenLightCupboard is the zigbee Dimmer Item and kitchenRocker1 is the knx dimmer-control channel.

Now you will need two rules to get full control:

rule "zigbee light"
when
    Item kitchenLightCupboard changed
then
    kitchenRocker1.postUpdate(kitchenLightCupboard.state)
end

rule "knx rocker"
when
    Item kitchenRocker1 received command
then
    var level = kitchenLightCupboard.state as Number
    switch(receivedCommand) {
        case ON       : kitchenLightCupboard.sendCommand(ON)
        case OFF      : kitchenLightCupboard.sendCommand(OFF)
        case INCREASE : kitchenLightCupboard.sendCommand(level + 5)
        case DECREASE : kitchenLightCupboard.sendCommand(level - 5)
    }
end

The first rule will always send the state to the rocker switch. Please take account to the fact, that, although it’s used to send to the knx bus, here we’re using .postUpdate() but NOT .sendCommand() (this is very special witrh knx)
The second rule will send all commands received from the rocker switch to the zigbee item and will also change INCREASE/DECREASE to absolute dimming commands. 5 is the step width, so 20 steps from 0 to 100. maybe change the step width and frequency slightly if 20 steps aren’t enough, but be careful, as the rule will be executed every frequency Milliseconds whenever you’re dimming.

Do not link two Items to any channel, you don’t need to.

ok, i see. I don’t realize this. My approach was to “connect” knx sensor with zigbee bulb with linking the same item twice (knx sensor and zigbee bulb). I thougt, i have only to overcome the problem with the wrong format (increase vs. percent value).

I know, that i can “switch” a light with the dimmer widget. Because of usability reasons, i want to have a switch widget, too. Is this ok?
image

I will implement the two rules for the link beween knx an zigbee. Let’s seen, when i have time…

Another problem seems to be the zigbee device or thing (don’t know, where the problem exaclty is). Wenn i send one value, the thing status is update everey time with 3 steps:

2024-02-26 12:51:58.164 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Zigbee_Kueche_Unterschrank_10w' received command 77
2024-02-26 12:51:58.272 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 100 to 77
2024-02-26 12:51:58.374 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 77 to 98
2024-02-26 12:51:59.373 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Zigbee_Kueche_Unterschrank_10w' changed from 98 to 77

Sure, you can use as many widgets with an item as you want :slight_smile:

Maybe zigbee tells not only when it’s reached the final value, but some steps between, too. Just a guess…

ok, sounds good. I was not sure, what you meant with “Do not link two Items to any channel, you don’t need to.”

Maybe, but an interesting step between: :rofl:

  1. 100 → 77
  2. 77 → 98
  3. 98 → 77

I try to implement the 2 rules now :wink:

Well, not at all… :slight_smile: chronological order:

  1. openHAB sends command to zigbee
  2. openHAB updates the state of the item (looking ahead and awaiting a distinct state after the command)
  3. zigbee sends a first state after starting to changed the dim level
  4. zigbee sends a final state after reaching the nominal value

to avoid the first “jump”, set Item metadata Autoupdate to false

Have i to use work directly the knx thing?

I tried this and it works:

var lightBulbItemState = items.getItem("Zigbee_Kueche_Unterschrank_10w").state;
var knxItem = items.getItem("KNX_fur_ZigbeeVerbindung_KNX_Unterschrank_Kueche_Switch");
if( lightBulbItemState == 0) {
  knxItem.postUpdate("OFF");
} else {
  knxItem.postUpdate("ON");
}

But the knxItem is an Item not a thing!

And it is a switch! When i postUpdate on the correspoding dimmer-Item the status is not updated!

It’s done now :upside_down_face:
Kudos an thanks to @Udo_Hartmann!

This thread is quite long, so here my summary:

  • create a thing and an item for the zigbee device
  • create a thing and an item for the knx dimmer / channel
  • do not link the knx item with the zigbee-thing!
  • create 2 rules, to connect the knx dimmer with the zigbee bulb

One rule recieves the commands of the knx-dimmer (item) an sends this to the zigbee item:

console.debug("Kueche Unterschrank Status aktualisieren.");

var itemCommand = event.itemCommand.toString();
var lightBulbItem = items.getItem("Zigbee_Kueche_Unterschrank_10w");
var level = lightBulbItem.numericState;
var dimStep = 5;

if(itemCommand == "INCREASE") {
  console.debug("dimmen HELLER " + level + " + " + dimStep);
  var newLevel = level + dimStep;
  if(newLevel > 100) {
    newLevel = 100;
  }
  if(level < 100) {
    lightBulbItem.sendCommand(newLevel);
  }
} else if(itemCommand == "DECREASE") {
  console.debug("dimmen DUNKLER " + level + " - " + dimStep);
  var newLevel = level - dimStep; 
  if(level > 10) {
    lightBulbItem.sendCommand(level - dimStep);  
  }  
} else if(itemCommand == "ON") {
  lightBulbItem.sendCommand("ON");
} else if(itemCommand == "OFF") {
  lightBulbItem.sendCommand("OFF");
}

The othe rule updates the knx dimmer (item), when the zigbee item changes. Here it is important, only to postUpdate and not to sendCommand:

console.info("Kueche Unterschrank - KNX-Sensor Status aktualisieren.")
var lightBulbItemState = items.getItem("Zigbee_Kueche_Unterschrank_10w").state;
var knxItem = items.getItem("KNX_fur_ZigbeeVerbindung_KNX_Unterschrank_Kueche_Switch");
if( lightBulbItemState == 0) {
  knxItem.postUpdate("OFF");
} else {
  knxItem.postUpdate("ON");
}

Dimming with step=5 is quite slow, perhaps i will change that to 10.

Best regards
Daniel :grinning:

1 Like