diff --git a/apps/controllerx/controllerx.py b/apps/controllerx/controllerx.py index b95c7ef3..0f938980 100644 --- a/apps/controllerx/controllerx.py +++ b/apps/controllerx/controllerx.py @@ -22,6 +22,7 @@ from cx_devices.livarno import * from cx_devices.lutron import * from cx_devices.muller_licht import * +from cx_devices.namron import * from cx_devices.osram import * from cx_devices.philips import * from cx_devices.prolight import * diff --git a/apps/controllerx/cx_devices/namron.py b/apps/controllerx/cx_devices/namron.py new file mode 100644 index 00000000..8fce458d --- /dev/null +++ b/apps/controllerx/cx_devices/namron.py @@ -0,0 +1,45 @@ +from cx_const import DefaultActionsMapping, Light +from cx_core import LightController + + +def generate_n45127772_chanmap(index: int) -> DefaultActionsMapping: + """Generate mapping for a namron 45127772 channel group.""" + if index not in range(1, 5): + raise ValueError("Only values between 1 and 4 are supported.") + + return { + f"on_l{index}": Light.ON, + f"off_l{index}": Light.OFF, + f"brightness_move_up_l{index}": Light.HOLD_BRIGHTNESS_UP, + f"brightness_move_down_l{index}": Light.HOLD_BRIGHTNESS_DOWN, + f"brightness_stop_l{index}": Light.RELEASE, + } + + +class Namron4512772Controller(LightController): + """Namron 4512772 Wall Switch with 8 buttons. + + This controller is meant to handle up to four different lights, with on/off and + brightness up/down. + + It has swappable physical buttons, and can support 1, 2 or 4 lights. + """ + + def get_z2m_actions_mapping(self) -> DefaultActionsMapping: + """Actions mapping. + + The controller is divided in to four groups all emitting the same events + suffixed with _l1 to _l4. + + """ + mapping: DefaultActionsMapping = {} + for n in range(1, 5): + mapping |= generate_n45127772_chanmap(n) + return mapping + + def default_delay(self) -> int: + """Set a default delay. + + This gives a better dimming experience. + """ + return 500 diff --git a/docs/docs/assets/controllers/Namron4512772.jpg b/docs/docs/assets/controllers/Namron4512772.jpg new file mode 100644 index 00000000..878ffd0d Binary files /dev/null and b/docs/docs/assets/controllers/Namron4512772.jpg differ diff --git a/docs/docs/examples/namron.md b/docs/docs/examples/namron.md new file mode 100644 index 00000000..e80e485f --- /dev/null +++ b/docs/docs/examples/namron.md @@ -0,0 +1,65 @@ +--- +title: Namron 4512772 Example +layout: page +--- + +### Using the Namron 4512772 Wall Switch + +The Namron 4512772 has four groups, and with swappable physical buttons it is intended to control one, two, or four buttons. + +To make this work with ControllerX, you can use one app per light you want to control. + +For example: + +```yaml +test_switch: + module: controllerx + class: Namron4512772Controller + integration: + name: z2m + listen_to: mqtt + controller: My_Namron_Lightswitch # The name of the controller in Z2M + actions: # Ensure that only the buttons you are interested in are configured. + - on_l1 # l1 - l4 selects the group of buttons + - off_l1 + - brightness_move_up_l1 + - brightness_move_down_l1 + - brightness_stop_l1 + light: light.my_light_entity +``` + +#### Setup with two buttons + +If the switch is installed with two physical buttons, it is recommended to configure groups 1 and **4**. + +```yaml +test_switch_grp1: + module: controllerx + class: Namron4512772Controller + integration: + name: z2m + listen_to: mqtt + controller: My_Namron_Lightswitch + actions: + - on_l1 + - off_l1 + - brightness_move_up_l1 + - brightness_move_down_l1 + - brightness_stop_l1 + light: light.my_light_entity + +test_switch_grp2: + module: controllerx + class: Namron4512772Controller + integration: + name: z2m + listen_to: mqtt + controller: My_Namron_Lightswitch + actions: + - on_l4 # l4 is the other button needed in a two button setup. + - off_l4 + - brightness_move_up_l4 + - brightness_move_down_l4 + - brightness_stop_l4 + light: light.my_other_light_entity +```