xaviml / controllerx

Create controller-based automations with ease to control your home devices and scenes.
https://xaviml.github.io/controllerx/
MIT License
336 stars 70 forks source link

[QUESTION] How to toggle a switch (plug)? #892

Open Gulpman opened 8 months ago

Gulpman commented 8 months ago

Question

I am trying to accomplish something - I thought - very simple but am struggling with my understanding of configuring ControllerX.

My use case In our living room I want to install an Aquara Opple 6-gang switch (WXCJKG13LM). I want to assign button 3 single press to toggle a plug where a lamp is attached to.

I managed to control the main light with the Aquara Opple 6-gang , e.g. putting actions and merge_mappings to the appropriate buttons for switching, dimming and changing color tempaerature flawlessly.

However, I'm stuck in how to tell ControlX to toggle the plug with one button. :)

At first I created a helper in Home Assistant to change the type of the plug from plug to light. But it seems that this is not detected as light as can bee seen from the following screenshot:

plug_as_light_not_detected_by_controllerx

I tried to use the plug as light. ... but that didn't work (see config below). I didn't find an example for what I am trying to accomplish - though I think this should be a very common use case?

I think it is just a tiny thing I'm missing but I do not get clear, how to do it in the documentation.

Can someone tell me how the right syntax would be?

Thank you very much in advance.

Additional information

AppDaemon app configuration

#  Aquara Opple 6-gang im Wohnzimmer an das Standlicht neben dem High Board
wz-opple6-door-to-wz-light-highboard:
  module: controllerx
  class: WXCJKG13LMLightController
  #class: WXCJKG13LMSwitchController
  #class: SwitchController
  integration: z2m
  controller: sensor.wz_switch_eingang_aqara6gang_action
  #light: switch.nn_tuyaplugorange01
  light: light.nn_tuyaplugorange01
  #switch: switch.nn_tuyaplugorange01
  actions:
    - button_3_single
  merge_mapping: # either use mapping: or merge_mapping:
    button_3_single: toggle

Logs

I didn't add all different logs, just the one from the config posted above - I think I understand why the error message there is - I just don't know how to fix it in the config :)

2024-02-25 16:00:49.437190 INFO AppDaemon: Reading config
2024-02-25 16:00:49.469306 INFO AppDaemon: /homeassistant/appdaemon/apps/apps.yaml added or modified
2024-02-25 16:00:49.470573 INFO AppDaemon: App 'wz-opple6-door-to-wz-light-highboard' changed
2024-02-25 16:00:49.473252 INFO AppDaemon: Found 8 active apps
2024-02-25 16:00:49.473686 INFO AppDaemon: Found 0 inactive apps
2024-02-25 16:00:49.474027 INFO AppDaemon: Found 0 global libraries
2024-02-25 16:00:49.511388 INFO AppDaemon: Terminating wz-opple6-door-to-wz-light-highboard
2024-02-25 16:00:49.512268 INFO AppDaemon: Reloading Module: /homeassistant/appdaemon/apps/controllerx/controllerx.py
2024-02-25 16:00:49.513752 INFO AppDaemon: Loading app wz-opple6-door-to-wz-light-highboard using class WXCJKG13LMLightController from module controllerx
2024-02-25 16:00:49.515242 INFO AppDaemon: Calling initialize() for wz-opple6-door-to-wz-light-highboard
2024-02-25 16:00:49.517634 INFO wz-opple6-door-to-wz-light-highboard: 🎮 ControllerX v4.26.2
2024-02-25 16:00:49.518051 WARNING wz-opple6-door-to-wz-light-highboard: ------------------------------------------------------------
2024-02-25 16:00:49.518383 WARNING wz-opple6-door-to-wz-light-highboard: Unexpected error running initialize() for wz-opple6-door-to-wz-light-highboard
2024-02-25 16:00:49.518690 WARNING wz-opple6-door-to-wz-light-highboard: ------------------------------------------------------------
2024-02-25 16:00:49.519313 WARNING wz-opple6-door-to-wz-light-highboard: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/app_management.py", line 160, in initialize_app
    await init()
  File "/homeassistant/appdaemon/apps/controllerx/cx_core/controller.py", line 104, in initialize
    await self.init()
  File "/homeassistant/appdaemon/apps/controllerx/cx_core/type/light_controller.py", line 146, in init
    await super().init()
  File "/homeassistant/appdaemon/apps/controllerx/cx_core/type_controller.py", line 53, in init
    raise ValueError(
ValueError: WXCJKG13LMLightController class needs the `light` attribute

2024-02-25 16:00:49.520224 WARNING wz-opple6-door-to-wz-light-highboard: ------------------------------------------------------------
2024-02-25 16:00:50.523632 INFO AppDaemon: Reading config
2024-02-25 16:00:50.557264 INFO AppDaemon: /homeassistant/appdaemon/apps/apps.yaml added or modified
2024-02-25 16:00:50.558588 INFO AppDaemon: App 'wz-opple6-door-to-wz-light-highboard' changed
2024-02-25 16:00:50.561262 INFO AppDaemon: Found 8 active apps
2024-02-25 16:00:50.561729 INFO AppDaemon: Found 0 inactive apps
2024-02-25 16:00:50.562083 INFO AppDaemon: Found 0 global libraries
2024-02-25 16:00:50.589050 INFO AppDaemon: Terminating wz-opple6-door-to-wz-light-highboard
2024-02-25 16:00:50.589920 INFO AppDaemon: Reloading Module: /homeassistant/appdaemon/apps/controllerx/controllerx.py
2024-02-25 16:00:50.591650 INFO AppDaemon: Loading app wz-opple6-door-to-wz-light-highboard using class WXCJKG13LMLightController from module controllerx
2024-02-25 16:00:50.593121 INFO AppDaemon: Calling initialize() for wz-opple6-door-to-wz-light-highboard
2024-02-25 16:00:50.595460 INFO wz-opple6-door-to-wz-light-highboard: 🎮 ControllerX v4.26.2
xaviml commented 8 months ago

Hi @Gulpman,

Sorry for the late reply. I am assuming you have already another config which hooks the same controller to a light (which you said it works well). Then, within the same config, you can hook an control what to do with the action you want. For example:

wz-opple6-door-to-wz-light-highboard:
  module: controllerx
  class: WXCJKG13LMLightController
  integration: z2m
  controller: sensor.wz_switch_eingang_aqara6gang_action
  light: light.your_light # This is the light you have hooked up with the controller with brightness and temperature
  merge_mapping: # either use mapping: or merge_mapping:
    button_3_single:
      service: switch.toggle
      entity_id: switch.nn_tuyaplugorange01

What this configuration will do is to control light.your_light with the specification from the default mapping (https://xaviml.github.io/controllerx/controllers/WXCJKG13LM/#light), and override the button_3_single action to toggle the plug.

Let me know if this is what you were looking for or not. In case of not working, could you please share the logs when you press the button, so I can see what happens?

Thanks!

Gulpman commented 8 months ago

Hi @xaviml. thank you for your reply.

In the meantime I managed to get what I want to work by using the blue print "Aqara Opple switch 3 bands via zigbee2mqtt" and assign the single click events there. However I do prefer to handle all the actions for one switch at one place, so I tried it out.

Your proposed change worked. :) Thank you very much for the explaination. Now button 3 is switching the plug where a lamp on the highboard is connected to.

However, as I prefer to have a single configuration for each [SWITCH] <-> [LIGHT] combination I tried to modify my initial configuration from the question to meet what I want to achieve and this as well worked.

So here is the working configuration for that:

#  Aquara Opple 6-gang im Wohnzimmer an das Standlicht neben dem High Board
wz-opple6-door-to-wz-light-highboard:
  module: controllerx
  class: WXCJKG13LMLightController
  integration: z2m
  controller: sensor.wz_switch_eingang_aqara6gang_action
  light: light.nn_tuyaplugorange01
  actions:
    - button_3_single
  merge_mapping: # either use mapping: or merge_mapping:
    button_3_single:
      service: light.toggle

This is for sure only working if you use a helper within Home Assistant which changes the type of a switch to a light.

So the last question I have: Would it be possible to configure ControllerX so I can tell it to use a switch instead of a light as destination?

So somehow change the line

light: light....

to something like

light: switch...

to allow switches as "lights" to be switched or

switch: switch....

to allow switches as targets? For sure only on, off and toggle could be assigned to those.

xaviml commented 7 months ago

Hi @Gulpman ,

Your configuration makes sense to me as well. In fact, the actions part is not needed if you use mapping instead of merge_mapping as you pointed out in the comment:

#  Aquara Opple 6-gang im Wohnzimmer an das Standlicht neben dem High Board
wz-opple6-door-to-wz-light-highboard:
  module: controllerx
  class: WXCJKG13LMLightController
  integration: z2m
  controller: sensor.wz_switch_eingang_aqara6gang_action
  light: light.nn_tuyaplugorange01
  mapping:
    button_3_single:
      service: light.toggle

Would it be possible to configure ControllerX so I can tell it to use a switch instead of a light as destination?

Yes, you can use a regular SwitchController instead of WXCJKG13LMLightController, so:

#  Aquara Opple 6-gang im Wohnzimmer an das Standlicht neben dem High Board
wz-opple6-door-to-wz-light-highboard:
  module: controllerx
  class: SwitchController
  integration: z2m
  controller: sensor.wz_switch_eingang_aqara6gang_action
  switch: switch.nn_tuyaplugorange01
  mapping:
    button_3_single:
      service: light.toggle

Note that WXCJKG13LMLightController is a Light Controller, so it expects only lights as entity. However, ControllerX support other types of controllers (e.g. Switch, Cover). You can read more about other types here.

Hopes this clarifies the questions you had.

Regards, Xavi M.