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

[NEW DEVICE] Legrand double wall switch #98

Closed
Crocmagnon opened this issue Jul 15, 2020 · 11 comments
Closed

[NEW DEVICE] Legrand double wall switch #98

Crocmagnon opened this issue Jul 15, 2020 · 11 comments
Assignees
Labels
new-device New device

Comments

@Crocmagnon
Copy link
Contributor

Crocmagnon commented Jul 15, 2020

New Device Support

Device Information

  • Device Model: Multiple device models (different look & feel). I have a 6 000 88
  • Device Description: Legrand double gang switch
  • Device Manufacturer: Legrand

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,
        }

Integrations

Integration: zha

Actions

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.

@Crocmagnon
Copy link
Contributor Author

🎉
What would the configuration look like to control two different lights from the two buttons?

@xaviml
Copy link
Owner

xaviml commented Jul 15, 2020

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:

  • press left top button: Turn on light
  • press left bottom button: Turn off light
  • hold left top button: Change color or color temperature up
  • hold left bottom button: Change color or color temperature down
  • press right top button: Full brightness
  • press right bottom button: Minimum brightness
  • hold right top button: Change brightness up
  • hold right bottom button: Change brightness down

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.

@Crocmagnon
Copy link
Contributor Author

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? :)

@xaviml
Copy link
Owner

xaviml commented Jul 17, 2020

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.

@xaviml
Copy link
Owner

xaviml commented Jul 17, 2020

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.

@Crocmagnon
Copy link
Contributor Author

Crocmagnon commented Jul 19, 2020

Yes, that’s 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.

@xaviml
Copy link
Owner

xaviml commented Jul 19, 2020

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.

xaviml added a commit that referenced this issue Jul 30, 2020
…llers

Now the mapping attribute can be used in any Controller type, so no need of CustomLightController for example, use LightController instead. We can also now use the mapping attribute for device controllers like E1810Controller or MFKZQ01LMLightController for example.

related to #98
@xaviml
Copy link
Owner

xaviml commented Aug 8, 2020

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 :)

@Crocmagnon
Copy link
Contributor Author

That looks great! Unfortunately I don't have time to test it right now but I will as soon as possible 😀

xaviml added a commit that referenced this issue Aug 17, 2020
…llers

Now the mapping attribute can be used in any Controller type, so no need of CustomLightController for example, use LightController instead. We can also now use the mapping attribute for device controllers like E1810Controller or MFKZQ01LMLightController for example.

related to #98
@xaviml
Copy link
Owner

xaviml commented Aug 17, 2020

Changes have been shipped to ControllerX v3.4.0.

@xaviml xaviml closed this as completed Aug 17, 2020
@Crocmagnon
Copy link
Contributor Author

Crocmagnon commented Aug 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-device New device
Projects
None yet
Development

No branches or pull requests

2 participants