Shelly Cloud - smooth dimming over MQTT using deconz

Hi all,

First and foremost - thanks for a great community - this is my first post here, so bear with me :slight_smile:

I’m having a hard time figuring out how to properly do smooth dimming on my Shelly Cloud Dimmers.

With the addition of the brightness control action in version 0.105, I can control the brightness in incremental steps - but I would like to do it in a smooth way, by using the long press events from Deconz for the TRADFRI remotes.

My setup is using TRADFRI E1810 through Deconz as the switch / dimming controller.
The Shelly Dimmers are connected through the standard MQTT broker using the Shellies Discovery Script.

Using this approach there’s no problems - I can create automations for switching the light ON (4002 click), OFF (5002 click), DIM UP (4001 hold start) and DIM DOWN (5001 hold start).

However, this approach has a very low WIF (Wife Acceptance Factor) - and I would like to improve on this :wink:

This led me to try the ControllerX solution - but after hours of frustration with no progress I’ve pretty much given up by now…

Am I expecting too much of HA at the moment, or am I missing something here?

Suggestions are more than welcome :slight_smile:

PS: I’ve only been using HA (hassio) for a month now, so go easy on me :smiley:

1 Like

Hi @ZEROBiTE,

I have just saw your post. I don’t if it is too late to respond, but I can help you set up your controller with ControllerX. This is the configuration that you should use in the apps.yaml:

any_name_you_want:
  module: controllerx
  class: E1810Controller
  controller: (controller id - you can extract this from the event)
  integration: deconz
  light: (light entity e.g. `light.bedroom`)

However, in order to use ControllerX, you will need to have AppDaemon up and running, do you have it already? If so, what are your problems? I would be glad to help you out :slight_smile:

Thanks for the reply @xaviml,

Since my initial post here, I actually managed to get some kind of response from the system.

So, I do of course have AppDaemon up and running, using the following configuration for XController:

MyController:
  log_level: DEBUG
  module: controllerx
  class: E1810Controller
  controller: tangent_4sl02_not_assigned
  light: light.shelly_dimmer_f32d92_light_0
  integration: deconz

I put the debug flag in there to do some basic debugging, some 16 days ago :slight_smile:

I am modding my E1810 controllers so they fit in-par with the Fuga line of wall outlets from the Danish manufacturer Lauritz Knudsen.

Because of the way the buttons end up, I would like the following behaviour (listed by Deconz event):

  • 4002 - Turn lamp ON
  • 5002 - Turn lamp OFF
  • 4001 - Begin dimming UP (brightness increases steadily at a constant rate)
  • 4003 - End dimming UP
  • 5001 - Begin dimming DOWN (brightness decreases steadily at a constant rate)
  • 5003 - End dimming DOWN

Furthermore - at the moment, the dimmer does respond whenever a 2002/3002 event is fired from Deconz - but I would very much like to change that mapping too, since I would like to use those two buttons for another purpose.

I did read about the mapping and action features of XController - but I didn’t manage to get it working.

Could you maybe point me in the right direction? :sunglasses:

Edit:
Browsing the log reveals the following error whenever Deconz is throwing a 5002 event:

2020-03-23 20:05:29.857880 DEBUG MyController: Button pressed: 4002
2020-03-23 20:05:29.869817 WARNING MyController: ------------------------------------------------------------
2020-03-23 20:05:29.871712 WARNING MyController: Unexpected error in worker for App MyController:
2020-03-23 20:05:29.873445 WARNING MyController: Worker Ags: {'id': '341330fb1a5a4c318829a0f3173555db', 'name': 'MyController', 'objectid': '6bb7ce12fb4e4f768b52b6d40c98c021', 'type': 'event', 'event': 'deconz_event', 'function': <bound method DeCONZIntegration.callback of <core.integration.deconz.DeCONZIntegration object at 0xb53c4550>>, 'data': {'id': 'tangent_4sl02_not_assigned', 'unique_id': '14:b4:57:ff:fe:77:74:de', 'event': 4002}, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'id': 'tangent_4sl02_not_assigned', '__thread_id': 'MainThread'}}
2020-03-23 20:05:29.875032 WARNING MyController: ------------------------------------------------------------
2020-03-23 20:05:29.877570 WARNING MyController: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 725, in async_worker
    await funcref(args["event"], data, args["kwargs"])
  File "/config/appdaemon/apps/controllerx/core/integration/deconz.py", line 16, in callback
    await self.controller.handle_action(data[type_])
  File "/config/appdaemon/apps/controllerx/core/controller.py", line 122, in handle_action
    await action(*args)
  File "/config/appdaemon/apps/controllerx/core/controller.py", line 29, in _action_impl
    await method(self, *args, **kwargs)
  File "/config/appdaemon/apps/controllerx/core/type/light_controller.py", line 352, in click
    attribute = await self.get_attribute(attribute)
  File "/config/appdaemon/apps/controllerx/core/type/light_controller.py", line 318, in get_attribute
    raise ValueError(
ValueError: This light does not support xy_color or color_temp

2020-03-23 20:05:29.879422 WARNING MyController: ------------------------------------------------------------

I recon this is caused because the XController tries to set an invalid or unsupported property on the light entity?

I guess this also points towards some missing or wrong action and/or mapping in my configuration?

Hi @ZEROBiTE,

Yes, this is right. It is trying to set color to your light and it does not support it.

The controller you are using is E1810Controller this gives the default behaviour to the controller for a light, so the center button toggles the light, the top/bottom buttons change the brightness and the left/right ones change the color.

However, if you want a custom behaviour, I suggest you to take a look to Custom Controller, which allows you to map the events to the actions you desired. In your case, if you want 4002 (left arrow) to turn on the lamp and 5002 (right arrow) to turn off the lamp, you can do the following:

MyController:
  log_level: DEBUG
  module: controllerx
  class: CustomLightController
  controller: tangent_4sl02_not_assigned
  light: light.shelly_dimmer_f32d92_light_0
  integration: deconz
  mapping:
    4002: on
    5002: off
    4001: hold_brightness_up
    4003: release
    5001: hold_brightness_down
    5003: release

You can see the deCONZ events for this controller in here and the predefined actions (the values in the map) in here.

Nonetheless, this controller will ignore the following events:

  • 1002 🠖 Click ⏻
  • 2002 🠖 Click :high_brightness:
  • 3002 🠖 Click :low_brightness:
  • 2001 🠖 Hold :high_brightness:
  • 2003 🠖 Release :high_brightness:
  • 3001 🠖 Hold :low_brightness:
  • 3003 🠖 Release :low_brightness:

You can either add more light predefined actions in the mapping object or you can create another app instance with CustomMediaPlayerController or CallServiceController to add the full functionality to your controller. For example, you can add the following to control another light with the same controller:

MyController2:
  log_level: DEBUG
  module: controllerx
  class: E1810Controller
  controller: tangent_4sl02_not_assigned
  light: light.another_light
  integration: deconz
  actions:
    - 1002
    - 2002
    - 3002
    - 2001
    - 2003
    - 3001
    - 3003

This adds the functionality to your controller to control also another light. This configuration does not replace the previous one, but adds to it.

If you tell me what you want to do with the rest of the events, I can help you create the configuration for it. I hope this helped :slight_smile:

Hi @xaviml,

Thank you for taking your time to help me out with this :slight_smile:

Your suggestions make a lot more sense to me now, than when I read the help pages myself - thanks for these explanations :+1:

However, when I changed my apps configuration to this:

MyController:
  log_level: DEBUG
  module: controllerx
  class: CustomLightController #E1810Controller
  controller: tangent_4sl02_not_assigned
  light: light.shelly_dimmer_f32d92_light_0
  integration: deconz
  mapping:
    4002: on
    5002: off
    #4001 : hold_brightness_up
    #4003 : release
    #5001 : hold_brightness_down
    #5003 : release

I get the following output in the log:

2020-03-25 13:00:39.856345 INFO AppDaemon: Initializing app MyController using class CustomLightController from module controllerx
2020-03-25 13:00:40.056097 INFO MyController: ControllerX v2.4.3
2020-03-25 13:00:40.062981 DEBUG MyController: Calling listen_event for MyController
2020-03-25 13:00:40.067002 INFO AppDaemon: App initialization complete
2020-03-25 13:01:48.256078 DEBUG MyController: Button pressed: 4002
2020-03-25 13:01:48.257089 WARNING MyController: ------------------------------------------------------------
2020-03-25 13:01:48.258635 WARNING MyController: Unexpected error in worker for App MyController:
2020-03-25 13:01:48.260347 WARNING MyController: Worker Ags: {'id': 'fc851c3f4381403e88cd888dba253376', 'name': 'MyController', 'objectid': '2f3bfdb2309d4462b3dc633195912d66', 'type': 'event', 'event': 'deconz_event', 'function': <bound method DeCONZIntegration.callback of <core.integration.deconz.DeCONZIntegration object at 0xb5328fb8>>, 'data': {'id': 'tangent_4sl02_not_assigned', 'unique_id': '14:b4:57:ff:fe:77:74:de', 'event': 4002}, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'id': 'tangent_4sl02_not_assigned', '__thread_id': 'MainThread'}}
2020-03-25 13:01:48.262008 WARNING MyController: ------------------------------------------------------------
2020-03-25 13:01:48.264215 WARNING MyController: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 725, in async_worker
    await funcref(args["event"], data, args["kwargs"])
  File "/config/appdaemon/apps/controllerx/core/integration/deconz.py", line 16, in callback
    await self.controller.handle_action(data[type_])
  File "/config/appdaemon/apps/controllerx/core/controller.py", line 121, in handle_action
    action, *args = self.get_action(self.actions_mapping[action_key])
  File "/config/appdaemon/apps/controllerx/core/controller.py", line 138, in get_action
    raise ValueError(
ValueError: The action value from the action mapping should be a list or a function

2020-03-25 13:01:48.265537 WARNING MyController: ------------------------------------------------------------

Did I miss something?

EDIT:

Ok, I think I got it…
The action should be enclosed in double quotes to be valid, like this:

MyController:
  log_level: DEBUG
  module: controllerx
  class: CustomLightController #E1810Controller
  controller: tangent_4sl02_not_assigned
  light: light.shelly_dimmer_f32d92_light_0
  integration: deconz
  mapping:
    4002: "on"
    5002: "off"

Hi @ZEROBiTE,

My mistake. When the YAML is parsed “on” and “off” are translated as “True” and “False” (booleans). So you need to wrap them with quotes, so like:

MyController:
  log_level: DEBUG
  module: controllerx
  class: CustomLightController #E1810Controller
  controller: tangent_4sl02_not_assigned
  light: light.shelly_dimmer_f32d92_light_0
  integration: deconz
  mapping:
    4002: "on"
    #5002: "off"
    #4001 : hold_brightness_up
    #4003 : release
    #5001 : hold_brightness_down
    #5003 : release

I always forget to mention this… sorry. I hope this works now :slight_smile:

1 Like

@xaviml

Yeah, I just found out - see the edit in my previous post :wink:

Thanks a million - :+1: :smiley:

1 Like