Side note: I have a zha implementation ready for the simple wall switch - 6 000 83, but I'm not sure how to handle the two endpoints in the double switch. Each endpoint (vertical pair of buttons) should be able to control a different light.
Implementation
# cx_devices/legrand.py
from cx_const import Light, TypeActionsMapping
from cx_core import LightController
class SimpleWallSwitchController(LightController):
# Different states reported from the controller:
# on, off, brightness_up, brightness_down, brightness_stop
def get_zha_actions_mapping(self) -> TypeActionsMapping:
return {
"on": Light.ON,
"off": Light.OFF,
"move_0_255": Light.HOLD_BRIGHTNESS_UP,
"move_1_255": Light.HOLD_BRIGHTNESS_DOWN,
"stop": Light.RELEASE,
}
There are four buttons. The switch recognizes both short and long presses.
Top left short press
"data": {
"device_ieee": "00:04:74:00:00:92:1d:78",
"unique_id": "00:04:74:00:00:92:1d:78:1:0x0006",
"endpoint_id": 1,
"cluster_id": 6,
"command": "off",
"args": []
}
Bottom left short press
"data": {
"device_ieee": "00:04:74:00:00:92:1d:78",
"unique_id": "00:04:74:00:00:92:1d:78:1:0x0006",
"endpoint_id": 1,
"cluster_id": 6,
"command": "on",
"args": []
}
Top right short press
"data": {
"device_ieee": "00:04:74:00:00:92:1d:78",
"unique_id": "00:04:74:00:00:92:1d:78:1:0x0006",
"endpoint_id": 2,
"cluster_id": 6,
"command": "off",
"args": []
}
Bottom right short press
"data": {
"device_ieee": "00:04:74:00:00:92:1d:78",
"unique_id": "00:04:74:00:00:92:1d:78:1:0x0006",
"endpoint_id": 2,
"cluster_id": 6,
"command": "on",
"args": []
}
The long press are the same but with "command": "move", "args": [0, 255] for the bottom buttons and "args": [1, 255] for the top buttons.
馃帀
What would the configuration look like to control two different lights from the two buttons?
Well, if you want to control 2 lights, you will need to use CustomLightController. ControllerX configuration aims to bind N controllers to N lights (everything with everything). If you want 1 button to control 1 light and another button to control another light, then you will need the CustomLightController as I mentioned.
However, ControllerX should give a default behaviour to the controller acting to one light. What I normally do with other controllers like this is:
I can add this to your code if you want, I just need to make sure that endpoint 1 is the left button and endpoint 2 is the right one. Is this true?
Thank you,
Xavi M.
Yep, feel free to add this to the PR :)
endpoint 1 is the left button and endpoint 2 is the right one. Is this true?
Yes it is!
you will need to use CustomLightController
Do you have any existing example of how I could configure it to manage two lights? :)
Hi @Crocmagnon I just added both devices and the documentation to your branch. I will proceed with the merge request then. Regarding the configuration for two light, it will look like the following:
example_app_light1:
module: controllerx
class: CustomLightController
controller: <controller id>
integration: <your integration>
light: light.light1
mapping:
1_on: on
1_off: off
1_move_up: hold_brightness_up
1_move_down: hold_brightness_down
1_stop: release
example_app_light2:
module: controllerx
class: CustomLightController
controller: <controller id>
integration: <your integration>
light: light.light2
mapping:
2_on: on
2_off: off
2_move_up: hold_brightness_up
2_move_down: hold_brightness_down
2_stop: release
Basically, we map one config with the events from the left button (1_) and the other for the right button (2_). The configuration uses the hold for brightness, but you can do what ever you want with the button actions. You can see the full predefined actions in here. However, if you want something even more customised, you can use CallServiceController to map button events with HA services.
Let me know if you need any help :)
Cheers,
Xavi M.
HI @Crocmagnon,
The integration for these 2 controllers is now in ControllerX v3.3.0. However, I just realised that the configuration I sent you earlier it will not work since the ZHA parse is done to the device level and we are not specifying the device, but the CustomLightController. I will need to think about how to solve this problem. I will let you know.
Yes, that鈥檚 what I thought when I took a glance at it.
An option to override the mapping of any controller class would solve this and may other use cases: we could add classes to support special device features such as my switch with two endpoints but the user could have the final say over the commands mapping?
EDIT: we would need to document the possible values for the keys and values of the mapping dictionary
EDIT 2: That would also allow us to disable some mappings. For example: I setup some Zigbee groups for my lights and bound the switches to the groups so that even when HA is down I can still turn on/off the lights. I don't need the on/off feature of ControllerX for these lights. If I can override the mapping, it means I can disable this feature while keeping the light variation.
Hi @Crocmagnon,
You are right. Now the CustomLightController is another class and this could be solved if we could override the mapping with the same Device Controller Class. The possible key-value mapping values are already accessible in the Custom Controllers documentation and the specific device page.
I will let you know about the changes as soon as I get to it. In the meantime, I will leave this issue open to solve this problem.
Thanks,
Xavi M.
Hi @Crocmagnon,
A beta version of the ControllerX v3.4.0 has been released. Now, all the CustomXYZController have been deprecated and we can use the device controller to define a custom mapping. For example, if your controller is Legrand600083LightController, you can leave it in the class attribute and define the mapping attribute. Furthermore, if no device is specified for your controller, we can use Controller, LightController, MediaPlayerController to custom map the actions.
In your case, you will need to specify the Legrand device because the ZHA parsed has been specified for this controller, so configuration should be:
example_app_light1:
module: controllerx
class: Legrand600088LightController
controller: <controller id>
integration: <your integration>
light: light.light1
mapping:
1_on: on
1_off: off
1_move_up: hold_brightness_up
1_move_down: hold_brightness_down
1_stop: release
example_app_light2:
module: controllerx
class: Legrand600088LightController
controller: <controller id>
integration: <your integration>
light: light.light2
mapping:
2_on: on
2_off: off
2_move_up: hold_brightness_up
2_move_down: hold_brightness_down
2_stop: release
Please, let me know if this works for you if you try. Thank you :)
That looks great! Unfortunately I don't have time to test it right now but I will as soon as possible 馃榾
Changes have been shipped to ControllerX v3.4.0.
It works like a charm! 馃帀鉂わ笍
I just had to quote the "on"/"off" values from the config you previously posted but otherwise it works great, thank you very much! 馃殌
For the sake of completeness, here's a sample config:
example_app_light1:
module: controllerx
class: Legrand600088LightController
controller: <controller id>
integration: zha
light: <light>
mapping:
1_on: "on"
1_off: "off"
1_move_up: hold_brightness_up
1_move_down: hold_brightness_down
1_stop: release
example_app_light2:
module: controllerx
class: Legrand600088LightController
controller: <controller id>
integration: zha
light: <light>
mapping:
2_on: "on"
2_off: "off"
2_move_up: hold_brightness_up
2_move_down: hold_brightness_down
2_stop: release