Dimming Zigbee lights with a KNX switch

Hi there,

I want to use KNX wall switches to control Zigbee lights. Burningstone helped me in this thread to adapt his dimming app, but somehow it didn’t work.

Never said thanks by the way, so thanks a lot Burningstone!

Since then I have been learning a bit of Python and took the code that he gave me to create my own app. This is working now, but the dimming up is behaving in a strange way. The problem is that it increases the light brightness in steps of about 6% and then stops. Everything else is working as expected, what is happening?

Here is my code:

from appdaemon.plugins.hass.hassapi import Hass

class KNXSwitchTest(Hass):
    
    def initialize(self) -> None:
        self.listen_event(self.action,"knx_event")

                # configure entities
        entities = self.args["entities"]
        self.light = entities["light"]
        self.on_off = entities["on_off"]
        self.dimm = entities["dimm"]
        # self.on = 1

    def action(self, event_name: str, data: dict, kwargs: dict) -> None:
        # self.log(event_name)
        # self.log(data)

        # ON/OFF
        if data ["address"] == self.on_off:

            if data ["data"] == 1:

                #self.log("ON")
                self.turn_on(self.light)

            else:
                #self.log("OFF")
                self.turn_off(self.light)

        # DIMM
        if data ["address"] == self.dimm:

            # DIMM HI
            if data ["data"] == 9:

                self.log("DIMM HI")
                self.log(data)
                self.call_service(
                    "deconz/configure",
                    field = "/action", 
                    entity = self.light, 
                    data={"bri_inc": 254, "transitiontime": 25}
                    )


            # DIMM LOW
            if data ["data"] == 1:

                self.log("DIMM LOW")
                self.log(data)
                self.call_service(
                    "deconz/configure",
                    field = "/action",
                    entity=self.light,
                    data={"bri_inc": -254, "transitiontime": 25}
                    )

            # DIMM STOP
            else:
                self.log("DIMM Stop")
                self.log(data)
                self.call_service(
                    "deconz/configure",
                    field = "/action",
                    entity=self.light,
                    data={"bri_inc": 0}
                    )

Thanks for your help.

Edit:

Looking at the logs, I noticed that the dimming up action is being called two times after pressing the button. Looks like this:

2020-12-12 18:56:39.993149 INFO Licht_TEST: {'address': '5/2/20', 'data': 0}
2020-12-12 18:56:39.991752 INFO Licht_TEST: DIMM Stop
2020-12-12 18:56:36.793134 INFO Licht_TEST: {'address': '5/2/20', 'data': 9}
2020-12-12 18:56:36.790225 INFO Licht_TEST: DIMM Stop
2020-12-12 18:56:36.684740 INFO Licht_TEST: {'address': '5/2/20', 'data': 9}
2020-12-12 18:56:36.683240 INFO Licht_TEST: DIMM HI
2020-12-12 18:56:23.080390 INFO AppDaemon: New client Admin Client connected

Changed the Dimming Stop action to:

            # DIMM STOP
            if data ["data"] == 0:
                self.log("DIMM Stop")
                self.log(data)
                self.call_service(
                    "deconz/configure",
                    field = "/action",
                    entity=self.light,
                    data={"bri_inc": 0}
                    )

Is working nicely now!

1 Like