Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ICTC-G-1 controller #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,6 +54,16 @@ nameOfYourInstanceApp:
light: <light or group entity id>
```

For IKEA ICTC-G-1:

```yaml
nameOfYourInstanceApp:
module: z2m_ikea_controller
class: ICTCG1Controller
sensor: <sensor(s) entity id>
light: <light or group entity id>
```

_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 |
Expand Down
45 changes: 43 additions & 2 deletions apps/z2m_ikea_controller/z2m_ikea_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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