From 496b910340fc1f5d99f5dae718a5fda9a19c126b Mon Sep 17 00:00:00 2001 From: EPMatt Date: Mon, 6 Jan 2020 01:21:08 +0100 Subject: [PATCH 1/2] add support for ICTC-G-1 controller --- .../z2m_ikea_controller.py | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/apps/z2m_ikea_controller/z2m_ikea_controller.py b/apps/z2m_ikea_controller/z2m_ikea_controller.py index 9fa0e230..0df29722 100755 --- a/apps/z2m_ikea_controller/z2m_ikea_controller.py +++ b/apps/z2m_ikea_controller/z2m_ikea_controller.py @@ -50,11 +50,16 @@ def state(self, entity, attribute, old, new, kwargs): if new == "": return attribute, direction, action = self.process_state(new) + if((attribute, direction, action) == (None, None, None)): + return light_state = self.get_state(self.light) if action == "toggle": self.toggle(self.light) elif action == "on": self.turn_on(self.light) + elif action == "on_full": + self.turn_on( + self.light, brightness=attribute_minmax['brightness']['max']) elif action == "off": self.turn_off(self.light) elif action == "release": @@ -64,8 +69,6 @@ def state(self, entity, attribute, old, new, kwargs): return sign = sign_mapping[direction] value = self.get_attr_value(self.light, attribute) - max_ = attribute_minmax[attribute]["max"] - min_ = attribute_minmax[attribute]["min"] if action == "click": self.turn_on_light(attribute, value, sign, self.manual_steps) elif action == "hold": @@ -138,3 +141,41 @@ def process_state(self, state): return attribute, action, "hold" else: return attribute, None, "release" + + +class ICTCG1Controller(IkeaController): + def initialize(self): + super().initialize() + self.rotating = False + + # Different states reported from the controller: + # rotate_left, rotate_left_quick + # rotate_right, rotate_right_quick + # rotate_stop + def process_state(self, state): + attribute = "brightness" # only brightness + splitted = state.split("_") + # handle rotate_left_quick / rotate_right_quick + if len(splitted) == 3: + t, direction, action = splitted + if direction == "right" and action == "quick": + return None, None, "on_full" + elif direction == "left" and action == "quick": + return None, None, "off" + else: + # handle rotate_stop / rotate_left / rotate_right + t, direction = splitted + if direction == "stop": + if self.rotating == False: + # ignore duplicate rotate_stop messages + return None, None, None + self.rotating = False + return attribute, None, "release" + elif self.rotating == False: + direction_mapping = {"left": "down", "right": "up"} + direction = direction_mapping.get(direction, direction) + self.rotating = True + return attribute, direction, "hold" + else: + # ignore duplicate rotate_left / rotate_right messages + return None, None, None From 51ecdb0e9915d8e84c5312451ff0d2c5c5ef26bf Mon Sep 17 00:00:00 2001 From: EPMatt Date: Mon, 6 Jan 2020 01:53:39 +0100 Subject: [PATCH 2/2] add readme for ictc-g-1 controller --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 1405b53c..22da9cab 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,12 @@ This automation will bring the following functionalities to IKEA E1743: - Manual increase/decrease of brightness - Smooth increase/decrease (holding button) of brightness +This automation will bring the following functionalities to IKEA ICTC-G-1: + +- Turn off light(s) (quickly rotating left) +- Turn on light(s) at full brightness (quickly rotating right) +- Smooth increase/decrease of brightness (rotating right/left) + ## Installation ### HACS @@ -48,6 +54,16 @@ nameOfYourInstanceApp: light: ``` +For IKEA ICTC-G-1: + +```yaml +nameOfYourInstanceApp: + module: z2m_ikea_controller + class: ICTCG1Controller + sensor: + light: +``` + _Note: This was tested with both devices, Zigbee2MQTT and IKEA lights, but the code does not use any MQTT calls, just Home assistant API._ | key | optional | type | default | example | description |