ControllerX. Bring full functionality to light and media player controllers

Hi Henning,

I do not doubt that your controllers work perfectly. And my WXKG01 (using ‘click’ iso ‘action’ - of course) works as ‘good’ as my Hue Dimmers, but suffers from the exact same problem.

But the fact remains that ‘my’ Z2M publishes topics strictly according to the official docs - and yours (and Xavi’s) does not quite, as Xavi admitted freely and as you can easily check for yourself. But no worries, as it’s rather easy to solve this discrepancy, and I’m sure Xavi is on top of it.

Cheers and thanks for chiming in,
Paul

Hi’ @pav & @xaviml

Well, ‘Google is your friend’ :wink:

It took some time to actually ‘filter out’ the answer I was looking for, but evetually I DID find it.
Both yours and mine (and Xavi’s) setup and MQTT commands are actually as expected and documented. But I must admit, that it was very hard to find some documentation on the specific Home Assistant legacy entity state implementation commands.

Please check this issue and especially check out Koenkk’s replies April 22nd, 2020

With homeassistant: true set in configuration.yaml you’ll get the extra MQTT command that clears state, in order to be able to trigger directly on state change in HA. Otherwise it would be impossible (as you’ve experienced) to detect multiple state changes on same entity_id. Makes perfect sense for all z2m click devices.

If you only use MQTT device triggers, it’s possible to completely disabe the HA entity integration with homeassistant_legacy_triggers: false

Recommended method is still using MQTT device triggers

Can’t test the above as I’m at work, but I’m quite sure that’s why we experience different MQTT commands in the logs.

Do you have the homeassistant: true set in your configuration.yaml, @pav ?

Ciao !

Hi @htvekov,

Thanks for finding this! I really tried to find why this was happening, but I could not. However, the documentation does not say what the homeassistant: true fully does. I did just try to set homeassistant to false in the configuration and indeed, I do not receive the /action and /click topic in the MQTT.

Anyway, I will give full support to the other topic in ControllerX since it is the official topic from Z2M.

Cheers,
Xavi M.

No worries, @xaviml :sunglasses:

Actually I’ve never given it ANY thought, that there were multiple MQTT calls for my click devices. Just used the easiest approach for automations - before you came up with ControllerX :grin:
For HA’s state machine it also makes perfect sense and more consistant that states for click devices don’t ‘live’ forever. You pressed a button - and now it’s done… Next ! As I’ve mentioned previously, I really dislike my Hue core (or custom ??) remote integration, which actually leaves states to live ‘forever’. No, state is not ‘1_click_up’. I pressed that button like 10 hours ago :unamused:
It’s also much easier for newcomers to understand how to build easy automations, without the need to understand how to parse JSON objects.

But documentation really lacks - quite a bit! Now I know what it’s about, I can understand the vague sentences about HA legacy integration. But if I’ve read it two days ago, I wouldn’t have a clue about what Koenkk actually meant with that Home Assistant legacy paragraph :joy:

While you at it (MQTT integration in ControllerX), Xavi. Could you briefly check if there’s some potential code optimizing hidden somewhere in order to speed up MQTT integration ? :hugs: I’m still using HA for toggling lights and let ControllerX do the rest. With a MQTT automation in HA, toggle is some estimated 150-200 ms. faster than same with MQTT integration in ControllerX. If not, I might raise an issue (more like a question) and ask Frenck if something could be done in Appdeamon code ?

Ciao !

1 Like

I’m at a loss here guys. Nothing happens when I press any of the buttons on the dimmer
Log for Appdaemon4:

[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: AppDaemon 4
 Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 0.2.6
 You are running the latest version of this add-on.
 System: HassOS 4.11  (armv7 / raspberrypi4)
 Home Assistant Core: 0.113.3
 Home Assistant Supervisor: 229
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] appdaemon.sh: executing... 
[cont-init.d] appdaemon.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[16:10:09] INFO: Starting AppDaemon...
2020-08-05 16:10:10.637804 INFO AppDaemon: AppDaemon Version 4.0.3 starting
2020-08-05 16:10:10.638242 INFO AppDaemon: Python version is 3.8.2
2020-08-05 16:10:10.638823 INFO AppDaemon: Configuration read from: /config/appdaemon/appdaemon.yaml
2020-08-05 16:10:10.639267 INFO AppDaemon: Added log: AppDaemon
2020-08-05 16:10:10.639871 INFO AppDaemon: Added log: Error
2020-08-05 16:10:10.640252 INFO AppDaemon: Added log: Access
2020-08-05 16:10:10.640633 INFO AppDaemon: Added log: Diag
2020-08-05 16:10:10.682808 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2020-08-05 16:10:10.723520 INFO HASS: HASS Plugin Initializing
2020-08-05 16:10:10.724020 INFO HASS: HASS Plugin initialization complete
2020-08-05 16:10:10.725048 INFO AppDaemon: Initializing HTTP
2020-08-05 16:10:10.725907 INFO AppDaemon: Using 'ws' for event stream
2020-08-05 16:10:10.751138 INFO AppDaemon: Starting API
2020-08-05 16:10:10.762340 INFO AppDaemon: Starting Admin Interface
2020-08-05 16:10:10.763217 INFO AppDaemon: Starting Dashboards
2020-08-05 16:10:10.792982 INFO HASS: Connected to Home Assistant 0.113.3
2020-08-05 16:10:10.836462 INFO AppDaemon: App 'hello_world' added
2020-08-05 16:10:10.837938 INFO AppDaemon: App 'myroom_controller' added
2020-08-05 16:10:10.840961 INFO AppDaemon: Found 2 total apps
2020-08-05 16:10:10.842502 INFO AppDaemon: Starting Apps with 2 workers and 2 pins
2020-08-05 16:10:10.846649 INFO AppDaemon: Running on port 5050
2020-08-05 16:10:10.888306 INFO HASS: Evaluating startup conditions
2020-08-05 16:10:10.920861 INFO AppDaemon: Got initial state from namespace default
2020-08-05 16:10:12.863428 INFO AppDaemon: Scheduler running in realtime
2020-08-05 16:10:12.874521 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2020-08-05 16:10:12.876460 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx to module import path
2020-08-05 16:10:12.878670 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_devices to module import path
2020-08-05 16:10:12.880662 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_core to module import path
2020-08-05 16:10:12.882016 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_core/type to module import path
2020-08-05 16:10:12.883162 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_core/stepper to module import path
2020-08-05 16:10:12.884318 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_core/integration to module import path
2020-08-05 16:10:12.885538 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/cx_core/feature_support to module import path
2020-08-05 16:10:12.941157 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/hello.py
2020-08-05 16:10:12.953977 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_const.py - ignoring
2020-08-05 16:10:12.956244 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/controllerx/controllerx.py
2020-08-05 16:10:12.998783 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_version.py - ignoring
2020-08-05 16:10:13.000717 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/legrand.py - ignoring
2020-08-05 16:10:13.003684 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/aqara.py - ignoring
2020-08-05 16:10:13.005612 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/ikea.py - ignoring
2020-08-05 16:10:13.007838 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/lutron.py - ignoring
2020-08-05 16:10:13.009922 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/trust.py - ignoring
2020-08-05 16:10:13.012114 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/smartthings.py - ignoring
2020-08-05 16:10:13.014140 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/philips.py - ignoring
2020-08-05 16:10:13.016331 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_devices/__init__.py - ignoring
2020-08-05 16:10:13.018369 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/color_helper.py - ignoring
2020-08-05 16:10:13.020569 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/custom_controller.py - ignoring
2020-08-05 16:10:13.022434 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/__init__.py - ignoring
2020-08-05 16:10:13.024730 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/controller.py - ignoring
2020-08-05 16:10:13.026582 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/type/switch_controller.py - ignoring
2020-08-05 16:10:13.029509 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/type/light_controller.py - ignoring
2020-08-05 16:10:13.032127 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/type/__init__.py - ignoring
2020-08-05 16:10:13.035285 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/type/media_player_controller.py - ignoring
2020-08-05 16:10:13.037956 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/type/cover_controller.py - ignoring
2020-08-05 16:10:13.041113 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/stepper/circular_stepper.py - ignoring
2020-08-05 16:10:13.043780 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/stepper/__init__.py - ignoring
2020-08-05 16:10:13.046857 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/stepper/minmax_stepper.py - ignoring
2020-08-05 16:10:13.049604 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/mqtt.py - ignoring
2020-08-05 16:10:13.052724 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/zha.py - ignoring
2020-08-05 16:10:13.055405 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/z2m.py - ignoring
2020-08-05 16:10:13.058581 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/__init__.py - ignoring
2020-08-05 16:10:13.061176 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/state.py - ignoring
2020-08-05 16:10:13.064278 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/integration/deconz.py - ignoring
2020-08-05 16:10:13.066919 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/feature_support/cover.py - ignoring
2020-08-05 16:10:13.070030 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/feature_support/light.py - ignoring
2020-08-05 16:10:13.072698 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/feature_support/media_player.py - ignoring
2020-08-05 16:10:13.075720 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/cx_core/feature_support/__init__.py - ignoring
2020-08-05 16:10:13.077988 INFO AppDaemon: Initializing app hello_world using class HelloWorld from module hello
2020-08-05 16:10:13.081931 INFO AppDaemon: Initializing app myroom_controller using class HueDimmerController from module controllerx
2020-08-05 16:10:13.275121 INFO hello_world: Hello from AppDaemon
2020-08-05 16:10:13.277518 INFO hello_world: You are now ready to run Apps!
2020-08-05 16:10:13.291356 INFO myroom_controller: 🎮 ControllerX v3.3.0
2020-08-05 16:10:13.299759 INFO AppDaemon: App initialization complete

ZHA event:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:17:88:01:04:f1:b4:f0",
        "unique_id": "00:17:88:01:04:f1:b4:f0:2:0xfc00",
        "endpoint_id": 2,
        "cluster_id": 64512,
        "command": "on_short_release",
        "args": {
            "button": "on",
            "press_type": "short_release",
            "command_id": 0,
            "args": [
                1,
                3145728,
                2,
                33,
                0,
                0
            ]
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-08-05T15:02:46.716006+00:00",
    "context": {
        "id": "1d6d720736154e5fa1e81b95f092f641",
        "parent_id": null,
        "user_id": null
    }
}

config\appdaemon\apps\apps.yaml

---
hello_world:
  module: hello
  class: HelloWorld
myroom_controller:
  module: controllerx
  class: HueDimmerController
  controller: 00:17:88:01:04:f1:b4:f0
  integration: zha
  light: group.my_room

What am I missing?

Hi @cabalforces,

Everything related to configuration seems right to me. What I think is happening is that the events that the Hue Dimmer switch fire are different from what ControllerX is expecting. ZHA is the most complicated integration to maintain since the events change from time to time and I am the only one maintaining all the controllers to be up-to-date. So if you want to help, could you please raise an issue (bug) on the GitHub repository and report the different ZHA JSON events for each action (clicks, holds and releases). Then I will update the code to integrate again that Controller for the ZHA integration.

Cheers,
Xavi M.

1 Like

Hi @htvekov,

Could you share the YAML automation from HA to have an idea of what the flow is and compare it to ControllerX? There is no much to optimize on the MQTT integration, it just listens to the topic that is been set and then calls HA services. Just to clarify, the MQTT integration (and any other) is to get the actions from the controllers, when dealing with devices/entities (lights, media players, switches, etc) ControllerX communicates through HA call services. This means that if you have a controller and a light with Z2M, the communication with the controller will be done with MQTT directly to AppDaemon/ControllerX, but when toggling the light, ControllerX sends a HA call service and not a MQTT topic.

Cheers,
Xavi M.

Hi’ Xavi.

I’ve been trying many different setup’s to toggle lights as fast as possible from my in wall Tasmota switchmode 11/12 Shelly’s. As you know, these use MQTT commands for the different click and hold situations.

Fastest setup so far for ‘toggle’, is using HA automation which listens to identical topic as used in ControllerX and uses standard HA light.toggle service calls to toggle the light. This setup is really close to instant action.

With Appdeamon, identical setup is notisable slower. On first tests, I had an active contrain_input_boolean in YAML. Disabling that actually makes ControllerX quite a bit faster. Perhaps almost halfes the ‘lag’ experienced with constrain_input_boolean. But still HA automation with MQTT trigger and even HA state trigger is faster than ControllerX with MQTT trigger… ?

On second thought, this leads me to think that MQTT integration is perhaps not the culprit here, but more likely that appdeamon <–> HA state integration has speed issues. Appdeamon uses many milliseconds more than HA itself to check states (condition using contrain_input_boolean) and/or changing states with same service calls as HA uses. Either that or HA automations are more closely linked to HA core than appdeamon (or any other external app) is. And hence can access state machine much faster than any external app ?

Don’t get me wrong - Both Appdeamon and ControllerX are excellent and makes life SO much easier :hugs: But it triggers my OCD :crazy_face::joy::rofl:that I can’t gather all tidy and neatly in ControllerX. Instead I’m forced to breakup my automations in both HA and ControllerX.

Probably just the way it is I’m afraid. And I’ll, without any doubt, survive this ‘luxury’ problem :grin::grin:

Below my test automation in HA and appdeamon.

Ciao !

# *** HA AUTOMATION ***
# Toggle lights through HA using MQTT trigger. Quicker responce than using platform state or directly in appdeamon ControllerX app 

- id: kontor_loftlys_cstm_mqtt_toggle
  alias: kontor_loftlys_cstm_mqtt_toggle
  
  trigger:
    platform: mqtt
    topic: zigbee2mqtt/office_cmnd
    payload: "toggle"
  
  #trigger:
  #- entity_id: sensor.tasmotest
  #  platform: state
  #  to: 'toggle'
  
  action:  
  - service: light.toggle
    data:
      entity_id:
      - light.0xec1bbdfffed45c3b_light
# ***  appdeamon app ***
controller_switchmode11_toggle_office:
  module: controllerx
  class: CustomLightController
  
  controller: 'zigbee2mqtt/office_cmnd'
  integration: mqtt
  #controller: sensor.tasmotest
  #integration: state

  light: light.0x680ae2fffe924460_light
  add_transition_turn_toggle: false
  mapping:
    toggle: toggle
  #constrain_input_boolean: light.0x90fd9ffffe838cb3_light,off 

feature request: make it possible to create “virtual” binary sensors for whatever zigbee switches.

apps.yaml

short_press_virtual_binary_sensor: “binary_sensor.bedroom_switch_short”
long_press_virtual_binary_sensor: “binary_sensor.bedroom_switch_long”

then I could use those zigbee switches as normal button entities in other usecases, the benefit is that the consumer case would not need to know if its a zigbee button or something else.

so pressing the button on my xiaomi switch would just flip the value of the defined virtual binary sensor.

Hi @gibman,

Not sure if I understood you fully, but you can toggle any type of sensor using CallServiceController (about to be deprecated and Controller can be used, but behaviour is the same). You can overwrite an attribute called mapping where you can define the event/action as a key and the service to call as value. Configuration would look like:

example_app:
  module: controllerx
  class: CallServiceController
  controller: sensor.controller_id
  integration: z2m
  mapping:
    single:
      service: input_boolean.toggle
      data:
        entity_id: input_boolean.your_input_boolean

From the ControllerX v3.4.0 (the beta version was just released) you will be able to do the same by doing:

example_app:
  module: controllerx
  class: SwitchController
  controller: sensor.controller_id
  integration: z2m
  switch: input_boolean.your_input_boolean
  mapping:
    single: toggle

This configuration allows you then to switch the value of your input_boolean when pressing the WXKG11LM Aqara switch. It goes without saying that the input_boolean.your_input_boolean should exist in your HA setup, either via UI r configuration.yaml.

Not sure if this is what you are looking for, otherwise, could you specify more in detail what is what you are looking for and see if it is something worth to implement or it’s there already a way of achieving it.

Cheers and thanks for the feature request!
Xavi M.

1 Like

Hi, do you think you can add support for this controller?

I have it working using deCONZ. It doesn’t show there, but it is listed under integrations/entities in HA. Also I can listen to event and have written an automation with it succesfully toggling lights using event_type: deconz_event. ControllerX support would be amazing!

I can help you out with finding out all the events that are paired to button presses and test this :slight_smile:

Hi @ASNNetworks,

Adding support to new device is simple. I will just need all the actions fired from each of the buttons (presses, holds, releases). You can create a new device in here.

Let me know if you have any questions.

Cheers,
Xavi M.

Awesome! I noticed some buttons have a hold option (firing a new event every 1-2 seconds) while others have a press-hold-release event and don’t keep firing.

I will test extensively tomorrow and share it there!

1 Like

Is is possible for custom controller to release an action if it repeated, for example, if I long press it do hold_xycolor_up and long press again it release the action ?

Hi @SilverWx,

This is not possible in the latest ControllerX version, but it will be possible on ControllerX v3.4.0. You can try it out on the beta version: https://github.com/xaviml/controllerx/releases/tag/v3.4.0b2

There is a new added attribute called hold_release_toggle. If true , a hold action will work as a release when another hold is running. This is useful when you have a button with just one action event and you want to use the hold-release feature, then you just need to map that event to a hold action. Otherwise, it will work as always, when a hold action is called while another one is called, then it will be ignored. Default is false. Configuration would look like the following:

example_app:
  module: controllerx
  class: E1810Controller
  controller: example_controller
  integration:
    name: z2m
    listen_to: mqtt
  light: light.livingroom_lamp
  hold_release_toggle: true
  mapping:
    toggle: hold_brightness_toggle

The important things in the config are the hold_release_toggle: true and that you can just use the toggle: hold_brightness_toggle without a release action. With this, every time you click the toggle button, it will bright up/down the light and stop when it is click again if it is still changing the brightness.

Cheers,
Xavi M.

So a good news !!
Perfect, thanks for the info :smiley:

1 Like

v3.4.0 is now released :partying_face:

downloads

This minor change does not contain breaking changes.
Note: Remember to restart the AppDaemon addon/server after updating to a new version.

:pencil2: Features

  • Add the mapping attribute to the Controller base code, so the attribute can be used in any controller class. Custom controllers have been deprecated, they can still be in use, but a warning will be shown in the console [ #98 ]
  • Add attribute parameter to the state integration to listen to state attributes. Default is to listen to the state as it already was [ #106 ]
  • Allow input_boolean and binary_sensor entities to be used in switch controllers
  • Add listen_to attribute to choose between listening to HA state or MQTT [ #109 ]
  • Add hold_release_toggle attribute. If true, a hold action will work as a release when another hold is running. This is useful when you have a button with just one action event and you want to use the hold-release feature, then you just need to map that event to a hold action. Otherwise, it will work as always, when a hold action is called while another one is called, then it will be ignored. Default is false.

:hammer: Fixes

  • Raise an error when a group has no entities [ #102 ]
  • Fix brightness transition only works once after a controller is started [ #100 ]
  • Fix ZHA mapping for HueDimmerController [ #110 ]
  • Fix Toggle direction requires the button to be held twice [ #113 ]

:scroll: Docs

  • Create Sonos Display documentation @htvekov [ #104 ]
  • Fix mapping for E1744 in the documentation [ #103, #105 ]
  • Update Tasmota Switchmode example @htvekov [ #114 ]
1 Like

Nice!

Can you perhaps update this controller https://xaviml.github.io/controllerx/controllers/WXCJKG13LM?

deCONZ supports this controller as well (I have received one today and paired it succesfully). Or can I just edit some files and tie in the deconz events myself?

Hi @ASNNetworks,

You can create a GitHub ticet in here. I will just need the events that each button fire (press, hold, release, double click, triple click).

Cheers,
Xavi M.

1 Like

Holy cr*p, @xaviml.
You’re on fire!! :fire::fire::fire::rocket::rocket::rocket: - v3.4.0 :sunglasses:

I’ve been using ControllerX for half a year now and just thought about the incredible development you’ve done with ControllerX in only six months time. Wow !! :clap::clap:
Your dedication, time spent with us end users and the countless hours you’ve spent debugging issues / enhancing code is simply amazing…

Go have a beer (or two), mate! :beers:
You definitely deserve it ! :smiley:

Edit: They are on me ! :wink:

Cheers !!

1 Like