ControllerX. Bring full functionality to light and media player controllers

Hi everyone,

I’ve succesfully connected the ikea dimmer remote to a media player for controlling the volume with following config:

media_player_volume:
  module: controllerx
  class: CustomMediaPlayerController
  controller: tradfri_wireless_dimmer
  integration:
    name: deconz
  media_player: media_player.living_room_home
  mapping:
    3002: click_volume_down # Rotate left
    2002: click_volume_up # Rotate right
    1002: next_track # Flip90
    4002: previous_track # Flip180

But now I want to expand this so it doesn’t control one media player but the currently playing media player(and even further if a cast group is playing I control the cast group instead of a single media player)
I’ve searched a bit but can’t find a way to template the media_player entity. Is there another way someone can think of?

Hi’ @Sennevds

ControllerX support HA groups of both lights and media players.
If your media player, like Sonos, provides a source list and current playing group as attributes, you can perhaps control the player/group of players in the same way as I’ve done with my Sonos speakers ?
Your could check the Sonos example in ControllerX documentation and see if same kind of setup could be used for your setup.

Direct templating in apps.yaml should be possible, but my knowledge on templating and appdeamon is quite limited. If direct templating can’t be done, you could do the templating on a HA sensor instead and use that as media player entity in apps.yaml

Ciao !

Thanks for the information! Templating doesn’t work. I tried the following:

media_player_volume:
  module: controllerx
  class: CustomMediaPlayerController
  controller: tradfri_wireless_dimmer
  integration:
    name: deconz
  media_player: >
          {% if is_state('media_player.all_speakers', 'playing') %}
            media_player.all_speakers
          {% elif is_state('media_player.receiver_and_home', 'playing') %}
            media_player.receiver_and_home
          {% elif is_state('media_player.living_room_home', 'playing') %}
            media_player.living_room_home
          {% elif is_state('media_player.chromecast_audio', 'playing') %}
            media_player.chromecast_audio
          {% else %}
            media_player.living_room_home
          {% endif %}
  mapping:
    3002: click_volume_down # Rotate left
    2002: click_volume_up # Rotate right
    1002: next_track # Flip90
    4002: previous_track # Flip180

But it isn’t accepted. I’m now going to try to make a dynamic group with just one media_player in it the one I want to control(If you change the volume of a cast group the volume off all the speakers in the group change)

I’ve found a way to achieve what I want here’s what I did I case someone wants to do the same as me:
I’ve created a empty group:

current_media_player:
  name: Current media player

Then I have setup a automation that triggers everytime when a media player changes state and then add the appropriate entity to the group(if a cast group is playing add the cast group and not the single entities) like this:

- alias: Current media player
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: media_player.all_speakers
    - platform: state
      entity_id: media_player.receiver_and_home
    - platform: state
      entity_id: media_player.living_room_home
    - platform: state
      entity_id: media_player.chromecast_audio
  action:
    - service: group.set
      data_template:
        object_id: current_media_player
        entities: >
          {% if is_state('media_player.all_speakers', 'playing') %}
            media_player.all_speakers
          {% elif is_state('media_player.receiver_and_home', 'playing') %}
            media_player.receiver_and_home
          {% elif is_state('media_player.living_room_home', 'playing') %}
            media_player.living_room_home
          {% elif is_state('media_player.chromecast_audio', 'playing') %}
            media_player.chromecast_audio
          {% else %}
            media_player.living_room_home
          {% endif %}

Then as media-player entity in ControllerX config use the group:

media_player_volume:
  module: controllerx
  class: CustomMediaPlayerController
  controller: tradfri_wireless_dimmer
  integration:
    name: deconz
  media_player: group.current_media_player
  mapping:
    3002: click_volume_down # Rotate left
    2002: click_volume_up # Rotate right
    1002: next_track # Flip90
    4002: previous_track # Flip180

Thanks for the help @htvekov!

1 Like

Hi @Sennevds,

I think you found a nice solution to it. The solution I was about to propose involved a feature from AppDaemon, that allows you to activate and deactivate certain automation depending on the entities’ values (constrain callback). Here I leave how the config would look like with the solution I propose for 2 media players:

media_player1:
  module: controllerx
  class: CustomMediaPlayerController
  controller: tradfri_wireless_dimmer
  integration: deconz
  media_player: media_player.media_player1
  mapping:
    3002: click_volume_down # Rotate left
    2002: click_volume_up # Rotate right
    1002: next_track # Flip90
    4002: previous_track # Flip180
  constrain_input_select: media_player.media_player1,playing

media_player2:
  module: controllerx
  class: CustomMediaPlayerController
  controller: tradfri_wireless_dimmer
  integration: deconz
  media_player: media_player.media_player2
  mapping:
    3002: click_volume_down # Rotate left
    2002: click_volume_up # Rotate right
    1002: next_track # Flip90
    4002: previous_track # Flip180
  constrain_input_select: media_player.media_player2,playing

As you can see, the problem is that you need to repeat the configuration twice, this is why I still recommend your solution. Plus, I have not tested this out myself, but I think it should work.

Thank you for sharing the solution with us, I will be adding it into the example page, so people can reuse it if needed :slight_smile:

Ha also nice solution. The only thing is that when a cast group is playing (and the group consist of 2 media players) you’ve got 3 media players playing and at that moment I want to control the group instead of the individual media players.

1 Like

Hi’ @Sennevds

Glad you got your template up and running :slightly_smiling_face::+1:
I’ve only got Sonos speakers, so don’t really know how cast groups are integrated and controlled.

What if you (by choice) are playing different sources simultaniously on different devices ?
Or is that a non existing ‘control group’ issue in your case ?

is the media_player.all:speakers a group or a single device ?

Ciao !

In my case that would be difficult. My chromecast audio is connected to a receiver which has speakers in the living and the kitchen and my google home is also in the kitchen(open spaces all connected).

media_player.all_speakers is a single entity in hass but are actually 3 devices.
So if I cast to all speakers I have the 3 real speakers that show up as currently playing + the entity media_player.all_speakers. I can adjust the volume per speaker but I want to control the volume off all the speakers.

tv_sonos_speaker:
  module: controllerx
  class: E1744MediaPlayerController
  sensor: sensor.ikea_sound_controller_action
  media_player: media_player.tv_sonos

Of late my ikea sounds controller has gone very slow. I turn the dial and it can be up to 2 full seconds before the Sonos speaker Volume changes. From the HA front end changing the Sonos media player volume is almost instant.

Any ideas why controller X and the ikea sound controller would be so slow?

My guess is that I need a better zigbee network? My cr@ppy zigbee network is the issue.

Hi @ladaowner

Sad to hear you get some delays in your network. I have experienced the same before in my on network and it was due to have the devices far away from my network or interferences. So if I was you, I would be thinking on what you changed lately (removed some devices, moved them around, changed some setting on your wifi channels, etc), then you might figure out where the problem is coming.

As a final recommendation, I would tell you to restart your PI or computer, maybe it is suffering from some lack of space in memory and it might make your system to be slower.

Maybe others can help you better on this as well :slight_smile:

I would also like to add that using E1744 with z2m is not the best choice, it works better with deconz due to the several layers that it needs to go through. I am working on something to make the z2m integration faster by operating directly with MQTT. You can read more about it in here

Hey, I’ve just tried to get ControllerX to work but somehow I’m unable to controle any lights.
Im using a conbee II and the standard deconz integration to homeassistant. The controller I’m trying to use is the E1810 from Ikea.
I installed ControllerX via HACS and my apps.yaml says the following:

bett_controller:
  module: controllerx
  class: E1810Controller
  controller: tradfri_fernbedienung
  integration: deconz
  light:
    name: light.alles
    color_mode: color_temp

I took the controller id as it’s described in the documentation via listening to deconz_event
Rebooting multiple times didn’t change anything.

Thanks already

Hi @tonih,

Your configuration seems right to me. If your light just supports color_temp then the color_mode is not needed and can be reduced to:

bett_controller:
  module: controllerx
  class: E1810Controller
  controller: tradfri_fernbedienung
  integration: deconz
  light: light.alles

Anyhow, your problem is not this. Did you install the AppDaemon addon or you have AppDaemon up and running already? If so, what are the AppDaemon logs?

Also, where did you place the configuration that you just showed me?

1 Like

omg, I feel so dumb now… I forgot to install AppDaemon at all :joy: :man_facepalming:t3:

1 Like

Not the first one, no worries haha I will need to highlight that in the documentation I guess

1 Like

Hello!

I managed to get an Ikea E1524 (what is the difference to a E1810?) remote to works as a remote for my Logitech Media Server without any problem.
Thank you very much for this great piece of software!

I used the following configuration:

  dachboden_controller:
    module: controllerx
    class: E1810MediaPlayerController
    controller: tradfri_fernbedienung
    integration: deconz
    media_player: media_player.dachboden
    volume_steps: 40

Is it possible to use also double press or long press actions on some buttons? The volume would stay the same, but e.g. the main button could do some extra thing when I do a long press.

I know I have to use CustomMediaPlayerController, but how to use a short press and a long press for the same button? As you can see I am using the deCONZ integration with a Conbee II stick.

Ok @Sennevds

If devices themselfes don’t deliver a group attribute, then perhaps you should consider making some different groups to match specific playing needs during the day.
But no need to make things more complicated, if you’re happy with a group solution where all active playing devices are added :slightly_smiling_face:

Saw that you’ve made a feature request on Github regarding volume control of your group.
Annoying that not all media-players support volume_set calls :unamused:
But it seems that you’re already done the neccesary coding and patched ControllerX to get a working solution :wink:

Hi @carsten_h,

The E1524 is the old model of E1810, but they look both the same, the documentation is the same for both: https://xaviml.github.io/controllerx/controllers/E1524_E1810

This controller does not support double. You can check the documentation to see the events that the controller fires. The only long press that does not work as expected is the center button since it fires the click event first and then the long click, but the rest you can use click and long press.

I did not understand exactly what is the use case you want to achieve, but I will leave you here a configuration so you understand how ControllerX works more deeply.

dachboden_controller:
  module: controllerx
  class: E1810MediaPlayerController
  controller: tradfri_fernbedienung
  integration: deconz
  media_player: media_player.dachboden
  volume_steps: 40
  excluded_actions:
    - 4001 # Hold left arrow event
    - 5001 # Hold right arrow event

dachboden_controller_light1:
  module: controllerx
  class: CustomLightController
  controller: tradfri_fernbedienung
  integration: deconz
  light: light.light1
  mapping:
    4001: toggle

dachboden_controller_light2:
  module: controllerx
  class: CustomLightController
  controller: tradfri_fernbedienung
  integration: deconz
  light: light.light2
  mapping:
    5001: toggle

So the first config is the same one you sent, but it exclude the left and right arrow hold actions. Then I added two custom light controllers to toggle 2 lights with the events I excluded. I hope this helped you understand the potential of ControllerX and achieve what you want to do. Here for more information of custom controllers.

If you tell me exactly what is what you want to achieve, I will be able to help you with the configuration :slight_smile:

Ah, I see, thank you!

Ok, that is not really good, because that would be the button I want to use. But left/right would be also a solution.

Yes, I didn’t wrote it clearly enough. Mainly I need a toggle for the speakers of the media player I want to control, as the don’t have to be switched on the whole day. So I need to control a switchable socket.

Yes, now the penny dropped. I think I understand now how to handle it.

Thank you very much for the fast help!

1 Like

Nice project,
I Enabled appdaemon in HACS. installed the controllerX automation in HACS, added the config for my IKEA E1743 remove to appdaemon/apps/apps.yaml file. But it doesn’t work and there are no logs on this matter. did i missen something?

Thanks,