diff --git a/function/__init__.py b/function/__init__.py
index 4fcba43..6ce1a72 100644
--- a/function/__init__.py
+++ b/function/__init__.py
@@ -7,7 +7,6 @@ from function.first_floor_west import first_floor_west_julian, first_floor_west_
 from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep_madi, first_floor_east_living
 import inspect
 
-# TODO: implement bed light dirk fading by input device
 # TODO: implement heating function sleep_madi
 # TODO: implement circulation pump
 # TODO: implement switch off functionality (except of switch off button transportation)
@@ -56,7 +55,7 @@ class all_functions(object):
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "arrow_right_click",
                                                    self.ffe_floor.toggle_main_light)
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, None,
-                                                   self.ffe_sleep_madi.fade_bed_light)
+                                                   self.ffe_sleep_madi.fade_light)
 
     def devicelist(self):
         if self.__devices__ is None:
diff --git a/function/first_floor_east.py b/function/first_floor_east.py
index b41716b..80c5ad1 100644
--- a/function/first_floor_east.py
+++ b/function/first_floor_east.py
@@ -87,21 +87,44 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
         self.gui_brightness_bed_light_di.add_callback(
             devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
+        #
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
+                                               None, self.state_machine_last_activated_device)
+        #
+        self.last_activated_device = None
 
     def toggle_main_light(self, device, key, data):
         logger.info("Toggeling \"%s\" main light", type(self).__name__)
         self.main_light_shelly.set_output_0("toggle")
 
-    def fade_bed_light(self, device, topic, data):
+    def state_machine_last_activated_device(self, device, topic, data):
+        if data is True:
+            self.last_activated_device = device.topic
+        elif data is False:
+            if device.topic == self.main_light_shelly.topic and self.bed_light_di_tradfri.output_0:
+                self.last_activated_device = self.bed_light_di_tradfri.topic
+            elif device.topic == self.bed_light_di_tradfri.topic and self.main_light_shelly.output_0:
+                self.last_activated_device = self.main_light_shelly.topic
+            else:
+                self.last_activated_device = None
+
+    def fade_light(self, device, topic, data):
+        if self.last_activated_device == self.main_light_shelly.topic:
+            target = self.main_light_tradfri
+        elif self.last_activated_device == self.bed_light_di_tradfri.topic:
+            target = self.bed_light_di_tradfri
+        else:
+            return
         if (data == 'brightness_up_hold'):
-            logger.info("Increasing brightness \"%s\" bed light dirk", type(self).__name__)
-            self.bed_light_di_tradfri.brightness_inc()
+            logger.info("Increasing brightness \"%s\" %s", type(self).__name__, target.topic)
+            target.brightness_inc()
         elif (data == 'brightness_down_hold'):
-            logger.info("Decreasing brightness \"%s\" bed light dirk", type(self).__name__)
-            self.bed_light_di_tradfri.brightness_dec()
+            logger.info("Decreasing brightness \"%s\" %s", type(self).__name__, target.topic)
+            target.brightness_dec()
         elif (data.startswith('brightness') and data.endswith('release')):
-            logger.info("Stoping brightness change \"%s\" bed light dirk", type(self).__name__)
-            self.bed_light_di_tradfri.brightness_stop()
+            logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
+            target.brightness_stop()
 
     def gui_switch_command_bed_light_di(self, device, key, data):
         logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))